Bug 1164397 - Part 8: Add a test case for the service worker for an app:// URI responding with a redirected Response; r=jdm
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 04 Jun 2015 16:32:31 -0400
changeset 247527 cbc748ab81ee24c8bde9ba22753cfe5cea503287
parent 247526 c28b933c091d26196bbd61c408006fb2d77a3b2a
child 247528 a675f30287e97d3d0b94c9be9046b3f1cfefa414
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 8: Add a test case for the service worker for an app:// URI responding with a redirected Response; r=jdm
dom/workers/test/serviceworkers/app-protocol/application.zip
dom/workers/test/serviceworkers/app-protocol/controlled.html
dom/workers/test/serviceworkers/app-protocol/realindex.html
dom/workers/test/serviceworkers/app-protocol/realindex.html^headers^
dom/workers/test/serviceworkers/app-protocol/redirect.sjs
dom/workers/test/serviceworkers/app-protocol/sw.js
dom/workers/test/serviceworkers/app-protocol/test.js
dom/workers/test/serviceworkers/test_app_protocol.html
index 4cc5b89a08ef418e4b76784a174041392570442f..e6c3ceb90acb8b5a7f813fe55bfbc6bcc562b70e
GIT binary patch
literal 3077
zc$|fn3pmsJAIE>p%v?@#Cq!+UL@o)jI;;?lnfu6nF~+p5Ly^=mQf{%bN`#fURpgRN
zu4}nO5+NiUosfGZ#aTJ$<oWCL|2@z5`Tf4n^LyUk&-1+A-_Pfbu>|o+001BWFhkj<
zf(FHxJb3`%H7@{c0OSF0QV^9)A`<aF8h+G3qP-my01eL^wSUK5$3lew9=;FUzrP7w
z!?sz}X-b@Y?O2~f)WivD(@MdYKaI+OrgME7`mS`tl`9H26`#^0+?+6uVWdX&Qmk4k
z4Hi4Tv=bM#Pbuk6Tp=fM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*;8io-Tg}g#{+vYc0zR4?pty-Qvv71Me0DEZxQ#0PmL^ECU5PZ8)lj%`9k?U
z^_eqPnqPpo!xn)(+WRsqgYCm5a;{K!-D5JZ1O6fDQF8^00Xa+zc^BIHiA?dpEVM4e
z?efZw0+HuZk{Oe++saKfnm59c9SwYsJZj`{!uR>|6mKayU;<PHjayH5luA6QA+X}R
zE>QKTTk;iZ6f-?62#}jLT67E+!RI1lW4On;rfsKaF*#h;F-VP&sQL?5N8<&*(|Psy
z{^&W0C9-zxoAgdSC6)j|_oGqVZ(a(i%Fc+Y{nF;TIuXyZb`j6txy^Sh->ZIyU{8RS
z%;6f;W)|g4!^QqE`xXbifys&O=&BesTw=oTuY>pf%IKa(XKT^1H?L)1ciH1=K9>_N
z!(;Ov61RDhF%fgl-QHxzD2o@dtl(mcd68)lr#46ILJ33&3p`??Xkkt^Tfy;q>Umbt
zv90><<E$%&o(J3gW->F_!F+!fp6qz6zV~5;TkC{$NK<#X)?_+KFr&P2ld%&8$+Nts
znc}H+rhAE3;|_6mXzo(@`&zjBki6ZABu^iALJ$>C_QnTO38bKZE=#{T=|`<qgi|CE
zsVU4?ov!)_1XGFJh(Iuuo+NlR)MLl1KLz)}|B!0Gw^^;l>oBx~*FRSDfV?wZ+7-F1
z{h1vIb7o8hQ;Gz071R9E%HM!6mOQ+Qp#O?%GT*`hcMC92fBjk)-oUHj?SBef75%Sd
zu~syX`}#L$fLC+I55@i~R;(5K#C@#|8Q|5B@e{rEGj6S3CHI7N6A!#P@qQw@elD#Q
zb>jp6nNr}@DfJVn_1$!>)GQeI-dn+|z4a$z>pi$uOb`nEKSzRB9l7oZFhB4OECev&
K)>#Psy88>Fa<?}C
--- a/dom/workers/test/serviceworkers/app-protocol/controlled.html
+++ b/dom/workers/test/serviceworkers/app-protocol/controlled.html
@@ -12,15 +12,16 @@ function runTests() {
     .then(() => {
         return testFetchAppResource('foo.txt',
                                     'swresponse', 'text/plain');
     })
     .then(() => {
         return testFetchAppResource('test_custom_content_type',
                                     'customContentType', 'text/html');
     })
+    .then(testRedirectedResponse)
     .then(done);
 }
   </script>
   </head>
   <body onload='runTests()'>
   </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/app-protocol/realindex.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+real index
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/app-protocol/realindex.html^headers^
@@ -0,0 +1,1 @@
+Access-Control-Allow-Origin: *
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/serviceworkers/app-protocol/redirect.sjs
@@ -0,0 +1,5 @@
+function handleRequest(request, response) {
+  response.setStatusLine(null, 308, "Permanent Redirect");
+  response.setHeader("Access-Control-Allow-Origin", "*", false);
+  response.setHeader("Location", "http://example.org/tests/dom/workers/test/serviceworkers/app-protocol/realindex.html", false);
+}
--- a/dom/workers/test/serviceworkers/app-protocol/sw.js
+++ b/dom/workers/test/serviceworkers/app-protocol/sw.js
@@ -12,9 +12,13 @@ self.addEventListener('fetch', (event) =
     }));
   }
 
   if (event.request.url.indexOf('test_custom_content_type') >= 0) {
     event.respondWith(new Response('customContentType', {
       headers: {'Content-Type': 'text/html'}
     }));
   }
+
+  if (event.request.url.indexOf('redirected.html') >= 0) {
+    event.respondWith(fetch("http://example.com/tests/dom/workers/test/serviceworkers/app-protocol/redirect.sjs"));
+  }
 });
--- a/dom/workers/test/serviceworkers/app-protocol/test.js
+++ b/dom/workers/test/serviceworkers/app-protocol/test.js
@@ -32,8 +32,25 @@ function testFetchAppResource(aUrl,
          contentType + ' should match with ' + aExpectedContentType));
     }
     return res.text().then(body => {
       ok(body == aExpectedResponse, 'body ' + body +
          ' should match with ' + aExpectedResponse);
     });
   });
 }
+
+function testRedirectedResponse() {
+  // Because of the CSP policies applied to privileged apps, we cannot run
+  // inline script inside realindex.html, and loading a script from the app://
+  // URI is also not an option, so we let the parent iframe which has access
+  // to the SpecialPowers API use those privileges to access the document.
+  var iframe = document.createElement("iframe");
+  document.body.appendChild(iframe);
+  iframe.src = "redirected.html";
+  iframe.id = "redirected";
+  return new Promise(resolve => {
+    iframe.addEventListener("load", event => {
+      alert("IFRAMELOADED");
+      resolve();
+    }, false);
+  });
+}
--- a/dom/workers/test/serviceworkers/test_app_protocol.html
+++ b/dom/workers/test/serviceworkers/test_app_protocol.html
@@ -98,16 +98,22 @@ function loadControlled() {
     iframe.setAttribute('mozbrowser', 'true');
     iframe.setAttribute('mozapp', gApp.manifestURL);
     iframe.addEventListener('mozbrowsershowmodalprompt', function listener(e) {
       let message = e.detail.message;
       if (/OK/.exec(message)) {
         ok(true, "Message from app: " + message);
       } else if (/KO/.exec(message)) {
         ok(false, "Message from app: " + message);
+      } else if (/IFRAMELOADED/.exec(message)) {
+        let doc = SpecialPowers.wrap(iframe).contentDocument;
+        let innerDoc = SpecialPowers.wrap(doc.getElementById("redirected").contentDocument);
+        let innerLocation = innerDoc.defaultView.location;
+        is(innerDoc.domain, "example.org", "Correct domain expected");
+        is(innerLocation.origin, "http://example.org", "Correct origin expected");
       } else if (/DONE/.exec(message)) {
         ok(true, "Messaging from app complete");
         iframe.removeEventListener('mozbrowsershowmodalprompt', listener);
         let domParent = document.getElementById('container');
         domParent.removeChild(iframe);
         resolve();
       } else {
         ok(false, "Unexpected message received: " + message);