Bug 1164397 - Part 7: Add a test case for the redirected Response object being stored in the DOM Cache; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 28 May 2015 14:06:19 -0400
changeset 247526 c28b933c091d26196bbd61c408006fb2d77a3b2a
parent 247525 9fe75f3e2131b2671d909290a083b33db8e4351d
child 247527 cbc748ab81ee24c8bde9ba22753cfe5cea503287
push id28870
push usercbook@mozilla.com
push dateMon, 08 Jun 2015 09:58:36 +0000
treeherdermozilla-central@4700d1cdf489 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1164397
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 1164397 - Part 7: Add a test case for the redirected Response object being stored in the DOM Cache; r=jdm
dom/workers/test/serviceworkers/fetch/origin/origin_test.js
dom/workers/test/serviceworkers/fetch/origin/realindex.html^headers^
dom/workers/test/serviceworkers/mochitest.ini
dom/workers/test/serviceworkers/test_origin_after_redirect.html
dom/workers/test/serviceworkers/test_origin_after_redirect_cached.html
--- a/dom/workers/test/serviceworkers/fetch/origin/origin_test.js
+++ b/dom/workers/test/serviceworkers/fetch/origin/origin_test.js
@@ -1,3 +1,23 @@
+var prefix = "/tests/dom/workers/test/serviceworkers/fetch/origin/";
+
+self.addEventListener("install", function(event) {
+  event.waitUntil(
+    self.caches.open("origin-cache")
+      .then(c => {
+        return c.add(prefix + 'index.sjs');
+      })
+  );
+});
+
 self.addEventListener("fetch", function(event) {
-  event.respondWith(fetch(event.request));
+  if (event.request.url.indexOf("index-cached.sjs") >= 0) {
+    event.respondWith(
+      self.caches.open("origin-cache")
+        .then(c => {
+          return c.match(prefix + 'index.sjs');
+        })
+    );
+  } else {
+    event.respondWith(fetch(event.request));
+  }
 });
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/fetch/origin/realindex.html^headers^
@@ -0,0 +1,1 @@
+Access-Control-Allow-Origin: http://mochi.test:8888
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -44,16 +44,17 @@ support-files =
   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/origin/index.sjs
   fetch/origin/realindex.html
+  fetch/origin/realindex.html^headers^
   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
   fetch/requesturl/register.html
   fetch/requesturl/requesturl_test.js
@@ -160,8 +161,9 @@ support-files =
 [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]
 [test_origin_after_redirect.html]
+[test_origin_after_redirect_cached.html]
--- a/dom/workers/test/serviceworkers/test_origin_after_redirect.html
+++ b/dom/workers/test/serviceworkers/test_origin_after_redirect.html
@@ -43,14 +43,15 @@
   }
 
   SimpleTest.waitForExplicitFinish();
   onload = function() {
     SpecialPowers.pushPrefEnv({"set": [
       ["dom.serviceWorkers.exemptFromPerDomainMax", true],
       ["dom.serviceWorkers.enabled", true],
       ["dom.serviceWorkers.testing.enabled", true],
+      ["dom.caches.enabled", true],
     ]}, runTest);
   };
 </script>
 </pre>
 </body>
 </html>
copy from dom/workers/test/serviceworkers/test_origin_after_redirect.html
copy to dom/workers/test/serviceworkers/test_origin_after_redirect_cached.html
--- a/dom/workers/test/serviceworkers/test_origin_after_redirect.html
+++ b/dom/workers/test/serviceworkers/test_origin_after_redirect_cached.html
@@ -21,17 +21,17 @@
   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");
+        win = window.open("/tests/dom/workers/test/serviceworkers/fetch/origin/index-cached.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") {
@@ -43,14 +43,15 @@
   }
 
   SimpleTest.waitForExplicitFinish();
   onload = function() {
     SpecialPowers.pushPrefEnv({"set": [
       ["dom.serviceWorkers.exemptFromPerDomainMax", true],
       ["dom.serviceWorkers.enabled", true],
       ["dom.serviceWorkers.testing.enabled", true],
+      ["dom.caches.enabled", true],
     ]}, runTest);
   };
 </script>
 </pre>
 </body>
 </html>