Bug 1425975 P15 Add session lifetime policy checks to test_third_party_iframe.html. r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 05 Jan 2018 12:10:22 -0500
changeset 397972 93e07d0261cb5b1025545263c22ac024ffa911c9
parent 397971 e7b92985e941f7f1b9b562fba75b0b764b1ce6a9
child 397973 5b1109ca1c1f887a793748f1e115152a42122151
push id98650
push userbkelly@mozilla.com
push dateFri, 05 Jan 2018 17:10:31 +0000
treeherdermozilla-inbound@141238320685 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1425975
milestone59.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 1425975 P15 Add session lifetime policy checks to test_third_party_iframe.html. r=asuth
dom/workers/test/serviceworkers/test_third_party_iframes.html
--- a/dom/workers/test/serviceworkers/test_third_party_iframes.html
+++ b/dom/workers/test/serviceworkers/test_third_party_iframes.html
@@ -77,19 +77,20 @@ function runTest(aExpectedResponses) {
       ok(false, "Expected " + expected.status + " got " + status);
     }
     responsesIndex++;
   };
 }
 
 // Verify that we can register and intercept a 3rd party iframe with
 // the given cookie policy.
-function testShouldIntercept(policy, done) {
+function testShouldIntercept(behavior, lifetime, done) {
   SpecialPowers.pushPrefEnv({"set": [
-      ["network.cookie.cookieBehavior", policy]
+      ["network.cookie.cookieBehavior", behavior],
+      ["network.cookie.lifetimePolicy", lifetime],
   ]}, function() {
     runTest([{
       status: "ok"
     }, {
       status: "registrationdone",
       next: function() {
         iframe.addEventListener("load", testIframeLoaded);
         iframe.src = origin + basePath + "iframe1.html";
@@ -116,19 +117,20 @@ function testShouldIntercept(policy, don
         done();
       }
     }]);
   });
 }
 
 // Verify that we cannot register a service worker in a 3rd party
 // iframe with the given cookie policy.
-function testShouldNotRegister(policy, done) {
+function testShouldNotRegister(behavior, lifetime, done) {
   SpecialPowers.pushPrefEnv({"set": [
-      ["network.cookie.cookieBehavior", policy]
+      ["network.cookie.cookieBehavior", behavior],
+      ["network.cookie.lifetimePolicy", lifetime],
   ]}, function() {
     runTest([{
       status: "registrationfailed",
       next: function() {
         iframe.addEventListener("load", testIframeLoaded);
         iframe.src = origin + basePath + "iframe1.html";
       }
     }, {
@@ -147,28 +149,30 @@ function testShouldNotRegister(policy, d
       }
     }]);
   });
 }
 
 // Verify that if a service worker is already registered a 3rd
 // party iframe will still not be intercepted with the given cookie
 // policy.
-function testShouldNotIntercept(policy, done) {
+function testShouldNotIntercept(behavior, lifetime, done) {
   SpecialPowers.pushPrefEnv({"set": [
-      ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_ACCEPT]
+    ["network.cookie.cookieBehavior", BEHAVIOR_ACCEPT],
+    ["network.cookie.lifetimePolicy", LIFETIME_EXPIRE],
   ]}, function() {
     runTest([{
       status: "ok"
     }, {
       status: "registrationdone",
       next: function() {
         iframe.addEventListener("load", testIframeLoaded);
         SpecialPowers.pushPrefEnv({"set": [
-            ["network.cookie.cookieBehavior", policy],
+            ["network.cookie.cookieBehavior", behavior],
+            ["network.cookie.lifetimePolicy", lifetime],
           ]}, function() {
             iframe.src = origin + basePath + "iframe1.html";
           });
       }
     }, {
       status: "networkresponse",
     }, {
       status: "worker-networkresponse",
@@ -181,17 +185,18 @@ function testShouldNotIntercept(policy, 
         iframe.src = thirdPartyOrigin + basePath + "unregister.html";
       }
     }, {
       status: "uncontrolled",
     }, {
       status: "getregistrationfailed",
       next: function() {
         SpecialPowers.pushPrefEnv({"set": [
-            ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_ACCEPT],
+            ["network.cookie.cookieBehavior", BEHAVIOR_ACCEPT],
+            ["network.cookie.lifetimePolicy", LIFETIME_EXPIRE],
           ]}, function() {
             iframe.src = thirdPartyOrigin + basePath + "unregister.html";
           });
       }
     }, {
       status: "controlled",
     }, {
       status: "unregistrationdone",
@@ -199,41 +204,59 @@ function testShouldNotIntercept(policy, 
         window.onmessage = null;
         ok(true, "Test finished successfully");
         done();
       }
     }]);
   });
 }
 
-const COOKIE_BEHAVIOR_ACCEPT        = 0;
-const COOKIE_BEHAVIOR_REJECTFOREIGN = 1;
-const COOKIE_BEHAVIOR_REJECT        = 2;
-const COOKIE_BEHAVIOR_LIMITFOREIGN  = 3;
+const BEHAVIOR_ACCEPT        = 0;
+const BEHAVIOR_REJECTFOREIGN = 1;
+const BEHAVIOR_REJECT        = 2;
+const BEHAVIOR_LIMITFOREIGN  = 3;
+
+const LIFETIME_EXPIRE        = 0;
+const LIFETIME_SESSION       = 2;
 
 let steps = [() => {
   SpecialPowers.pushPrefEnv({"set": [
     ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     ["dom.serviceWorkers.enabled", true],
     ["dom.serviceWorkers.testing.enabled", true],
     ["browser.dom.window.dump.enabled", true],
-    ["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_ACCEPT]
+    ["network.cookie.cookieBehavior", BEHAVIOR_ACCEPT],
+    ["network.cookie.lifetimePolicy", LIFETIME_EXPIRE],
   ]}, next);
 }, () => {
-  testShouldIntercept(COOKIE_BEHAVIOR_ACCEPT, next);
+  testShouldIntercept(BEHAVIOR_ACCEPT, LIFETIME_EXPIRE, next);
+}, () => {
+  testShouldNotRegister(BEHAVIOR_REJECTFOREIGN, LIFETIME_EXPIRE, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_REJECTFOREIGN, LIFETIME_EXPIRE, next);
 }, () => {
-  testShouldNotRegister(COOKIE_BEHAVIOR_REJECTFOREIGN, next);
+  testShouldNotRegister(BEHAVIOR_REJECT, LIFETIME_EXPIRE, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_REJECT, LIFETIME_EXPIRE, next);
 }, () => {
-  testShouldNotIntercept(COOKIE_BEHAVIOR_REJECTFOREIGN, next);
+  testShouldNotRegister(BEHAVIOR_LIMITFOREIGN, LIFETIME_EXPIRE, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_LIMITFOREIGN, LIFETIME_EXPIRE, next);
 }, () => {
-  testShouldNotRegister(COOKIE_BEHAVIOR_REJECT, next);
+  testShouldNotIntercept(BEHAVIOR_ACCEPT, LIFETIME_SESSION, next);
 }, () => {
-  testShouldNotIntercept(COOKIE_BEHAVIOR_REJECT, next);
+  testShouldNotRegister(BEHAVIOR_REJECTFOREIGN, LIFETIME_SESSION, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_REJECTFOREIGN, LIFETIME_SESSION, next);
 }, () => {
-  testShouldNotRegister(COOKIE_BEHAVIOR_LIMITFOREIGN, next);
+  testShouldNotRegister(BEHAVIOR_REJECT, LIFETIME_SESSION, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_REJECT, LIFETIME_SESSION, next);
 }, () => {
-  testShouldNotIntercept(COOKIE_BEHAVIOR_LIMITFOREIGN, next);
+  testShouldNotRegister(BEHAVIOR_LIMITFOREIGN, LIFETIME_SESSION, next);
+}, () => {
+  testShouldNotIntercept(BEHAVIOR_LIMITFOREIGN, LIFETIME_SESSION, next);
 }];
 
 </script>
 </pre>
 </body>
 </html>