Bug 1346286 - Remove CPOWs from browser_bug822367.js draft
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 09 Mar 2017 11:16:17 -0800
changeset 499548 3ee9ee96a2e87a96e411a720737fbade0581de3f
parent 499547 3cf6bf2c48622e9c9af2ed473e40f791ab2b414a
child 499549 2f3311619efef35ad97c6ffbe6e1fd0857afa722
push id49450
push userbmo:mrbkap@mozilla.com
push dateWed, 15 Mar 2017 23:51:54 +0000
bugs1346286, 822367
milestone55.0a1
Bug 1346286 - Remove CPOWs from browser_bug822367.js MozReview-Commit-ID: DHsQEyTgapN
browser/base/content/test/siteIdentity/browser_bug822367.js
--- a/browser/base/content/test/siteIdentity/browser_bug822367.js
+++ b/browser/base/content/test/siteIdentity/browser_bug822367.js
@@ -7,189 +7,181 @@ const PREF_DISPLAY = "security.mixed_con
 const PREF_ACTIVE = "security.mixed_content.block_active_content";
 
 // We alternate for even and odd test cases to simulate different hosts
 const HTTPS_TEST_ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
 const HTTPS_TEST_ROOT_2 = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://test1.example.com");
 
 var gTestBrowser = null;
 
-registerCleanupFunction(function() {
-  // Set preferences back to their original values
-  Services.prefs.clearUserPref(PREF_DISPLAY);
-  Services.prefs.clearUserPref(PREF_ACTIVE);
-});
-
-function MixedTestsCompleted() {
-  gBrowser.removeCurrentTab();
-  window.focus();
-  finish();
-}
-
-function test() {
-  waitForExplicitFinish();
-
-  Services.prefs.setBoolPref(PREF_DISPLAY, true);
-  Services.prefs.setBoolPref(PREF_ACTIVE, true);
+add_task(function* test() {
+  yield SpecialPowers.pushPrefEnv({ set: [[ PREF_DISPLAY, true ],
+                                          [ PREF_ACTIVE, true  ]] });
 
   var newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   gTestBrowser = gBrowser.selectedBrowser;
   newTab.linkedBrowser.stop()
 
   // Mixed Script Test
-  gTestBrowser.addEventListener("load", MixedTest1A, true);
   var url = HTTPS_TEST_ROOT + "file_bug822367_1.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
 // Mixed Script Test
-function MixedTest1A() {
-  gTestBrowser.removeEventListener("load", MixedTest1A, true);
-  gTestBrowser.addEventListener("load", MixedTest1B, true);
-
+add_task(function* MixedTest1A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest1B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 1").then(MixedTest1C);
-}
-function MixedTest1C() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 1");
-  gTestBrowser.removeEventListener("load", MixedTest1B, true);
-  MixedTest2();
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest1B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 1");
+  });
+});
 
 // Mixed Display Test - Doorhanger should not appear
-function MixedTest2() {
-  gTestBrowser.addEventListener("load", MixedTest2A, true);
+add_task(function* MixedTest2() {
   var url = HTTPS_TEST_ROOT_2 + "file_bug822367_2.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
 
-function MixedTest2A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: false, passiveLoaded: false});
-  MixedTest3();
-}
+});
 
 // Mixed Script and Display Test - User Override should cause both the script and the image to load.
-function MixedTest3() {
-  gTestBrowser.removeEventListener("load", MixedTest2A, true);
-  gTestBrowser.addEventListener("load", MixedTest3A, true);
+add_task(function* MixedTest3() {
   var url = HTTPS_TEST_ROOT + "file_bug822367_3.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest3A() {
-  gTestBrowser.removeEventListener("load", MixedTest3A, true);
-  gTestBrowser.addEventListener("load", MixedTest3B, true);
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest3A() {
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
+
+  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
+  gIdentityHandler.disableMixedContentProtection();
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
+add_task(function* MixedTest3B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    let p1 = ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 3");
+    let p2 = ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p2").innerHTML == "bye",
+      "Waited too long for mixed image to load in Test 3");
+    yield Promise.all([ p1, p2 ]);
+  });
+
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: true});
+});
+
+// Location change - User override on one page doesn't propogate to another page after location change.
+add_task(function* MixedTest4() {
+  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_4.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest4A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest3B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 3").then(MixedTest3C);
-}
-function MixedTest3C() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p2").innerHTML == "bye", "Waited too long for mixed image to load in Test 3").then(MixedTest3D);
-}
-function MixedTest3D() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 3");
-  ok(content.document.getElementById("p2").innerHTML == "bye", "Mixed image didn't load in Test 3");
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: true});
-  MixedTest4();
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest4B() {
+  let url = HTTPS_TEST_ROOT + "file_bug822367_4B.html";
+  yield ContentTask.spawn(gTestBrowser, url, function* (wantedUrl) {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.location == wantedUrl,
+      "Waited too long for mixed script to run in Test 4");
+  });
+});
+
+add_task(function* MixedTest4C() {
+  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
-// Location change - User override on one page doesn't propogate to another page after location change.
-function MixedTest4() {
-  gTestBrowser.removeEventListener("load", MixedTest3B, true);
-  gTestBrowser.addEventListener("load", MixedTest4A, true);
-  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_4.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest4A() {
-  gTestBrowser.removeEventListener("load", MixedTest4A, true);
-  gTestBrowser.addEventListener("load", MixedTest4B, true);
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "",
+      "Mixed script loaded in test 4 after location change!");
+  });
+});
 
+// Mixed script attempts to load in a document.open()
+add_task(function* MixedTest5() {
+  var url = HTTPS_TEST_ROOT + "file_bug822367_5.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
+
+add_task(function* MixedTest5A() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest4B() {
-  BrowserTestUtils.waitForCondition(() => content.document.location == HTTPS_TEST_ROOT + "file_bug822367_4B.html", "Waited too long for mixed script to run in Test 4").then(MixedTest4C);
-}
-function MixedTest4C() {
-  ok(content.document.location == HTTPS_TEST_ROOT + "file_bug822367_4B.html", "Location didn't change in test 4");
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
+add_task(function* MixedTest5B() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById("p1").innerHTML == "hello",
+      "Waited too long for mixed script to run in Test 5");
+  });
+});
 
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "", "Mixed script loaded in test 4 after location change!").then(MixedTest4D);
-}
-function MixedTest4D() {
-  ok(content.document.getElementById("p1").innerHTML == "", "p1.innerHTML changed; mixed script loaded after location change in Test 4");
-  MixedTest5();
-}
+// Mixed script attempts to load in a document.open() that is within an iframe.
+add_task(function* MixedTest6() {
+  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_6.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-// Mixed script attempts to load in a document.open()
-function MixedTest5() {
-  gTestBrowser.removeEventListener("load", MixedTest4B, true);
-  gTestBrowser.addEventListener("load", MixedTest5A, true);
-  var url = HTTPS_TEST_ROOT + "file_bug822367_5.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest5A() {
-  gTestBrowser.removeEventListener("load", MixedTest5A, true);
-  gTestBrowser.addEventListener("load", MixedTest5B, true);
+add_task(function* MixedTest6A() {
+  gTestBrowser.removeEventListener("load", MixedTest6A, true);
+  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
 
+  yield BrowserTestUtils.waitForCondition(
+    () => gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"),
+    "Waited too long for control center to get mixed active blocked state");
+});
+
+add_task(function* MixedTest6B() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
 
   let {gIdentityHandler} = gTestBrowser.ownerGlobal;
   gIdentityHandler.disableMixedContentProtection();
-}
-function MixedTest5B() {
-  BrowserTestUtils.waitForCondition(() => content.document.getElementById("p1").innerHTML == "hello", "Waited too long for mixed script to run in Test 5").then(MixedTest5C);
-}
-function MixedTest5C() {
-  ok(content.document.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 5");
-  MixedTest6();
-}
 
-// Mixed script attempts to load in a document.open() that is within an iframe.
-function MixedTest6() {
-  gTestBrowser.removeEventListener("load", MixedTest5B, true);
-  gTestBrowser.addEventListener("load", MixedTest6A, true);
-  var url = HTTPS_TEST_ROOT_2 + "file_bug822367_6.html";
-  gTestBrowser.contentWindow.location = url;
-}
-function MixedTest6A() {
-  gTestBrowser.removeEventListener("load", MixedTest6A, true);
-  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
-  BrowserTestUtils.waitForCondition(() => gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"), "Waited too long for control center to get mixed active blocked state").then(MixedTest6B);
-}
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
-function MixedTest6B() {
-  gTestBrowser.addEventListener("load", MixedTest6C, true);
-
-  assertMixedContentBlockingState(gTestBrowser, {activeLoaded: false, activeBlocked: true, passiveLoaded: false});
-
-  let {gIdentityHandler} = gTestBrowser.ownerGlobal;
-  gIdentityHandler.disableMixedContentProtection();
-}
+add_task(function* MixedTest6C() {
+  yield ContentTask.spawn(gTestBrowser, null, function* () {
+    function test() {
+      try {
+        return content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello";
+      } catch (e) {
+        return false;
+      }
+    }
 
-function MixedTest6C() {
-  gTestBrowser.removeEventListener("load", MixedTest6C, true);
-  BrowserTestUtils.waitForCondition(function() {
-    try {
-      return content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello";
-    } catch (e) {
-      return false;
-    }
-  }, "Waited too long for mixed script to run in Test 6").then(MixedTest6D);
-}
-function MixedTest6D() {
-  ok(content.document.getElementById("f1").contentDocument.getElementById("p1").innerHTML == "hello", "Mixed script didn't load in Test 6");
+    yield ContentTaskUtils.waitForCondition(test, "Waited too long for mixed script to run in Test 6");
+  });
+});
+
+add_task(function* MixedTest6D() {
   assertMixedContentBlockingState(gTestBrowser, {activeLoaded: true, activeBlocked: false, passiveLoaded: false});
-  MixedTestsCompleted();
-}
+});
+
+add_task(function* cleanup() {
+  gBrowser.removeCurrentTab();
+});