Bug 1254148 - Fix browser_privacypane_8.js to run in e10s. r=gijs, a=test-only
authorJared Wein <jwein@mozilla.com>
Mon, 07 Mar 2016 12:34:21 -0500
changeset 325272 66c7e14adba69fd75d1024f2cb93286360a20c9b
parent 325271 23310a1c623289d20cb8b454ddc34c92e095a660
child 325273 c63a2db7aafa18f7a5374c2bd431f5fbf0274361
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs, test-only
bugs1254148
milestone47.0a2
Bug 1254148 - Fix browser_privacypane_8.js to run in e10s. r=gijs, a=test-only MozReview-Commit-ID: 9Xwmlk8jp9B
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_privacypane_1.js
browser/components/preferences/in-content/tests/browser_privacypane_3.js
browser/components/preferences/in-content/tests/browser_privacypane_4.js
browser/components/preferences/in-content/tests/browser_privacypane_5.js
browser/components/preferences/in-content/tests/browser_privacypane_8.js
browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -24,16 +24,15 @@ skip-if = true || !healthreport # Bug 11
 [browser_notifications_do_not_disturb.js]
 [browser_permissions_urlFieldHidden.js]
 [browser_proxy_backup.js]
 [browser_privacypane_1.js]
 [browser_privacypane_3.js]
 [browser_privacypane_4.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
-skip-if = e10s # Bug ?????? -  "leaked until shutdown [nsGlobalWindow #99 about:preferences]"
 [browser_sanitizeOnShutdown_prefLocked.js]
 [browser_searchsuggestions.js]
 [browser_subdialogs.js]
 support-files = subdialog.xul
 [browser_telemetry.js]
 # Skip this test on Android and B2G as FHR and Telemetry are separate systems there.
 skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android') || (os == 'b2g')
--- a/browser/components/preferences/in-content/tests/browser_privacypane_1.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_1.js
@@ -1,25 +1,18 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  requestLongerTimeout(2);
-
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
+let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+             getService(Ci.mozIJSSubScriptLoader);
 
-  let rootDir = getRootDirectory(gTestPath);
-  let jar = getJar(rootDir);
-  if (jar) {
-    let tmpdir = extractJarToTmp(jar);
-    rootDir = "file://" + tmpdir.path + '/';
-  }
-  loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + '/';
+}
+loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
 
-  run_test_subset([
-    test_pane_visibility,
-    test_dependent_elements,
-    test_dependent_cookie_elements,
-    test_dependent_clearonclose_elements,
-    test_dependent_prefs,
-  ]);
-}
+run_test_subset([
+  test_pane_visibility,
+  test_dependent_elements,
+  test_dependent_cookie_elements,
+  test_dependent_clearonclose_elements,
+  test_dependent_prefs,
+]);
--- a/browser/components/preferences/in-content/tests/browser_privacypane_3.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_3.js
@@ -1,22 +1,17 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
+let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+             getService(Ci.mozIJSSubScriptLoader);
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + '/';
+}
+loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
 
-function test() {
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
-  let rootDir = getRootDirectory(gTestPath);
-  let jar = getJar(rootDir);
-  if (jar) {
-    let tmpdir = extractJarToTmp(jar);
-    rootDir = "file://" + tmpdir.path + '/';
-  }
-  loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
-
-  run_test_subset([
-    test_custom_retention("rememberHistory", "remember"),
-    test_custom_retention("rememberHistory", "custom"),
-    test_custom_retention("rememberForms", "remember"),
-    test_custom_retention("rememberForms", "custom"),
-    test_historymode_retention("remember", "remember"),
-  ]);
-}
+run_test_subset([
+  test_custom_retention("rememberHistory", "remember"),
+  test_custom_retention("rememberHistory", "custom"),
+  test_custom_retention("rememberForms", "remember"),
+  test_custom_retention("rememberForms", "custom"),
+  test_historymode_retention("remember", "remember"),
+]);
--- a/browser/components/preferences/in-content/tests/browser_privacypane_4.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_4.js
@@ -1,33 +1,23 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-requestLongerTimeout(2);
-
-function test() {
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
-  let rootDir = getRootDirectory(gTestPath);
-  let jar = getJar(rootDir);
-  if (jar) {
-    let tmpdir = extractJarToTmp(jar);
-    rootDir = "file://" + tmpdir.path + '/';
-  }
-  loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
-  let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
+let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+             getService(Ci.mozIJSSubScriptLoader);
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + '/';
+}
+loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
+let runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
 
-  run_test_subset(Array.concat([
-    test_custom_retention("acceptCookies", "remember"),
-    test_custom_retention("acceptCookies", "custom")
-  ],
-    [
-    test_custom_retention("acceptThirdPartyMenu", "remember", "visited"),
-    test_custom_retention("acceptThirdPartyMenu", "custom", "always")
-    ], [
-    test_custom_retention("keepCookiesUntil", "remember", 1),
-    test_custom_retention("keepCookiesUntil", "custom", 2),
-    test_custom_retention("keepCookiesUntil", "custom", 0),
-    test_custom_retention("alwaysClear", "remember"),
-    test_custom_retention("alwaysClear", "custom"),
-    test_historymode_retention("remember", "remember"),
-  ]));
-}
+run_test_subset([
+  test_custom_retention("acceptCookies", "remember"),
+  test_custom_retention("acceptCookies", "custom"),
+  test_custom_retention("acceptThirdPartyMenu", "remember", "visited"),
+  test_custom_retention("acceptThirdPartyMenu", "custom", "always"),
+  test_custom_retention("keepCookiesUntil", "remember", 1),
+  test_custom_retention("keepCookiesUntil", "custom", 2),
+  test_custom_retention("keepCookiesUntil", "custom", 0),
+  test_custom_retention("alwaysClear", "remember"),
+  test_custom_retention("alwaysClear", "custom"),
+  test_historymode_retention("remember", "remember"),
+]);
--- a/browser/components/preferences/in-content/tests/browser_privacypane_5.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_5.js
@@ -1,24 +1,17 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
+let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+             getService(Ci.mozIJSSubScriptLoader);
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + '/';
+}
+loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
 
-function test() {
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
-  let rootDir = getRootDirectory(gTestPath);
-  let jar = getJar(rootDir);
-  if (jar) {
-    let tmpdir = extractJarToTmp(jar);
-    rootDir = "file://" + tmpdir.path + '/';
-  }
-  loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
-
-  let tests = [
-    test_locbar_suggestion_retention("history", true),
-    test_locbar_suggestion_retention("bookmark", true),
-    test_locbar_suggestion_retention("openpage", false),
-    test_locbar_suggestion_retention("history", true),
-    test_locbar_suggestion_retention("history", false),
-  ];
-
-  run_test_subset(tests);
-}
+run_test_subset([
+  test_locbar_suggestion_retention("history", true),
+  test_locbar_suggestion_retention("bookmark", true),
+  test_locbar_suggestion_retention("openpage", false),
+  test_locbar_suggestion_retention("history", true),
+  test_locbar_suggestion_retention("history", false),
+]);
--- a/browser/components/preferences/in-content/tests/browser_privacypane_8.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_8.js
@@ -1,31 +1,26 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-               getService(Ci.mozIJSSubScriptLoader);
-  let rootDir = getRootDirectory(gTestPath);
-  let jar = getJar(rootDir);
-  if (jar) {
-    let tmpdir = extractJarToTmp(jar);
-    rootDir = "file://" + tmpdir.path + '/';
-  }
-  loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
+let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
+             getService(Ci.mozIJSSubScriptLoader);
+let rootDir = getRootDirectory(gTestPath);
+let jar = getJar(rootDir);
+if (jar) {
+  let tmpdir = extractJarToTmp(jar);
+  rootDir = "file://" + tmpdir.path + '/';
+}
+loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this);
 
-  run_test_subset([
-    // history mode should be initialized to remember
-    test_historymode_retention("remember", undefined),
+run_test_subset([
+  // history mode should be initialized to remember
+  test_historymode_retention("remember", undefined),
 
-    // history mode should remain remember; toggle acceptCookies checkbox
-    test_custom_retention("acceptCookies", "remember"),
+  // history mode should remain remember; toggle acceptCookies checkbox
+  test_custom_retention("acceptCookies", "remember"),
 
-    // history mode should now be custom; set history mode to dontremember
-    test_historymode_retention("dontremember", "custom"),
+  // history mode should now be custom; set history mode to dontremember
+  test_historymode_retention("dontremember", "custom"),
 
-    // history mode should remain custom; set history mode to remember
-    test_historymode_retention("remember", "custom"),
+  // history mode should remain custom; set history mode to remember
+  test_historymode_retention("remember", "custom"),
 
-    // history mode should now be remember
-    test_historymode_retention("remember", "remember"),
-  ]);
-}
+  // history mode should now be remember
+  test_historymode_retention("remember", "remember"),
+]);
--- a/browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
+++ b/browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js
@@ -1,27 +1,17 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function runTestOnPrivacyPrefPane(testFunc) {
-  
-  gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
-    gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true);
-    let browser = aEvent.originalTarget.linkedBrowser;
-    browser.addEventListener("Initialized", function(aEvent) {
-      browser.removeEventListener("Initialized", arguments.callee, true);
-      is(browser.contentWindow.location.href, "about:preferences", "Checking if the preferences tab was opened");
-      browser.contentWindow.gotoPref("panePrivacy");
-      testFunc(browser.contentWindow);
-      gBrowser.removeCurrentTab();
-      testRunner.runNext();
-    }, true);
-  }, true);
-  
-  gBrowser.selectedTab = gBrowser.addTab("about:preferences");
+function* runTestOnPrivacyPrefPane(testFunc) {
+  info("runTestOnPrivacyPrefPane entered");
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences", true, true);
+  let browser = tab.linkedBrowser;
+  info("loaded about:preferences");
+  browser.contentWindow.gotoPref("panePrivacy");
+  info("viewing privacy pane, executing testFunc");
+  testFunc(browser.contentWindow);
+  yield BrowserTestUtils.removeTab(tab);
 }
 
 function controlChanged(element) {
   element.doCommand();
 }
 
 // We can only test the panes that don't trigger a preference update
 function test_pane_visibility(win) {
@@ -249,17 +239,17 @@ function test_dependent_prefs(win) {
   });
   expect_checked(false);
   historymode.value = "remember";
   controlChanged(historymode);
   expect_checked(true);
 }
 
 function test_historymode_retention(mode, expect) {
-  return function(win) {
+  return function test_historymode_retention_fn(win) {
     let historymode = win.document.getElementById("historyMode");
     ok(historymode, "history mode menulist should exist");
 
     if ((historymode.value == "remember" && mode == "dontremember") ||
         (historymode.value == "dontremember" && mode == "remember") ||
         (historymode.value == "custom" && mode == "dontremember")) {
       return;
     }
@@ -270,17 +260,17 @@ function test_historymode_retention(mode
     }
 
     historymode.value = mode;
     controlChanged(historymode);
   };
 }
 
 function test_custom_retention(controlToChange, expect, valueIncrement) {
-  return function(win) {
+  return function test_custom_retention_fn(win) {
     let historymode = win.document.getElementById("historyMode");
     ok(historymode, "history mode menulist should exist");
 
     if (expect !== undefined) {
       is(historymode.value, expect,
         "history mode is expected to remain " + expect);
     }
 
@@ -324,36 +314,17 @@ function cache_preferences(win) {
 }
 
 function reset_preferences(win) {
   let prefs = win.document.querySelectorAll("#privacyPreferences > preference");
   for (let pref of prefs)
     pref.value = gPrefCache.get(pref.name);
 }
 
-var testRunner;
 function run_test_subset(subset) {
-  Services.prefs.setBoolPref("browser.preferences.instantApply", true);
-  dump("subset: " + Array.from(subset, x => x.name).join(",") + "\n");
-
-  waitForExplicitFinish();
-  registerCleanupFunction(function() {
-    // Reset pref to its default
-    Services.prefs.clearUserPref("browser.preferences.instantApply");
-  });
+  info("subset: " + Array.from(subset, x => x.name).join(",") + "\n");
+  SpecialPowers.pushPrefEnv({"set": [["browser.preferences.instantApply", true]]});
 
-  testRunner = {
-    tests: [cache_preferences, ...subset, reset_preferences],
-    counter: 0,
-    runNext: function() {
-      if (this.counter == this.tests.length) {
-        finish();
-      } else {
-        let self = this;
-        setTimeout(function() {
-          runTestOnPrivacyPrefPane(self.tests[self.counter++]);
-        }, 0);
-      }
-    }
-  };
-
-  testRunner.runNext();
+  let tests = [cache_preferences, ...subset, reset_preferences];
+  for (let test of tests) {
+    add_task(runTestOnPrivacyPrefPane.bind(undefined, test));
+  }
 }