Bug 1330822 - Remove CPOWs from browser_no_mcb_on_http_site.js. r=Felipe draft
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 15 Nov 2016 15:10:49 -0800
changeset 460332 6cebfc421acf22be1c8e7e63d3ac73c8a544801e
parent 460331 2f1da34ab346cb7755409a11d28d23c7a3b87496
child 460333 2d9730c2d47a2594b090fa88b757649adefaf88d
push id41373
push userbmo:mrbkap@mozilla.com
push dateFri, 13 Jan 2017 00:11:03 +0000
reviewersFelipe
bugs1330822
milestone53.0a1
Bug 1330822 - Remove CPOWs from browser_no_mcb_on_http_site.js. r=Felipe
browser/base/content/test/general/browser_no_mcb_on_http_site.js
--- a/browser/base/content/test/general/browser_no_mcb_on_http_site.js
+++ b/browser/base/content/test/general/browser_no_mcb_on_http_site.js
@@ -23,116 +23,84 @@
  * should >> NOT << trigger a warning.
  */
 
 const PREF_ACTIVE = "security.mixed_content.block_active_content";
 const PREF_DISPLAY = "security.mixed_content.block_display_content";
 
 const gHttpTestRoot = "http://example.com/browser/browser/base/content/test/general/";
 
-var origBlockActive, origBlockDisplay;
 var gTestBrowser = null;
 
-registerCleanupFunction(function() {
-  // Set preferences back to their original values
-  Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
-  Services.prefs.setBoolPref(PREF_DISPLAY, origBlockDisplay);
-});
-
 function cleanUpAfterTests() {
   gBrowser.removeCurrentTab();
   window.focus();
-  finish();
 }
 
-function waitForCondition(condition, nextTest, errorMsg, okMsg) {
-  var tries = 0;
-  var interval = setInterval(function() {
-    if (tries >= 30) {
-      ok(false, errorMsg);
-      moveOn();
-    }
-    if (condition()) {
-      ok(true, okMsg)
-      moveOn();
-    }
-    tries++;
-  }, 100);
-  var moveOn = function() {
-    clearInterval(interval); nextTest();
-  };
-}
+add_task(function* init() {
+  yield SpecialPowers.pushPrefEnv({ set: [[ PREF_ACTIVE, true ],
+                                          [ PREF_DISPLAY, true ]] });
+  let url = gHttpTestRoot + "test_no_mcb_on_http_site_img.html";
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url)
+  gTestBrowser = tab.linkedBrowser;
+});
 
 // ------------- TEST 1 -----------------------------------------
 
-function test1A() {
-  gTestBrowser.removeEventListener("load", test1A, true);
-
-  var expected = "Verifying MCB does not trigger warning/error for an http page ";
+add_task(function* test1() {
+  let expected = "Verifying MCB does not trigger warning/error for an http page ";
   expected += "with https css that includes http image";
-  waitForCondition(
-    () => content.document.getElementById('testDiv').innerHTML == expected,
-    test1B, "Error: Waited too long for status in Test 1!",
-    "OK: Expected result in innerHTML!");
-}
+
+  yield ContentTask.spawn(gTestBrowser, expected, function* (condition) {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById('testDiv').innerHTML == condition,
+      "Waited too long for status in Test 1!");
+  });
 
-function test1B() {
+  // Explicit OKs needed because the harness requires at least one call to ok.
+  ok(true, "test 1 passed");
+
   // set up test 2
-  gTestBrowser.addEventListener("load", test2A, true);
-  var url = gHttpTestRoot + "test_no_mcb_on_http_site_font.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  let url = gHttpTestRoot + "test_no_mcb_on_http_site_font.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
 // ------------- TEST 2 -----------------------------------------
 
-function test2A() {
-  gTestBrowser.removeEventListener("load", test2A, true);
-
-  var expected = "Verifying MCB does not trigger warning/error for an http page ";
+add_task(function* test2() {
+  let expected = "Verifying MCB does not trigger warning/error for an http page ";
   expected += "with https css that includes http font";
-  waitForCondition(
-    () => content.document.getElementById('testDiv').innerHTML == expected,
-    test2B, "Error: Waited too long for status in Test 2!",
-    "OK: Expected result in innerHTML!");
-}
+
+  yield ContentTask.spawn(gTestBrowser, expected, function* (condition) {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById('testDiv').innerHTML == condition,
+      "Waited too long for status in Test 2!");
+  });
 
-function test2B() {
+  ok(true, "test 2 passed");
+
   // set up test 3
-  gTestBrowser.addEventListener("load", test3, true);
-  var url = gHttpTestRoot + "test_no_mcb_on_http_site_font2.html";
-  gTestBrowser.contentWindow.location = url;
-}
+  let url = gHttpTestRoot + "test_no_mcb_on_http_site_font2.html";
+  BrowserTestUtils.loadURI(gTestBrowser, url);
+  yield BrowserTestUtils.browserLoaded(gTestBrowser);
+});
 
 // ------------- TEST 3 -----------------------------------------
 
-function test3() {
-  gTestBrowser.removeEventListener("load", test3, true);
-
-  var expected = "Verifying MCB does not trigger warning/error for an http page "
+add_task(function* test3() {
+  let expected = "Verifying MCB does not trigger warning/error for an http page "
   expected += "with https css that imports another http css which includes http font";
-  waitForCondition(
-    () => content.document.getElementById('testDiv').innerHTML == expected,
-    cleanUpAfterTests, "Error: Waited too long for status in Test 3!",
-    "OK: Expected result in innerHTML!");
-}
+
+  yield ContentTask.spawn(gTestBrowser, expected, function* (condition) {
+    yield ContentTaskUtils.waitForCondition(
+      () => content.document.getElementById('testDiv').innerHTML == condition,
+      "Waited too long for status in Test 3!");
+  });
+
+  ok(true, "test3 passed");
+});
 
 // ------------------------------------------------------
 
-function test() {
-  // Performing async calls, e.g. 'onload', we have to wait till all of them finished
-  waitForExplicitFinish();
-
-  // Store original preferences so we can restore settings after testing
-  origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
-  origBlockDisplay = Services.prefs.getBoolPref(PREF_DISPLAY);
-
-  Services.prefs.setBoolPref(PREF_ACTIVE, true);
-  Services.prefs.setBoolPref(PREF_DISPLAY, true);
-
-  var newTab = gBrowser.addTab();
-  gBrowser.selectedTab = newTab;
-  gTestBrowser = gBrowser.selectedBrowser;
-  newTab.linkedBrowser.stop();
-
-  gTestBrowser.addEventListener("load", test1A, true);
-  var url = gHttpTestRoot + "test_no_mcb_on_http_site_img.html";
-  gTestBrowser.contentWindow.location = url;
-}
+add_task(function* cleanup() {
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});