1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test allow-presentation sandboxing flag</title>
<script type="application/javascript;version=1.8">
"use strict";
function is(a, b, msg) {
window.parent.postMessage((a === b ? "OK " : "KO ") + msg, "*");
}
function ok(a, msg) {
window.parent.postMessage((a ? "OK " : "KO ") + msg, "*");
}
function info(msg) {
window.parent.postMessage("INFO " + msg, "*");
}
function command(msg) {
window.parent.postMessage("COMMAND " + JSON.stringify(msg), "*");
}
function finish() {
window.parent.postMessage("DONE", "*");
}
function testGetAvailability() {
return new Promise(function(aResolve, aReject) {
ok(navigator.presentation, "navigator.presentation should be available.");
var request = new PresentationRequest("http://example.com");
request.getAvailability().then(
function(aAvailability) {
ok(false, "Unexpected success, should get a security error.");
aReject();
},
function(aError) {
is(aError.name, "SecurityError", "Should get a security error.");
aResolve();
}
);
});
}
function testStartRequest() {
return new Promise(function(aResolve, aReject) {
var request = new PresentationRequest("http://example.com");
request.start().then(
function(aAvailability) {
ok(false, "Unexpected success, should get a security error.");
aReject();
},
function(aError) {
is(aError.name, "SecurityError", "Should get a security error.");
aResolve();
}
);
});
}
function testDefaultRequest() {
return new Promise(function(aResolve, aReject) {
navigator.presentation.defaultRequest = new PresentationRequest("http://example.com");
is(navigator.presentation.defaultRequest, null, "DefaultRequest shoud be null.");
aResolve();
});
}
function testReconnectRequest() {
return new Promise(function(aResolve, aReject) {
var request = new PresentationRequest("http://example.com");
request.reconnect("dummyId").then(
function(aConnection) {
ok(false, "Unexpected success, should get a security error.");
aReject();
},
function(aError) {
is(aError.name, "SecurityError", "Should get a security error.");
aResolve();
}
);
});
}
function runTest() {
testGetAvailability()
.then(testStartRequest)
.then(testDefaultRequest)
.then(testReconnectRequest)
.then(finish);
}
window.addEventListener("message", function onMessage(evt) {
window.removeEventListener("message", onMessage);
if (evt.data === "start") {
runTest();
}
}, false);
window.setTimeout(function() {
command("ready-to-start");
}, 3000);
</script>
</head>
<body>
</body>
</html>
|