Bug 1164397 - Part 6: Add a test case for the service worker responding with a redirected Response; r=jdm

This commit is contained in:
Ehsan Akhgari 2015-05-21 11:11:20 -04:00
Родитель d9f5031529
Коммит 02f547b7e8
7 изменённых файлов: 101 добавлений и 0 удалений

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

@ -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>