Bug 1143981 - Reroute all fetch tests through a transparent service worker; r=nsm
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 13 May 2015 08:56:25 -0400
changeset 243794 1189f6ffc65e162d6aa6b2ee75234e59a54abe93
parent 243793 67708ff58accca7e53127c3a7c05305499b7096a
child 243795 436f7334138754a9d21a585b9d596b1304391134
push id59780
push usereakhgari@mozilla.com
push dateThu, 14 May 2015 13:10:36 +0000
treeherdermozilla-inbound@1189f6ffc65e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1143981
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 1143981 - Reroute all fetch tests through a transparent service worker; r=nsm
dom/tests/mochitest/fetch/fetch_test_framework.js
dom/tests/mochitest/fetch/mochitest.ini
dom/tests/mochitest/fetch/reroute.html
dom/tests/mochitest/fetch/reroute.js
dom/tests/mochitest/fetch/reroute.js^headers^
dom/tests/mochitest/fetch/sw_reroute.js
dom/tests/mochitest/fetch/test_fetch_basic_http_sw_reroute.html
dom/tests/mochitest/fetch/test_fetch_basic_sw_reroute.html
dom/tests/mochitest/fetch/test_fetch_cors_sw_reroute.html
dom/tests/mochitest/fetch/test_formdataparsing_sw_reroute.html
dom/tests/mochitest/fetch/test_headers_sw_reroute.html
dom/tests/mochitest/fetch/test_request.html
dom/tests/mochitest/fetch/test_request_sw_reroute.html
dom/tests/mochitest/fetch/test_response_sw_reroute.html
--- a/dom/tests/mochitest/fetch/fetch_test_framework.js
+++ b/dom/tests/mochitest/fetch/fetch_test_framework.js
@@ -62,18 +62,30 @@ function testScript(script) {
         var iframe = document.createElement("iframe");
         iframe.src = "message_receiver.html";
         iframe.onload = function() {
           worker.postMessage({ script: script });
         };
         document.body.appendChild(iframe);
       }
 
-      navigator.serviceWorker.ready.then(setupSW);
-      navigator.serviceWorker.register("worker_wrapper.js", {scope: "."});
+      navigator.serviceWorker.register("worker_wrapper.js", {scope: "."})
+        .then(function(registration) {
+          if (registration.installing) {
+            var done = false;
+            registration.installing.onstatechange = function() {
+              if (!done) {
+                done = true;
+                setupSW(registration);
+              }
+            };
+          } else {
+            setupSW(registration);
+          }
+        });
     });
   }
 
   function windowTest() {
     return new Promise(function(resolve, reject) {
       var scriptEl = document.createElement("script");
       scriptEl.setAttribute("src", script);
       scriptEl.onload = function() {
@@ -99,12 +111,16 @@ function testScript(script) {
     })
     .catch(function(e) {
       ok(false, "Some test failed in " + script);
       info(e);
       info(e.message);
       return Promise.resolve();
     })
     .then(function() {
-      SimpleTest.finish();
+      if (parent && parent.finishTest) {
+        parent.finishTest();
+      } else {
+        SimpleTest.finish();
+      }
     });
 }
 
--- a/dom/tests/mochitest/fetch/mochitest.ini
+++ b/dom/tests/mochitest/fetch/mochitest.ini
@@ -7,18 +7,38 @@ support-files =
   test_fetch_cors.js
   test_formdataparsing.js
   test_headers_common.js
   test_request.js
   test_response.js
   utils.js
   worker_wrapper.js
   message_receiver.html
+  reroute.html
+  reroute.js
+  reroute.js^headers^
+  sw_reroute.js
 
 [test_headers.html]
+[test_headers_sw_reroute.html]
+skip-if = buildapp == 'b2g' # Bug 1137683
 [test_headers_mainthread.html]
 [test_fetch_app_protocol.html]
 [test_fetch_basic.html]
+[test_fetch_basic_sw_reroute.html]
+skip-if = buildapp == 'b2g' # Bug 1137683
 [test_fetch_basic_http.html]
+[test_fetch_basic_http_sw_reroute.html]
+skip-if = true # Bug 1122161, need proper support for redirects
+#skip-if = buildapp == 'b2g' # Bug 1137683
 [test_fetch_cors.html]
+[test_fetch_cors_sw_reroute.html]
+skip-if = true # Bug 1122161, need proper support for redirects
+#skip-if = buildapp == 'b2g' # Bug 1137683
 [test_formdataparsing.html]
+[test_formdataparsing_sw_reroute.html]
+skip-if = buildapp == 'b2g' # Bug 1137683
 [test_request.html]
+[test_request_sw_reroute.html]
+skip-if = buildapp == 'b2g' # Bug 1137683
 [test_response.html]
+[test_response_sw_reroute.html]
+skip-if = buildapp == 'b2g' # Bug 1137683
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/reroute.html
@@ -1,23 +1,10 @@
-<!--
-  Any copyright is dedicated to the Public Domain.
-  http://creativecommons.org/publicdomain/zero/1.0/
--->
-<!DOCTYPE HTML>
-<html>
-<head>
-  <title>Bug XXXXXX - Test Request object in 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"></div>
-<pre id="test"></pre>
+<!DOCTYPE html>
+<script>
+["SimpleTest", "ok", "info", "is", "$"]
+  .forEach((v) => window[v] = window.parent[v]);
+</script>
 <script type="text/javascript" src="utils.js"> </script>
 <script type="text/javascript" src="fetch_test_framework.js"> </script>
-<script class="testbody" type="text/javascript">
-testScript("test_request.js");
+<script>
+testScript(location.search.substring(1) + ".js");
 </script>
-</body>
-</html>
-
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/fetch/reroute.js
@@ -0,0 +1,3 @@
+onfetch = function(e) {
+  e.respondWith(fetch(e.request));
+};
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/fetch/reroute.js^headers^
@@ -0,0 +1,1 @@
+Service-Worker-Allowed: /
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/fetch/sw_reroute.js
@@ -0,0 +1,29 @@
+var gRegistration;
+
+function testScript(script) {
+  function setupSW(registration) {
+    gRegistration = registration;
+
+    var iframe = document.createElement("iframe");
+    iframe.src = "reroute.html?" + script.replace(".js", "");
+    document.body.appendChild(iframe);
+  }
+
+  SpecialPowers.pushPrefEnv({
+    "set": [["dom.serviceWorkers.enabled", true],
+            ["dom.serviceWorkers.testing.enabled", true],
+            ["dom.serviceWorkers.exemptFromPerDomainMax", true]]
+  }, function() {
+    navigator.serviceWorker.ready.then(setupSW);
+    navigator.serviceWorker.register("reroute.js", {scope: "/"});
+  });
+}
+
+function finishTest() {
+  gRegistration.unregister().then(SimpleTest.finish, function(e) {
+    dump("unregistration failed: " + e + "\n");
+    SimpleTest.finish();
+  });
+}
+
+SimpleTest.waitForExplicitFinish();
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_fetch_basic_http_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_fetch_basic_http_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Bug 1039846 - Test fetch() http fetching in 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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_fetch_basic_http.js");
 </script>
 </body>
 </html>
 
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_fetch_basic_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_fetch_basic_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Bug 1039846 - Test fetch() function in 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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_fetch_basic.js");
 </script>
 </body>
 </html>
 
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_fetch_cors_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_fetch_cors_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Bug 1039846 - Test fetch() CORS mode</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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_fetch_cors.js");
 </script>
 </body>
 </html>
 
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_formdataparsing_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_formdataparsing_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Bug 1109751 - Test FormData parsing</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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_formdataparsing.js");
 </script>
 </body>
 </html>
 
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_headers_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_headers_sw_reroute.html
@@ -1,23 +1,16 @@
-<!--
-  Any copyright is dedicated to the Public Domain.
-  http://creativecommons.org/publicdomain/zero/1.0/
--->
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Test Fetch Headers - Basic</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"></div>
-<pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_headers_common.js");
 </script>
 </body>
 </html>
-
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_request.html
@@ -1,16 +1,16 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Test Request object in 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"></div>
 <pre id="test"></pre>
 <script type="text/javascript" src="utils.js"> </script>
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_request_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_request_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Test Request object in 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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
 testScript("test_request.js");
 </script>
 </body>
 </html>
 
copy from dom/tests/mochitest/fetch/test_request.html
copy to dom/tests/mochitest/fetch/test_response_sw_reroute.html
--- a/dom/tests/mochitest/fetch/test_request.html
+++ b/dom/tests/mochitest/fetch/test_response_sw_reroute.html
@@ -1,23 +1,22 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
-  <title>Bug XXXXXX - Test Request object in worker</title>
+  <title>Bug 1039846 - Test Response object in 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"></div>
 <pre id="test"></pre>
-<script type="text/javascript" src="utils.js"> </script>
-<script type="text/javascript" src="fetch_test_framework.js"> </script>
+<script type="text/javascript" src="sw_reroute.js"> </script>
 <script class="testbody" type="text/javascript">
-testScript("test_request.js");
+testScript("test_response.js");
 </script>
 </body>
 </html>