Bug 731866 - Copy and port current preference tests to run against the in-content preferences. r=jaws
authorZuhao (Joe) Chen <joejoevictor@gmail.com>
Tue, 08 May 2012 19:33:14 -0700
changeset 93583 8b195889f55cc8feb0517352261e46afbd32218c
parent 93582 9b4f86c85565c3da346592d86a2c65a4bfc2c481
child 93584 a251bada10b54c94469b4f237d8ad50b129308bb
push id9210
push userjwein@mozilla.com
push dateWed, 09 May 2012 05:35:43 +0000
treeherdermozilla-inbound@8b195889f55c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs731866
milestone15.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 731866 - Copy and port current preference tests to run against the in-content preferences. r=jaws
browser/components/preferences/in-content/Makefile.in
browser/components/preferences/in-content/tests/Makefile.in
browser/components/preferences/in-content/tests/browser_bug410900.js
browser/components/preferences/in-content/tests/browser_bug567487.js
browser/components/preferences/in-content/tests/browser_bug731866.js
browser/components/preferences/in-content/tests/browser_privacypane_1.js
browser/components/preferences/in-content/tests/browser_privacypane_2.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_6.js
browser/components/preferences/in-content/tests/browser_privacypane_7.js
browser/components/preferences/in-content/tests/browser_privacypane_8.js
browser/components/preferences/in-content/tests/head.js
browser/components/preferences/in-content/tests/privacypane_tests.js
--- a/browser/components/preferences/in-content/Makefile.in
+++ b/browser/components/preferences/in-content/Makefile.in
@@ -4,16 +4,18 @@
 
 DEPTH		= ../../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
+TEST_DIRS += tests
+
 include $(topsrcdir)/config/rules.mk
 
 DEFINES += \
 	-DMOZ_APP_NAME=$(MOZ_APP_NAME) \
 	-DMOZ_MACBUNDLE_NAME=$(MOZ_MACBUNDLE_NAME) \
 	$(NULL)
 
 ifneq (,$(filter windows gtk2 cocoa, $(MOZ_WIDGET_TOOLKIT)))
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/Makefile.in
@@ -0,0 +1,31 @@
+# -- This Source Code Form is subject to the terms of the Mozilla Public
+#  - License, v. 2.0. If a copy of the MPL was not distributed with this file,
+#  - You can obtain one at http://mozilla.org/MPL/2.0/.
+
+DEPTH		= ../../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+relativesrcdir  = browser/components/preferences/in-content/tests
+
+include $(DEPTH)/config/autoconf.mk
+include $(topsrcdir)/config/rules.mk
+
+_BROWSER_FILES = \
+    head.js \
+    browser_bug410900.js \
+    browser_bug567487.js \
+    browser_bug731866.js \
+    privacypane_tests.js \
+    browser_privacypane_1.js \
+    browser_privacypane_2.js \
+    browser_privacypane_3.js \
+    browser_privacypane_4.js \
+    browser_privacypane_5.js \
+    browser_privacypane_6.js \
+    browser_privacypane_7.js \
+    browser_privacypane_8.js \
+    $(NULL)
+
+libs::	$(_BROWSER_FILES)
+	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_bug410900.js
@@ -0,0 +1,58 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
+Components.utils.import("resource://gre/modules/NetUtil.jsm");
+
+function test() {
+  waitForExplicitFinish();
+
+  // Setup a phony handler to ensure the app pane will be populated.
+  var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
+                createInstance(Ci.nsIWebHandlerApp);
+  handler.name = "App pane alive test";
+  handler.uriTemplate = "http://test.mozilla.org/%s";
+
+  var extps = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
+              getService(Ci.nsIExternalProtocolService);
+  var info = extps.getProtocolHandlerInfo("apppanetest");
+  info.possibleApplicationHandlers.appendElement(handler, false);
+
+  var hserv = Cc["@mozilla.org/uriloader/handler-service;1"].
+              getService(Ci.nsIHandlerService);
+  hserv.store(info);
+
+  function observer(win, topic, data) {
+    if (topic != "app-handler-pane-loaded")
+      return;
+
+    Services.obs.removeObserver(observer, "app-handler-pane-loaded");
+    runTest(win);
+  }
+  Services.obs.addObserver(observer, "app-handler-pane-loaded", false);
+
+  gBrowser.selectedTab = gBrowser.addTab("about:preferences");
+}
+
+function runTest(win) {
+  win.gotoPref("applications");
+  var sel = win.history.state;
+  ok(sel == "applications", "Specified pane was opened");
+
+  var rbox = win.document.getElementById("handlersView");
+  ok(rbox, "handlersView is present");
+
+  var items = rbox && rbox.getElementsByTagName("richlistitem");
+  ok(items && items.length > 0, "App handler list populated");
+
+  var handlerAdded = false;
+  for (let i = 0; i < items.length; i++) {
+    if (items[i].getAttribute('type') == "apppanetest")
+      handlerAdded = true;
+  }
+  ok(handlerAdded, "apppanetest protocol handler was successfully added");
+
+  gBrowser.removeCurrentTab();
+  win.close();
+  finish();
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_bug567487.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  waitForExplicitFinish();
+  resetPreferences();
+
+  function observer(win, topic, data) {
+    if (topic != "main-pane-loaded")
+      return;
+
+    Services.obs.removeObserver(observer, "main-pane-loaded");
+    runTest(win);
+  }
+  Services.obs.addObserver(observer, "main-pane-loaded", false);
+
+  gBrowser.selectedTab = gBrowser.addTab("about:preferences");
+}
+
+function runTest(win) {
+  win.gotoPref("general");
+  let doc = win.document;
+  let pbAutoStartPref = doc.getElementById("browser.privatebrowsing.autostart");
+  let startupPref = doc.getElementById("browser.startup.page");
+  let menu = doc.getElementById("browserStartupPage");
+  let option = doc.getElementById("browserStartupLastSession");
+  let defOption = doc.getElementById("browserStartupHomePage");
+  let otherOption = doc.getElementById("browserStartupBlank");
+
+  ok(!pbAutoStartPref.value, "Sanity check");
+  is(startupPref.value, startupPref.defaultValue, "Sanity check");
+
+  // First, check to make sure that setting pbAutoStartPref disables the menu item
+  pbAutoStartPref.value = true;
+  is(option.getAttribute("disabled"), "true", "Setting private browsing to autostart " +
+     "should disable the 'Show my tabs and windows from last time' option");
+  pbAutoStartPref.value = false;
+
+  // Now ensure the correct behavior when pbAutoStartPref is set with option enabled
+  startupPref.value = option.getAttribute("value");
+  is(menu.selectedItem, option, "Sanity check");
+  pbAutoStartPref.value = true;
+  is(option.getAttribute("disabled"), "true", "Setting private browsing to autostart " +
+     "should disable the 'Show my tabs and windows from last time' option");
+  is(menu.selectedItem, defOption, "The 'Show home page' option should be selected");
+  is(startupPref.value, option.getAttribute("value"), "But the value of the startup " +
+     "pref itself shouldn't change");
+  menu.selectedItem = otherOption;
+  menu.doCommand();
+  is(startupPref.value, otherOption.getAttribute("value"), "And we should be able to " +
+     "chnage it!");
+  pbAutoStartPref.value = false;
+
+  // Now, ensure that with 'Show my windows and tabs from last time' enabled, toggling
+  // pbAutoStartPref would restore that value in the menulist.
+  startupPref.value = option.getAttribute("value");
+  is(menu.selectedItem, option, "Sanity check");
+  pbAutoStartPref.value = true;
+  is(menu.selectedItem, defOption, "The 'Show home page' option should be selected");
+  pbAutoStartPref.value = false;
+  is(menu.selectedItem, option, "The correct value should be restored");
+
+  // cleanup
+  resetPreferences();
+  gBrowser.removeCurrentTab();
+  win.close();
+  finish();
+}
+
+function resetPreferences() {
+  Services.prefs.clearUserPref("browser.startup.page");
+  Services.prefs.clearUserPref("browser.privatebrowsing.autostart");
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_bug731866.js
@@ -0,0 +1,113 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
+Components.utils.import("resource://gre/modules/NetUtil.jsm");
+
+function test() {
+  waitForExplicitFinish();
+  let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab = gBrowser.addTab("about:preferences"));
+  newTabBrowser.addEventListener("load", function () {
+    newTabBrowser.removeEventListener("load", arguments.callee, true);
+    runTest(gBrowser.contentWindow);
+  }, true);
+}
+
+function runTest(win) {
+  is(gBrowser.currentURI.spec, "about:preferences", "about:preferences loaded");
+
+  let tab = win.document;
+  let elements = tab.getElementById("mainPrefPane").children;
+
+  //Test if general pane is opened correctly
+  win.gotoPref("paneGeneral");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneGeneral") {
+      is_element_visible(element, "General elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-General elements should be hidden");
+    }
+  }
+
+  //Test if tabs pane is opened correctly
+  win.gotoPref("paneTabs");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneTabs") {
+      is_element_visible(element, "Tab elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Tab elements should be hidden");
+    }
+  }
+
+  //Test if content pane is opened correctly
+  win.gotoPref("paneContent");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneContent") {
+      is_element_visible(element, "Content elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Content elements should be hidden");
+    }
+  }
+
+  //Test if applications pane is opened correctly
+  win.gotoPref("paneApplications");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneApplications") {
+      is_element_visible(element, "Application elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Application elements should be hidden");
+    }
+  }
+
+  //Test if privacy pane is opened correctly
+  win.gotoPref("panePrivacy");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "panePrivacy") {
+      is_element_visible(element, "Privacy elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Privacy elements should be hidden");
+    }
+  }
+
+  //Test if security pane is opened correctly
+  win.gotoPref("paneSecurity");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneSecurity") {
+      is_element_visible(element, "Security elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Security elements should be hidden");
+    }
+  }
+
+  //Test if sync pane is opened correctly
+  win.gotoPref("paneSync");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneSync") {
+      is_element_visible(element, "Sync elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Sync elements should be hidden");
+    }
+  }
+
+  //Test if advanced pane is opened correctly
+  win.gotoPref("paneAdvanced");
+  for (let element of elements) {
+    let attributeValue = element.getAttribute("data-category");
+    if (attributeValue == "paneAdvanced") {
+      is_element_visible(element, "Advanced elements should be visible");
+    } else {
+      is_element_hidden(element, "Non-Advanced elements should be hidden");
+    }
+  }
+
+  gBrowser.removeCurrentTab();
+  win.close();
+  finish();
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_1.js
@@ -0,0 +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.js", this);
+
+  run_test_subset([
+    test_pane_visibility,
+    test_dependent_elements,
+    test_dependent_cookie_elements,
+    test_dependent_clearonclose_elements,
+    test_dependent_prefs,
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_2.js
@@ -0,0 +1,29 @@
+/* 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.js", this);
+
+  run_test_subset([
+    test_historymode_retention("remember", undefined),
+    test_historymode_retention("dontremember", "remember"),
+    test_historymode_retention("custom", "dontremember"),
+    // custom without any micro-prefs changed won't retain
+    test_historymode_retention("remember", "dontremember"),
+    test_historymode_retention("custom", "remember"),
+    // custom without any micro-prefs changed won't retain
+    test_historymode_retention("remember", "remember"),
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_3.js
@@ -0,0 +1,25 @@
+/* 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.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"),
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_4.js
@@ -0,0 +1,30 @@
+/* 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.js", this);
+
+  run_test_subset([
+    test_custom_retention("acceptCookies", "remember"),
+    test_custom_retention("acceptCookies", "custom"),
+    test_custom_retention("acceptThirdParty", "remember"),
+    test_custom_retention("acceptThirdParty", "custom"),
+    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"),
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_5.js
@@ -0,0 +1,25 @@
+/* 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.js", this);
+
+  run_test_subset([
+    test_locbar_suggestion_retention(-1, undefined),
+    test_locbar_suggestion_retention(1, -1),
+    test_locbar_suggestion_retention(2, 1),
+    test_locbar_suggestion_retention(0, 2),
+    test_locbar_suggestion_retention(0, 0),
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_6.js
@@ -0,0 +1,22 @@
+/* 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.js", this);
+
+  run_test_subset([
+    test_privatebrowsing_toggle,
+    enter_private_browsing, // once again, test with PB initially enabled
+    test_privatebrowsing_toggle,
+
+    // don't reset preferences, will pick up where we left off in browser_privacypane_7.js
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_7.js
@@ -0,0 +1,23 @@
+/* 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.js", this);
+
+  run_test_subset([
+    test_privatebrowsing_ui,
+    enter_private_browsing, // once again, test with PB initially enabled
+    test_privatebrowsing_ui,
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_8.js
@@ -0,0 +1,34 @@
+/* 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.js", this);
+
+  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 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 now be remember
+    test_historymode_retention("remember", "remember"),
+
+    // reset all preferences to their default values once we're done
+    reset_preferences
+  ]);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/head.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function is_hidden(aElement) {
+  var style = aElement.ownerDocument.defaultView.getComputedStyle(aElement, "");
+  if (style.display == "none")
+    return true;
+  if (style.visibility != "visible")
+    return true;
+
+  // Hiding a parent element will hide all its children
+  if (aElement.parentNode != aElement.ownerDocument)
+    return is_hidden(aElement.parentNode);
+
+  return false;
+}
+
+function is_element_visible(aElement, aMsg) {
+  isnot(aElement, null, "Element should not be null, when checking visibility");
+  ok(!is_hidden(aElement), aMsg);
+}
+
+function is_element_hidden(aElement, aMsg) {
+  isnot(aElement, null, "Element should not be null, when checking visibility");
+  ok(is_hidden(aElement), aMsg);
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/privacypane_tests.js
@@ -0,0 +1,491 @@
+/* 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");
+      testFunc(browser.contentWindow);
+      gBrowser.removeCurrentTab();
+      testRunner.runNext();
+    }, true);
+  }, true);
+  
+  gBrowser.selectedTab = gBrowser.addTab("about:preferences");
+}
+
+function controlChanged(element) {
+  element.doCommand();
+}
+
+function test_pane_visibility(win) {
+  let modes = {
+    "remember": "historyRememberPane",
+    "dontremember": "historyDontRememberPane",
+    "custom": "historyCustomPane"
+  };
+
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let historypane = win.document.getElementById("historyPane");
+  ok(historypane, "history mode pane should exist");
+
+  for (let mode in modes) {
+    historymode.value = mode;
+    controlChanged(historymode);
+    is(historypane.selectedPanel, win.document.getElementById(modes[mode]),
+      "The correct pane should be selected for the " + mode + " mode");
+  }
+}
+
+function test_dependent_elements(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
+  ok(pbautostart, "the private browsing auto-start checkbox should exist");
+  let controls = [
+    win.document.getElementById("rememberHistory"),
+    win.document.getElementById("rememberForms"),
+    win.document.getElementById("keepUntil"),
+    win.document.getElementById("keepCookiesUntil"),
+    win.document.getElementById("alwaysClear"),
+  ];
+  controls.forEach(function(control) {
+    ok(control, "the dependent controls should exist");
+  });
+  let independents = [
+    win.document.getElementById("acceptCookies"),
+    win.document.getElementById("acceptThirdParty"),
+  ];
+  independents.forEach(function(control) {
+    ok(control, "the independent controls should exist");
+  });
+  let cookieexceptions = win.document.getElementById("cookieExceptions");
+  ok(cookieexceptions, "the cookie exceptions button should exist");
+  let keepuntil = win.document.getElementById("keepCookiesUntil");
+  ok(keepuntil, "the keep cookies until menulist should exist");
+  let alwaysclear = win.document.getElementById("alwaysClear");
+  ok(alwaysclear, "the clear data on close checkbox should exist");
+  let rememberhistory = win.document.getElementById("rememberHistory");
+  ok(rememberhistory, "the remember history checkbox should exist");
+  let rememberforms = win.document.getElementById("rememberForms");
+  ok(rememberforms, "the remember forms checkbox should exist");
+  let alwaysclearsettings = win.document.getElementById("clearDataSettings");
+  ok(alwaysclearsettings, "the clear data settings button should exist");
+
+  function expect_disabled(disabled) {
+    controls.forEach(function(control) {
+      is(control.disabled, disabled,
+        control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled");
+    });
+    is(keepuntil.value, disabled ? 2 : 0,
+      "the keep cookies until menulist value should be as expected");
+    if (disabled) {
+     ok(!alwaysclear.checked,
+        "the clear data on close checkbox value should be as expected");
+     ok(!rememberhistory.checked,
+        "the remember history checkbox value should be as expected");
+     ok(!rememberforms.checked,
+        "the remember forms checkbox value should be as expected");
+    }
+  }
+  function check_independents(expected) {
+    independents.forEach(function(control) {
+      is(control.disabled, expected,
+        control.getAttribute("id") + " should " + (expected ? "" : "not ") + "be disabled");
+    });
+
+    ok(!cookieexceptions.disabled,
+      "the cookie exceptions button should never be disabled");
+    ok(alwaysclearsettings.disabled,
+      "the clear data settings button should always be disabled");
+  }
+
+  // controls should only change in custom mode
+  historymode.value = "remember";
+  controlChanged(historymode);
+  expect_disabled(false);
+  check_independents(false);
+
+  // setting the mode to custom shouldn't change anything
+  historymode.value = "custom";
+  controlChanged(historymode);
+  expect_disabled(false);
+  check_independents(false);
+
+  // controls should only change in custom mode
+  historymode.value = "dontremember";
+  controlChanged(historymode);
+  expect_disabled(false);
+  check_independents(false);
+
+  // controls should only change in custom mode
+  historymode.value = "custom";
+  controlChanged(historymode);
+  expect_disabled(true);
+  check_independents(false);
+
+  // dependent controls should follow pbautostart
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  expect_disabled(false);
+  check_independents(false);
+
+  // dependent controls should follow pbautostart
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+  check_independents(false);
+}
+
+function test_dependent_cookie_elements(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
+  ok(pbautostart, "the private browsing auto-start checkbox should exist");
+  let controls = [
+    win.document.getElementById("acceptThirdParty"),
+    win.document.getElementById("keepUntil"),
+    win.document.getElementById("keepCookiesUntil"),
+  ];
+  controls.forEach(function(control) {
+    ok(control, "the dependent cookie controls should exist");
+  });
+  let acceptcookies = win.document.getElementById("acceptCookies");
+  ok(acceptcookies, "the accept cookies checkbox should exist");
+
+  function expect_disabled(disabled) {
+    controls.forEach(function(control) {
+      is(control.disabled, disabled,
+        control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled");
+    });
+  }
+
+  historymode.value = "custom";
+  controlChanged(historymode);
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  expect_disabled(false);
+
+  acceptcookies.checked = false;
+  controlChanged(acceptcookies);
+  expect_disabled(true);
+
+  // pbautostart shouldn't change anything now
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+
+  acceptcookies.checked = true;
+  controlChanged(acceptcookies);
+  expect_disabled(false);
+
+  let accessthirdparty = controls.shift();
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+  ok(!accessthirdparty.disabled, "access third party button should be enabled");
+
+  acceptcookies.checked = false;
+  controlChanged(acceptcookies);
+  expect_disabled(true);
+  ok(accessthirdparty.disabled, "access third party button should be disabled");
+
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+  ok(accessthirdparty.disabled, "access third party button should be disabled");
+
+  acceptcookies.checked = true;
+  controlChanged(acceptcookies);
+  expect_disabled(false);
+  ok(!accessthirdparty.disabled, "access third party button should be enabled");
+}
+
+function test_dependent_clearonclose_elements(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
+  ok(pbautostart, "the private browsing auto-start checkbox should exist");
+  let alwaysclear = win.document.getElementById("alwaysClear");
+  ok(alwaysclear, "the clear data on close checkbox should exist");
+  let alwaysclearsettings = win.document.getElementById("clearDataSettings");
+  ok(alwaysclearsettings, "the clear data settings button should exist");
+
+  function expect_disabled(disabled) {
+    is(alwaysclearsettings.disabled, disabled,
+      "the clear data settings should " + (disabled ? "" : "not ") + "be disabled");
+  }
+
+  historymode.value = "custom";
+  controlChanged(historymode);
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  alwaysclear.checked = false;
+  controlChanged(alwaysclear);
+  expect_disabled(true);
+
+  alwaysclear.checked = true;
+  controlChanged(alwaysclear);
+  expect_disabled(false);
+
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  expect_disabled(true);
+
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  expect_disabled(false);
+
+  alwaysclear.checked = false;
+  controlChanged(alwaysclear);
+  expect_disabled(true);
+}
+
+function test_dependent_prefs(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let controls = [
+    win.document.getElementById("rememberHistory"),
+    win.document.getElementById("rememberForms"),
+    win.document.getElementById("acceptCookies"),
+    win.document.getElementById("acceptThirdParty"),
+  ];
+  controls.forEach(function(control) {
+    ok(control, "the micro-management controls should exist");
+  });
+
+  function expect_checked(checked) {
+    controls.forEach(function(control) {
+      is(control.checked, checked,
+        control.getAttribute("id") + " should " + (checked ? "not " : "") + "be checked");
+    });
+  }
+
+  // controls should be checked in remember mode
+  historymode.value = "remember";
+  controlChanged(historymode);
+  expect_checked(true);
+
+  // even if they're unchecked in custom mode
+  historymode.value = "custom";
+  controlChanged(historymode);
+  controls.forEach(function(control) {
+    control.checked = false;
+    controlChanged(control);
+  });
+  expect_checked(false);
+  historymode.value = "remember";
+  controlChanged(historymode);
+  expect_checked(true);
+}
+
+function test_historymode_retention(mode, expect) {
+  return function(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);
+    }
+
+    historymode.value = mode;
+    controlChanged(historymode);
+  };
+}
+
+function test_custom_retention(controlToChange, expect, valueIncrement) {
+  return function(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);
+    }
+
+    historymode.value = "custom";
+    controlChanged(historymode);
+
+    controlToChange = win.document.getElementById(controlToChange);
+    ok(controlToChange, "the control to change should exist");
+    switch (controlToChange.localName) {
+    case "checkbox":
+      controlToChange.checked = !controlToChange.checked;
+      break;
+    case "textbox":
+      controlToChange.value = parseInt(controlToChange.value) + valueIncrement;
+      break;
+    case "menulist":
+      controlToChange.value = valueIncrement;
+      break;
+    }
+    controlChanged(controlToChange);
+  };
+}
+
+function test_locbar_suggestion_retention(mode, expect) {
+  return function(win) {
+    let locbarsuggest = win.document.getElementById("locationBarSuggestion");
+    ok(locbarsuggest, "location bar suggestion menulist should exist");
+
+    if (expect !== undefined) {
+      is(locbarsuggest.value, expect,
+        "location bar suggestion is expected to remain " + expect);
+    }
+
+    locbarsuggest.value = mode;
+    controlChanged(locbarsuggest);
+  };
+}
+
+function test_privatebrowsing_toggle(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
+  ok(pbautostart, "the private browsing auto-start checkbox should exist");
+
+  let pbService = Cc["@mozilla.org/privatebrowsing;1"].
+                  getService(Ci.nsIPrivateBrowsingService);
+
+  // initial state
+  historymode.value = "remember";
+  controlChanged(historymode);
+
+  // switch to dontremember mode
+  historymode.value = "dontremember";
+  controlChanged(historymode);
+  ok(pbService.privateBrowsingEnabled, "private browsing should be activated");
+
+  // switch to remember mode
+  historymode.value = "remember";
+  controlChanged(historymode);
+  ok(!pbService.privateBrowsingEnabled, "private browsing should be deactivated");
+
+  // switch to custom mode
+  historymode.value = "custom";
+  controlChanged(historymode);
+  ok(!pbService.privateBrowsingEnabled, "private browsing should remain deactivated");
+
+  // check the autostart checkbox
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  ok(pbService.privateBrowsingEnabled, "private browsing should be activated");
+
+  // uncheck the autostart checkbox
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  ok(!pbService.privateBrowsingEnabled, "private browsing should be deactivated");
+}
+
+function test_privatebrowsing_ui(win) {
+  let historymode = win.document.getElementById("historyMode");
+  ok(historymode, "history mode menulist should exist");
+  let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
+  ok(pbautostart, "the private browsing auto-start checkbox should exist");
+
+  let pbmenuitem = document.getElementById("privateBrowsingItem");
+  ok(pbmenuitem, "the private browsing menu item should exist");
+  let pbcommand = document.getElementById("Tools:PrivateBrowsing");
+  ok(pbcommand, "the private browsing command should exist");
+
+  // initial state
+  historymode.value = "remember";
+  controlChanged(historymode);
+  ok(!pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should not be initially disabled");
+  ok(!pbcommand.hasAttribute("disabled"),
+    "private browsing command should not be initially disabled");
+
+  // switch to dontremember mode
+  historymode.value = "dontremember";
+  controlChanged(historymode);
+  ok(pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should be disabled");
+  ok(pbcommand.hasAttribute("disabled"),
+    "private browsing command should be disabled");
+
+  // switch to remember mode
+  historymode.value = "remember";
+  controlChanged(historymode);
+  ok(!pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should be enabled");
+  ok(!pbcommand.hasAttribute("disabled"),
+    "private browsing command should be enabled");
+
+  // switch to custom mode
+  historymode.value = "custom";
+  controlChanged(historymode);
+  ok(!pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should remain enabled");
+  ok(!pbcommand.hasAttribute("disabled"),
+    "private browsing command should remain enabled");
+
+  // check the autostart checkbox
+  pbautostart.checked = true;
+  controlChanged(pbautostart);
+  ok(pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should be disabled");
+  ok(pbcommand.hasAttribute("disabled"),
+    "private browsing command should be disabled");
+
+  // uncheck the autostart checkbox
+  pbautostart.checked = false;
+  controlChanged(pbautostart);
+  ok(!pbmenuitem.hasAttribute("disabled"),
+    "private browsing menu item should be enabled");
+  ok(!pbcommand.hasAttribute("disabled"),
+    "private browsing command should be enabled");
+}
+
+function enter_private_browsing(win) {
+  let pbService = Cc["@mozilla.org/privatebrowsing;1"].
+                  getService(Ci.nsIPrivateBrowsingService);
+  win.document.getElementById("browser.privatebrowsing.keep_current_session")
+              .value = true;
+  pbService.privateBrowsingEnabled = true;
+}
+
+function reset_preferences(win) {
+  let prefs = win.document.querySelectorAll("#privacyPreferences > preference");
+  for (let i = 0; i < prefs.length; ++i)
+    if (prefs[i].hasUserValue)
+      prefs[i].reset();
+}
+
+let testRunner;
+function run_test_subset(subset) {
+  Services.prefs.setBoolPref("browser.preferences.instantApply", true);
+
+  waitForExplicitFinish();
+  registerCleanupFunction(function() {
+    // Reset pref to its default
+    Services.prefs.clearUserPref("browser.preferences.instantApply");
+  });
+
+  testRunner = {
+    tests: subset,
+    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();
+}