mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 931249 - patch 3 - tests. r=bkelly
--HG-- extra : rebase_source : d5da130a62fd6e9996b226c29b6a788b1af80acf
This commit is contained in:
parent
f9c8e3cf34
commit
dec7349527
9
dom/workers/test/serviceworkers/importscript.sjs
Normal file
9
dom/workers/test/serviceworkers/importscript.sjs
Normal 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!");
|
||||
}
|
||||
}
|
23
dom/workers/test/serviceworkers/importscript_worker.js
Normal file
23
dom/workers/test/serviceworkers/importscript_worker.js
Normal 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");
|
||||
});
|
||||
};
|
@ -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]
|
||||
|
67
dom/workers/test/serviceworkers/test_importscript.html
Normal file
67
dom/workers/test/serviceworkers/test_importscript.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user