зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1139425 - Service Worker Client uuid tests. r=baku
This commit is contained in:
Родитель
7f663f49db
Коммит
6fc5c56408
|
@ -0,0 +1,31 @@
|
||||||
|
<!--
|
||||||
|
Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
-->
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Bug 1139425 - controlled page</title>
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
var testWindow = parent;
|
||||||
|
if (opener) {
|
||||||
|
testWindow = opener;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
navigator.serviceWorker.ready.then(function(swr) {
|
||||||
|
swr.active.postMessage("Start");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
navigator.serviceWorker.onmessage = function(msg) {
|
||||||
|
// worker message;
|
||||||
|
testWindow.postMessage(msg.data, "*");
|
||||||
|
window.close();
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,28 @@
|
||||||
|
onmessage = function(e) {
|
||||||
|
dump("MatchAllClientIdWorker:" + e.data + "\n");
|
||||||
|
var id = [];
|
||||||
|
var iterations = 5;
|
||||||
|
var counter = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < iterations; i++) {
|
||||||
|
self.clients.matchAll().then(function(res) {
|
||||||
|
if (!res.length) {
|
||||||
|
dump("ERROR: no clients are currently controlled.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
client = res[0];
|
||||||
|
id[counter] = client.id;
|
||||||
|
counter++;
|
||||||
|
if (counter >= iterations) {
|
||||||
|
var response = true;
|
||||||
|
for (var index = 1; index < iterations; index++) {
|
||||||
|
if (id[0] != id[index]) {
|
||||||
|
response = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.postMessage(response);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Bug 1058311 - controlled page</title>
|
<title>Bug 1058311 - controlled page</title>
|
||||||
<script class="testbody" type="text/javascript">
|
<script class="testbody" type="text/javascript">
|
||||||
|
var re = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
||||||
var frameType = "none";
|
var frameType = "none";
|
||||||
var testWindow = parent;
|
var testWindow = parent;
|
||||||
|
|
||||||
|
@ -38,6 +39,9 @@
|
||||||
|
|
||||||
navigator.serviceWorker.onmessage = function(msg) {
|
navigator.serviceWorker.onmessage = function(msg) {
|
||||||
// worker message;
|
// worker message;
|
||||||
|
result = re.test(msg.data.id);
|
||||||
|
postResult(result, "Client id test");
|
||||||
|
|
||||||
result = msg.data.url == window.location;
|
result = msg.data.url == window.location;
|
||||||
postResult(result, "Client url test");
|
postResult(result, "Client url test");
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ onmessage = function(e) {
|
||||||
for (i = 0; i < res.length; i++) {
|
for (i = 0; i < res.length; i++) {
|
||||||
client = res[i];
|
client = res[i];
|
||||||
response = {
|
response = {
|
||||||
|
id: client.id,
|
||||||
url: client.url,
|
url: client.url,
|
||||||
visibilityState: client.visibilityState,
|
visibilityState: client.visibilityState,
|
||||||
focused: client.focused,
|
focused: client.focused,
|
||||||
|
|
|
@ -39,6 +39,8 @@ support-files =
|
||||||
message_receiver.html
|
message_receiver.html
|
||||||
close_test.js
|
close_test.js
|
||||||
serviceworker_not_sharedworker.js
|
serviceworker_not_sharedworker.js
|
||||||
|
match_all_client/match_all_client_id.html
|
||||||
|
match_all_client_id_worker.js
|
||||||
|
|
||||||
[test_unregister.html]
|
[test_unregister.html]
|
||||||
[test_installation_simple.html]
|
[test_installation_simple.html]
|
||||||
|
@ -58,3 +60,4 @@ support-files =
|
||||||
[test_close.html]
|
[test_close.html]
|
||||||
[test_serviceworker_interfaces.html]
|
[test_serviceworker_interfaces.html]
|
||||||
[test_serviceworker_not_sharedworker.html]
|
[test_serviceworker_not_sharedworker.html]
|
||||||
|
[test_match_all_client_id.html]
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
<!--
|
||||||
|
Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
|
-->
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Bug 1058311 - Test matchAll client id </title>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none"></div>
|
||||||
|
<pre id="test"></pre>
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
var registration;
|
||||||
|
var clientURL = "match_all_client/match_all_client_id.html";
|
||||||
|
function start() {
|
||||||
|
return navigator.serviceWorker.register("match_all_client_id_worker.js",
|
||||||
|
{ scope: "./match_all_client/" })
|
||||||
|
.then((swr) => registration = swr);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unregister() {
|
||||||
|
return registration.unregister().then(function(result) {
|
||||||
|
ok(result, "Unregister should return true.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessageListener() {
|
||||||
|
return new Promise(function(res, rej) {
|
||||||
|
window.onmessage = function(e) {
|
||||||
|
ok(e.data, "Same client id for multiple calls.");
|
||||||
|
|
||||||
|
if (!e.data) {
|
||||||
|
rej();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info("DONE from: " + e.source);
|
||||||
|
res();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNestedWindow() {
|
||||||
|
var p = getMessageListener();
|
||||||
|
|
||||||
|
var content = document.getElementById("content");
|
||||||
|
ok(content, "Parent exists.");
|
||||||
|
|
||||||
|
iframe = document.createElement("iframe");
|
||||||
|
|
||||||
|
content.appendChild(iframe);
|
||||||
|
iframe.setAttribute('src', clientURL);
|
||||||
|
|
||||||
|
return p.then(() => content.removeChild(iframe));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAuxiliaryWindow() {
|
||||||
|
var p = getMessageListener();
|
||||||
|
var w = window.open(clientURL);
|
||||||
|
|
||||||
|
return p.then(() => w.close());
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
info(window.opener == undefined);
|
||||||
|
start()
|
||||||
|
.then(testAuxiliaryWindow)
|
||||||
|
.then(testNestedWindow)
|
||||||
|
.catch(function(e) {
|
||||||
|
ok(false, "Some test failed with error " + e);
|
||||||
|
}).then(SimpleTest.finish);
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
SpecialPowers.pushPrefEnv({"set": [
|
||||||
|
["dom.serviceWorkers.enabled", true],
|
||||||
|
["dom.serviceWorkers.testing.enabled", true]
|
||||||
|
]}, runTest);
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
Загрузка…
Ссылка в новой задаче