Bug 1167808 P4 Test that respondWith() for a browser load reads the body correctly. r=ehsan
☠☠ backed out by 48347c4899df ☠ ☠
authorBen Kelly <ben@wanderview.com>
Thu, 02 Jul 2015 14:34:01 -0700
changeset 251201 1c9c72d93973039fa67fde1901af7abeff225653
parent 251200 9c94c759a0fb72e13ca17c73fcf79d27e25214b6
child 251202 d2c37bf5d4a68da578b787cc153a9c7d6f641a28
push id61794
push userbkelly@mozilla.com
push dateThu, 02 Jul 2015 21:34:03 +0000
treeherdermozilla-inbound@1c9c72d93973 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1167808
milestone42.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 1167808 P4 Test that respondWith() for a browser load reads the body correctly. r=ehsan
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/notify_loaded.js
dom/workers/test/serviceworkers/opaque_intercept_worker.js
dom/workers/test/serviceworkers/sw_clients/refresher.html
dom/workers/test/serviceworkers/sw_clients/refresher_compressed.html
dom/workers/test/serviceworkers/test_opaque_intercept.html
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -139,16 +139,18 @@ support-files =
   thirdparty/register.html
   thirdparty/unregister.html
   thirdparty/sw.js
   register_https.html
   gzip_redirect_worker.js
   sw_clients/navigator.html
   eval_worker.js
   test_eval_not_allowed.html^headers^
+  opaque_intercept_worker.js
+  notify_loaded.js
 
 [test_app_protocol.html]
 [test_bug1151916.html]
 [test_claim.html]
 [test_claim_fetch.html]
 [test_claim_oninstall.html]
 [test_client_focus.html]
 [test_close.html]
@@ -196,8 +198,9 @@ skip-if = toolkit == 'android' # Bug 116
 [test_serviceworker_not_sharedworker.html]
 [test_skip_waiting.html]
 [test_strict_mode_error.html]
 [test_third_party_iframes.html]
 [test_unregister.html]
 [test_workerUnregister.html]
 [test_workerUpdate.html]
 [test_workerupdatefoundevent.html]
+[test_opaque_intercept.html]
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/notify_loaded.js
@@ -0,0 +1,1 @@
+parent.postMessage('SCRIPT_LOADED', '*');
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/opaque_intercept_worker.js
@@ -0,0 +1,25 @@
+var name = 'opaqueInterceptCache';
+
+// Cross origin request to ensure that an opaque response is used
+var prefix = 'http://example.com/tests/dom/workers/test/serviceworkers/'
+
+self.addEventListener('install', function(event) {
+  var request = new Request(prefix + 'notify_loaded.js', { mode: 'no-cors' });
+  event.waitUntil(
+    Promise.all([caches.open(name), fetch(request)]).then(function(results) {
+      var cache = results[0];
+      var response = results[1];
+      return cache.put('./sw_clients/does_not_exist.js', response);
+    })
+  );
+});
+
+self.addEventListener('fetch', function (event) {
+  event.respondWith(
+    caches.open(name).then(function(cache) {
+      return cache.match(event.request);
+    }).then(function(response) {
+      return response || fetch(event.request);
+    })
+  );
+});
--- a/dom/workers/test/serviceworkers/sw_clients/refresher.html
+++ b/dom/workers/test/serviceworkers/sw_clients/refresher.html
@@ -1,27 +1,28 @@
 <!--
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Bug 982726 - test match_all not crashing</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <!-- some tests will intercept this bogus script request -->
+  <script type="text/javascript" src="does_not_exist.js"></script>
 </head>
 <body>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test"></pre>
 <script class="testbody" type="text/javascript">
 
   if (!parent) {
-    info("sw_clients/simple.html shouldn't be launched directly!");
+    dump("sw_clients/simple.html shouldn't be launched directly!");
   }
 
   window.addEventListener("message", function(event) {
     if (event.data === "REFRESH") {
       window.location.reload();
     } else if (event.data === "FORCE_REFRESH") {
       window.location.reload(true);
     }
index 3cf1f6a4fbf4f39ded4568d475792bf44d4566f1..7a45bcafabffd7063334187b0fe536ad758b2e5a
GIT binary patch
literal 608
zc$@)X0-yaKiwFqmFnU!019D|%a%FR9WpXZPbZu+^jZ;le8!-^Q=T}U8X{efY%b_1M
z8;L>?2M{PARh%Nn9<m0nz4dq#wpIUo$GZe^Xr-R)ef#FUnYXjE@pL)@IQAXr&~(vm
zssxt6ps`vdG>`(M3gNn4JFDR|)XMsTORAKbBPn%6mFyOEsO#XV2yr8uo@;ul{E0Eh
z55;>qnoj4V+4%J8<o51*0q3`u7yMkM+T{b4nX~FF+2nBkt=+(v&xfB5Kf)9eQi56~
zU9FUJ;6nl(6;;-6W^&-?N@x8eM0BN~)H$RIF$qXrgQZCLl%ysSP({2ih0K~HZ*1K-
zyybfj6g@-sYMcvDsIhk^*jaYAK4H|@Bu<1gT8B+bKss7RBK~M|pLs|we@0)qKd7x5
zPyrNmDNI0G@h~fVvh4jpVm^}tg9DL6BC~Zc9Ul!?!zGp)r@BmR7&La<!#Z$dKI`Ve
zUuZ`hmB&nGV%CV*)AK~VMC9Q1ooc6uhIiRg{G;{xh^MpnFc~*0vgZN(VgSIjbu$sP
zTWMz*CP{s?MgF`%RcM{@ZxXB#oNB$Uc(II)sFUl);@~T5{Lacd>rL1d%9zELWiB`v
z^cW|iMk2LA@eb~}JlWtUxP9fHTk3(rsHC7QOAyP&*>Z7nF7})kc^7!KS)$-=3Cc`*
zf9?R#5&l)`>}q+kSpBzPiY@L%^JskM!>g^`s1#yB7`ImA_Yfa3a*;A!!9SUwybQOu
u7*Z~pK<RRbV8U}9pWbm2;_Y*CS^o9v3?EiLuZ|pkvC$vXT}{O60{{TL5h^JF
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/test_opaque_intercept.html
@@ -0,0 +1,86 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 982726 - Test service worker post message </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 class="testbody" type="text/javascript">
+  var registration;
+  function start() {
+    return navigator.serviceWorker.register("opaque_intercept_worker.js",
+                                            { scope: "./sw_clients/" })
+      .then((swr) => registration = swr);
+  }
+
+  function unregister() {
+    return registration.unregister().then(function(result) {
+      ok(result, "Unregister should return true.");
+    }, function(e) {
+      dump("Unregistering the SW failed with " + e + "\n");
+    });
+  }
+
+
+  function testOpaqueIntercept(swr) {
+    var p = new Promise(function(res, rej) {
+      var ready = false;
+      var scriptLoaded = false;
+      window.onmessage = function(e) {
+        if (e.data === "READY") {
+          ok(!ready, "ready message should only be received once");
+          ok(!scriptLoaded, "ready message should be received before script loaded");
+          if (ready) {
+            res();
+            return;
+          }
+          ready = true;
+          iframe.contentWindow.postMessage("REFRESH", "*");
+        } else if (e.data === "SCRIPT_LOADED") {
+          ok(ready, "script loaded should be received after ready");
+          ok(!scriptLoaded, "script loaded message should be received only once");
+          scriptLoaded = true;
+          res();
+        }
+      }
+    });
+
+    var content = document.getElementById("content");
+    ok(content, "Parent exists.");
+
+    iframe = document.createElement("iframe");
+    iframe.setAttribute('src', "sw_clients/refresher.html");
+    content.appendChild(iframe);
+
+    return p.then(() => content.removeChild(iframe));
+  }
+
+  function runTest() {
+    start()
+      .then(testOpaqueIntercept)
+      .then(unregister)
+      .catch(function(e) {
+        ok(false, "Some test failed with error " + e);
+      }).then(SimpleTest.finish);
+  }
+
+  SimpleTest.waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({"set": [
+    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
+    ["dom.serviceWorkers.enabled", true],
+    ["dom.serviceWorkers.testing.enabled", true],
+    ["dom.serviceWorkers.interception.opaque.enabled", true],
+    ["dom.caches.enabled", true],
+  ]}, runTest);
+</script>
+</pre>
+</body>
+</html>