Bug 1253274 - Update browser_bug435325.js to use add_task and BrowserTestUtils. r=johannh
authorPrathiksha <prathikshaprasadsuman@gmail.com>
Mon, 15 May 2017 20:14:14 +0530
changeset 360628 23dfbd6437b86b2c7220c9cae9fcee98fb4997ed
parent 360627 98b85a78d45ff9168b080dbbf2bb45f5470b7769
child 360629 c4b678956b298236a4f6d7bbda404a72b0c12a79
push id43400
push userryanvm@gmail.com
push dateThu, 25 May 2017 13:32:49 +0000
treeherderautoland@23dfbd6437b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1253274, 435325
milestone55.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 1253274 - Update browser_bug435325.js to use add_task and BrowserTestUtils. r=johannh MozReview-Commit-ID: HTBqiWzi2NM
browser/base/content/test/general/browser_bug435325.js
--- a/browser/base/content/test/general/browser_bug435325.js
+++ b/browser/base/content/test/general/browser_bug435325.js
@@ -1,69 +1,44 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* Ensure that clicking the button in the Offline mode neterror page makes the browser go online. See bug 435325. */
 
-var proxyPrefValue;
-
-function test() {
-  waitForExplicitFinish();
+add_task(async function checkSwitchPageToOnlineMode() {
 
   // Go offline and disable the proxy and cache, then try to load the test URL.
   Services.io.offline = true;
 
   // Tests always connect to localhost, and per bug 87717, localhost is now
   // reachable in offline mode.  To avoid this, disable any proxy.
-  proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
-  Services.prefs.setIntPref("network.proxy.type", 0);
-
-  Services.prefs.setBoolPref("browser.cache.disk.enable", false);
-  Services.prefs.setBoolPref("browser.cache.memory.enable", false);
-
-  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "http://example.com/");
+  let proxyPrefValue = SpecialPowers.getIntPref("network.proxy.type");
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["network.proxy.type", 0],
+    ["browser.cache.disk.enable", false],
+    ["browser.cache.memory.enable", false],
+  ]});
 
-  let contentScript = `
-    let listener = function () {
-      removeEventListener("DOMContentLoaded", listener);
-      sendAsyncMessage("Test:DOMContentLoaded", { uri: content.document.documentURI });
-    };
-    addEventListener("DOMContentLoaded", listener);
-  `;
+  await BrowserTestUtils.withNewTab("about:blank", async function(browser) {
+    let netErrorLoaded = BrowserTestUtils.waitForErrorPage(browser);
 
-  function pageloaded({ data }) {
-    mm.removeMessageListener("Test:DOMContentLoaded", pageloaded);
-    checkPage(data);
-  }
+    await BrowserTestUtils.loadURI(browser, "http://example.com/");
+    await netErrorLoaded;
 
-  let mm = gBrowser.selectedBrowser.messageManager;
-  mm.addMessageListener("Test:DOMContentLoaded", pageloaded);
-  mm.loadFrameScript("data:," + contentScript, true);
-}
-
-function checkPage(data) {
-  ok(Services.io.offline, "Setting Services.io.offline to true.");
-
-  is(data.uri.substring(0, 27),
-     "about:neterror?e=netOffline", "Loading the Offline mode neterror page.");
+    // Re-enable the proxy so example.com is resolved to localhost, rather than
+    // the actual example.com.
+    await SpecialPowers.pushPrefEnv({"set": [["network.proxy.type", proxyPrefValue]]});
+    let changeObserved = TestUtils.topicObserved("network:offline-status-changed");
 
-  // Re-enable the proxy so example.com is resolved to localhost, rather than
-  // the actual example.com.
-  Services.prefs.setIntPref("network.proxy.type", proxyPrefValue);
+    // Click on the 'Try again' button.
+    await ContentTask.spawn(browser, null, function* () {
+      ok(content.document.documentURI.startsWith("about:neterror?e=netOffline"), "Should be showing error page");
+      content.document.getElementById("errorTryAgain").click();
+    });
 
-  Services.obs.addObserver(function observer(aSubject, aTopic) {
-    ok(!Services.io.offline, "After clicking the Try Again button, we're back " +
-                             "online.");
-    Services.obs.removeObserver(observer, "network:offline-status-changed");
-    finish();
-  }, "network:offline-status-changed");
-
-  ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
-    content.document.getElementById("errorTryAgain").click();
+    await changeObserved;
+    ok(!Services.io.offline, "After clicking the 'Try Again' button, we're back online.");
   });
-}
+});
 
 registerCleanupFunction(function() {
-  Services.prefs.setBoolPref("browser.cache.disk.enable", true);
-  Services.prefs.setBoolPref("browser.cache.memory.enable", true);
   Services.io.offline = false;
-  gBrowser.removeCurrentTab();
 });