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
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 04 Jun 2015 10:13:40 -0400
changeset 247189 b485fe97c0486f188b47aae272e7e1019746009d
parent 247188 2096212a25cb52eaef3f6c886aa9de06404ef500
child 247190 a509c974aa1f07e07b650c18c4dbc91a1e84336b
push id28855
push userkwierso@gmail.com
push dateFri, 05 Jun 2015 01:19:30 +0000
treeherdermozilla-central@227d356ac030 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1162018
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/workers/test/serviceworkers/fetch/requesturl/index.html
dom/workers/test/serviceworkers/fetch/requesturl/redirect.sjs
dom/workers/test/serviceworkers/fetch/requesturl/redirector.html
dom/workers/test/serviceworkers/fetch/requesturl/register.html
dom/workers/test/serviceworkers/fetch/requesturl/requesturl_test.js
dom/workers/test/serviceworkers/fetch/requesturl/secret.html
dom/workers/test/serviceworkers/fetch/requesturl/unregister.html
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/test_cross_origin_url_after_redirect.html
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/index.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<script>
+  navigator.serviceWorker.onmessage = window.onmessage = e => {
+    window.parent.postMessage(e.data, "*");
+  };
+</script>
+<iframe src="redirector.html"></iframe>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/redirect.sjs
@@ -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);
+}
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/redirector.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<meta http-equiv="refresh" content="3;URL=/tests/dom/workers/test/serviceworkers/fetch/requesturl/redirect.sjs">
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/register.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/requesturl_test.js
@@ -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));
+      });
+    })
+  );
+});
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/secret.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+secret stuff
+<script>
+  window.parent.postMessage({status: "done"}, "*");
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/requesturl/unregister.html
@@ -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>
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -42,16 +42,23 @@ support-files =
   fetch/https/index.html
   fetch/https/register.html
   fetch/https/unregister.html
   fetch/https/https_test.js
   fetch/https/clonedresponse/index.html
   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
   fetch/sandbox/unregister.html
   fetch/sandbox/sandbox_test.js
   match_all_properties_worker.js
   match_all_clients/match_all_controlled.html
   test_serviceworker_interfaces.js
@@ -146,8 +153,9 @@ support-files =
 [test_sanitize.html]
 [test_sanitize_domain.html]
 [test_service_worker_allowed.html]
 [test_app_protocol.html]
 [test_claim_fetch.html]
 [test_force_refresh.html]
 [test_skip_waiting.html]
 [test_strict_mode_error.html]
+[test_cross_origin_url_after_redirect.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/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>