Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |