зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1164397 - Part 6: Add a test case for the service worker responding with a redirected Response; r=jdm
This commit is contained in:
Родитель
d9f5031529
Коммит
02f547b7e8
|
@ -0,0 +1,4 @@
|
|||
function handleRequest(request, response) {
|
||||
response.setStatusLine(null, 308, "Permanent Redirect");
|
||||
response.setHeader("Location", "http://example.org/tests/dom/workers/test/serviceworkers/fetch/origin/realindex.html", false);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
self.addEventListener("fetch", function(event) {
|
||||
event.respondWith(fetch(event.request));
|
||||
});
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
window.opener.postMessage({status: "domain", data: document.domain}, "*");
|
||||
window.opener.postMessage({status: "origin", data: location.origin}, "*");
|
||||
window.opener.postMessage({status: "done"}, "*");
|
||||
</script>
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
function ok(v, msg) {
|
||||
window.parent.postMessage({status: "ok", result: !!v, message: msg}, "*");
|
||||
}
|
||||
|
||||
function done(reg) {
|
||||
ok(reg.active, "The active worker should be available.");
|
||||
window.parent.postMessage({status: "registrationdone"}, "*");
|
||||
}
|
||||
|
||||
navigator.serviceWorker.ready.then(done);
|
||||
navigator.serviceWorker.register("origin_test.js", {scope: "."});
|
||||
</script>
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
navigator.serviceWorker.getRegistration(".").then(function(registration) {
|
||||
registration.unregister().then(function(success) {
|
||||
if (success) {
|
||||
window.parent.postMessage({status: "unregistrationdone"}, "*");
|
||||
}
|
||||
}, function(e) {
|
||||
dump("Unregistering the SW failed with " + e + "\n");
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -47,6 +47,11 @@ support-files =
|
|||
fetch/https/clonedresponse/register.html
|
||||
fetch/https/clonedresponse/unregister.html
|
||||
fetch/https/clonedresponse/https_test.js
|
||||
fetch/origin/index.sjs
|
||||
fetch/origin/realindex.html
|
||||
fetch/origin/register.html
|
||||
fetch/origin/unregister.html
|
||||
fetch/origin/origin_test.js
|
||||
fetch/requesturl/index.html
|
||||
fetch/requesturl/redirect.sjs
|
||||
fetch/requesturl/redirector.html
|
||||
|
@ -159,3 +164,4 @@ support-files =
|
|||
[test_skip_waiting.html]
|
||||
[test_strict_mode_error.html]
|
||||
[test_cross_origin_url_after_redirect.html]
|
||||
[test_origin_after_redirect.html]
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test the origin of a redirected response from a service worker</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">
|
||||
<iframe></iframe>
|
||||
</div>
|
||||
<pre id="test"></pre>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var iframe;
|
||||
function runTest() {
|
||||
iframe = document.querySelector("iframe");
|
||||
iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/origin/register.html";
|
||||
var win;
|
||||
window.onmessage = function(e) {
|
||||
if (e.data.status == "ok") {
|
||||
ok(e.data.result, e.data.message);
|
||||
} else if (e.data.status == "registrationdone") {
|
||||
win = window.open("/tests/dom/workers/test/serviceworkers/fetch/origin/index.sjs", "mywindow", "width=100,height=100");
|
||||
} else if (e.data.status == "domain") {
|
||||
is(e.data.data, "example.org", "Correct domain expected");
|
||||
} else if (e.data.status == "origin") {
|
||||
is(e.data.data, "http://example.org", "Correct origin expected");
|
||||
} else if (e.data.status == "done") {
|
||||
win.close();
|
||||
iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/origin/unregister.html";
|
||||
} else if (e.data.status == "unregistrationdone") {
|
||||
window.onmessage = null;
|
||||
ok(true, "Test finished successfully");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
onload = function() {
|
||||
SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.exemptFromPerDomainMax", true],
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true],
|
||||
]}, runTest);
|
||||
};
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче