зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1162018 - Add an automated test to ensure that a redirected Request won't be visible to a service worker if it had triggered the original fetch(); r=jdm
This commit is contained in:
Родитель
cbf85aceea
Коммит
f30c9b2b9a
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<script>
|
||||
navigator.serviceWorker.onmessage = window.onmessage = e => {
|
||||
window.parent.postMessage(e.data, "*");
|
||||
};
|
||||
</script>
|
||||
<iframe src="redirector.html"></iframe>
|
|
@ -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/requesturl/secret.html", false);
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
<!DOCTYPE html>
|
||||
<meta http-equiv="refresh" content="3;URL=/tests/dom/workers/test/serviceworkers/fetch/requesturl/redirect.sjs">
|
|
@ -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("requesturl_test.js", {scope: "."});
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
addEventListener("fetch", event => {
|
||||
var url = event.request.url;
|
||||
var badURL = url.indexOf("secret.html") > -1;
|
||||
event.respondWith(
|
||||
new Promise(resolve => {
|
||||
clients.matchAll().then(clients => {
|
||||
for (var client of clients) {
|
||||
if (client.url.indexOf("index.html") > -1) {
|
||||
client.postMessage({status: "ok", result: !badURL, message: "Should not find a bad URL (" + url + ")"});
|
||||
break;
|
||||
}
|
||||
}
|
||||
resolve(fetch(event.request));
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
secret stuff
|
||||
<script>
|
||||
window.parent.postMessage({status: "done"}, "*");
|
||||
</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,13 @@ support-files =
|
|||
fetch/https/clonedresponse/register.html
|
||||
fetch/https/clonedresponse/unregister.html
|
||||
fetch/https/clonedresponse/https_test.js
|
||||
fetch/requesturl/index.html
|
||||
fetch/requesturl/redirect.sjs
|
||||
fetch/requesturl/redirector.html
|
||||
fetch/requesturl/register.html
|
||||
fetch/requesturl/requesturl_test.js
|
||||
fetch/requesturl/secret.html
|
||||
fetch/requesturl/unregister.html
|
||||
fetch/sandbox/index.html
|
||||
fetch/sandbox/intercepted_index.html
|
||||
fetch/sandbox/register.html
|
||||
|
@ -151,3 +158,4 @@ support-files =
|
|||
[test_force_refresh.html]
|
||||
[test_skip_waiting.html]
|
||||
[test_strict_mode_error.html]
|
||||
[test_cross_origin_url_after_redirect.html]
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test access to a cross origin Request.url property from a service worker for a redirected intercepted iframe</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/requesturl/register.html";
|
||||
window.onmessage = function(e) {
|
||||
if (e.data.status == "ok") {
|
||||
ok(e.data.result, e.data.message);
|
||||
} else if (e.data.status == "registrationdone") {
|
||||
iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/requesturl/index.html";
|
||||
} else if (e.data.status == "done") {
|
||||
iframe.src = "/tests/dom/workers/test/serviceworkers/fetch/requesturl/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>
|
Загрузка…
Ссылка в новой задаче