Bug 1139425 - Service Worker Client uuid tests. r=baku

This commit is contained in:
Albert Crespell 2015-03-16 11:20:40 +01:00
Родитель 7f663f49db
Коммит 6fc5c56408
6 изменённых файлов: 153 добавлений и 0 удалений

Просмотреть файл

@ -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>
<title>Bug 1058311 - controlled page</title>
<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 testWindow = parent;
@ -38,6 +39,9 @@
navigator.serviceWorker.onmessage = function(msg) {
// worker message;
result = re.test(msg.data.id);
postResult(result, "Client id test");
result = msg.data.url == window.location;
postResult(result, "Client url test");

Просмотреть файл

@ -8,6 +8,7 @@ onmessage = function(e) {
for (i = 0; i < res.length; i++) {
client = res[i];
response = {
id: client.id,
url: client.url,
visibilityState: client.visibilityState,
focused: client.focused,

Просмотреть файл

@ -39,6 +39,8 @@ support-files =
message_receiver.html
close_test.js
serviceworker_not_sharedworker.js
match_all_client/match_all_client_id.html
match_all_client_id_worker.js
[test_unregister.html]
[test_installation_simple.html]
@ -58,3 +60,4 @@ support-files =
[test_close.html]
[test_serviceworker_interfaces.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>