Bug 931249 - patch 3 - tests. r=bkelly

--HG--
extra : rebase_source : d5da130a62fd6e9996b226c29b6a788b1af80acf
This commit is contained in:
Nikhil Marathe 2015-03-18 09:47:19 -07:00
parent f9c8e3cf34
commit dec7349527
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,9 @@
var counter = 0;
function handleRequest(request, response) {
if (!counter) {
response.setHeader("Content-Type", "application/javascript", false);
response.write("callByScript();");
} else {
response.write("no cache no party!");
}
}

View File

@ -0,0 +1,23 @@
var counter = 0;
function callByScript() {
++counter;
}
importScripts(['importscript.sjs']);
importScripts(['importscript.sjs']);
onmessage = function(e) {
self.clients.matchAll().then(function(res) {
if (!res.length) {
dump("ERROR: no clients are currently controlled.\n");
}
try {
importScript(['importscript.sjs']);
res[0].postMessage("KO");
return;
} catch(e) {}
res[0].postMessage(counter == 2 ? "OK" : "KO");
});
};

View File

@ -61,6 +61,8 @@ support-files =
source_message_posting_worker.js
scope/scope_worker.js
redirect_serviceworker.sjs
importscript.sjs
importscript_worker.js
[test_unregister.html]
[test_installation_simple.html]
@ -86,3 +88,4 @@ skip-if = true # Bug 1136780
[test_match_all_client_id.html]
[test_sandbox_intercept.html]
[test_request_context.html]
[test_importscript.html]

View File

@ -0,0 +1,67 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test service worker - script cache policy</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<div id="content"></div>
<script class="testbody" type="text/javascript">
function start() {
return navigator.serviceWorker.register("importscript_worker.js",
{ scope: "./sw_clients/" })
.then((swr) => registration = swr);
}
function unregister() {
return registration.unregister().then(function(result) {
ok(result, "Unregister should return true.");
});
}
function testPostMessage(swr) {
var p = new Promise(function(res, rej) {
window.onmessage = function(e) {
if (e.data === "READY") {
swr.active.postMessage("do magic");
return;
}
ok(e.data === "OK", "Worker posted the correct value: " + e.data);
res();
}
});
var content = document.getElementById("content");
ok(content, "Parent exists.");
iframe = document.createElement("iframe");
iframe.setAttribute('src', "sw_clients/service_worker_controlled.html");
content.appendChild(iframe);
return p.then(() => content.removeChild(iframe));
}
function runTest() {
start()
.then(testPostMessage)
.then(unregister)
.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>