michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function runTestOnPrivacyPrefPane(testFunc) { michael@0: michael@0: gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) { michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true); michael@0: let browser = aEvent.originalTarget.linkedBrowser; michael@0: browser.addEventListener("Initialized", function(aEvent) { michael@0: browser.removeEventListener("Initialized", arguments.callee, true); michael@0: is(browser.contentWindow.location.href, "about:preferences", "Checking if the preferences tab was opened"); michael@0: testFunc(browser.contentWindow); michael@0: gBrowser.removeCurrentTab(); michael@0: testRunner.runNext(); michael@0: }, true); michael@0: }, true); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab("about:preferences"); michael@0: } michael@0: michael@0: function controlChanged(element) { michael@0: element.doCommand(); michael@0: } michael@0: michael@0: // We can only test the panes that don't trigger a preference update michael@0: function test_pane_visibility(win) { michael@0: let modes = { michael@0: "remember": "historyRememberPane", michael@0: "custom": "historyCustomPane" michael@0: }; michael@0: michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: let historypane = win.document.getElementById("historyPane"); michael@0: ok(historypane, "history mode pane should exist"); michael@0: michael@0: for (let mode in modes) { michael@0: historymode.value = mode; michael@0: controlChanged(historymode); michael@0: is(historypane.selectedPanel, win.document.getElementById(modes[mode]), michael@0: "The correct pane should be selected for the " + mode + " mode"); michael@0: } michael@0: } michael@0: michael@0: function test_dependent_elements(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); michael@0: ok(pbautostart, "the private browsing auto-start checkbox should exist"); michael@0: let controls = [ michael@0: win.document.getElementById("rememberHistory"), michael@0: win.document.getElementById("rememberForms"), michael@0: win.document.getElementById("keepUntil"), michael@0: win.document.getElementById("keepCookiesUntil"), michael@0: win.document.getElementById("alwaysClear"), michael@0: ]; michael@0: controls.forEach(function(control) { michael@0: ok(control, "the dependent controls should exist"); michael@0: }); michael@0: let independents = [ michael@0: win.document.getElementById("acceptCookies"), michael@0: win.document.getElementById("acceptThirdPartyLabel"), michael@0: win.document.getElementById("acceptThirdPartyMenu") michael@0: ]; michael@0: independents.forEach(function(control) { michael@0: ok(control, "the independent controls should exist"); michael@0: }); michael@0: let cookieexceptions = win.document.getElementById("cookieExceptions"); michael@0: ok(cookieexceptions, "the cookie exceptions button should exist"); michael@0: let keepuntil = win.document.getElementById("keepCookiesUntil"); michael@0: ok(keepuntil, "the keep cookies until menulist should exist"); michael@0: let alwaysclear = win.document.getElementById("alwaysClear"); michael@0: ok(alwaysclear, "the clear data on close checkbox should exist"); michael@0: let rememberhistory = win.document.getElementById("rememberHistory"); michael@0: ok(rememberhistory, "the remember history checkbox should exist"); michael@0: let rememberforms = win.document.getElementById("rememberForms"); michael@0: ok(rememberforms, "the remember forms checkbox should exist"); michael@0: let alwaysclearsettings = win.document.getElementById("clearDataSettings"); michael@0: ok(alwaysclearsettings, "the clear data settings button should exist"); michael@0: michael@0: function expect_disabled(disabled) { michael@0: controls.forEach(function(control) { michael@0: is(control.disabled, disabled, michael@0: control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled"); michael@0: }); michael@0: is(keepuntil.value, disabled ? 2 : 0, michael@0: "the keep cookies until menulist value should be as expected"); michael@0: if (disabled) { michael@0: ok(!alwaysclear.checked, michael@0: "the clear data on close checkbox value should be as expected"); michael@0: ok(!rememberhistory.checked, michael@0: "the remember history checkbox value should be as expected"); michael@0: ok(!rememberforms.checked, michael@0: "the remember forms checkbox value should be as expected"); michael@0: } michael@0: } michael@0: function check_independents(expected) { michael@0: independents.forEach(function(control) { michael@0: is(control.disabled, expected, michael@0: control.getAttribute("id") + " should " + (expected ? "" : "not ") + "be disabled"); michael@0: }); michael@0: michael@0: ok(!cookieexceptions.disabled, michael@0: "the cookie exceptions button should never be disabled"); michael@0: ok(alwaysclearsettings.disabled, michael@0: "the clear data settings button should always be disabled"); michael@0: } michael@0: michael@0: // controls should only change in custom mode michael@0: historymode.value = "remember"; michael@0: controlChanged(historymode); michael@0: expect_disabled(false); michael@0: check_independents(false); michael@0: michael@0: // setting the mode to custom shouldn't change anything michael@0: historymode.value = "custom"; michael@0: controlChanged(historymode); michael@0: expect_disabled(false); michael@0: check_independents(false); michael@0: } michael@0: michael@0: function test_dependent_cookie_elements(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); michael@0: ok(pbautostart, "the private browsing auto-start checkbox should exist"); michael@0: let controls = [ michael@0: win.document.getElementById("acceptThirdPartyLabel"), michael@0: win.document.getElementById("acceptThirdPartyMenu"), michael@0: win.document.getElementById("keepUntil"), michael@0: win.document.getElementById("keepCookiesUntil"), michael@0: ]; michael@0: controls.forEach(function(control) { michael@0: ok(control, "the dependent cookie controls should exist"); michael@0: }); michael@0: let acceptcookies = win.document.getElementById("acceptCookies"); michael@0: ok(acceptcookies, "the accept cookies checkbox should exist"); michael@0: michael@0: function expect_disabled(disabled) { michael@0: controls.forEach(function(control) { michael@0: is(control.disabled, disabled, michael@0: control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled"); michael@0: }); michael@0: } michael@0: michael@0: historymode.value = "custom"; michael@0: controlChanged(historymode); michael@0: pbautostart.checked = false; michael@0: controlChanged(pbautostart); michael@0: expect_disabled(false); michael@0: michael@0: acceptcookies.checked = false; michael@0: controlChanged(acceptcookies); michael@0: expect_disabled(true); michael@0: michael@0: acceptcookies.checked = true; michael@0: controlChanged(acceptcookies); michael@0: expect_disabled(false); michael@0: michael@0: let accessthirdparty = controls.shift(); michael@0: acceptcookies.checked = false; michael@0: controlChanged(acceptcookies); michael@0: expect_disabled(true); michael@0: ok(accessthirdparty.disabled, "access third party button should be disabled"); michael@0: michael@0: pbautostart.checked = false; michael@0: controlChanged(pbautostart); michael@0: expect_disabled(true); michael@0: ok(accessthirdparty.disabled, "access third party button should be disabled"); michael@0: michael@0: acceptcookies.checked = true; michael@0: controlChanged(acceptcookies); michael@0: expect_disabled(false); michael@0: ok(!accessthirdparty.disabled, "access third party button should be enabled"); michael@0: } michael@0: michael@0: function test_dependent_clearonclose_elements(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); michael@0: ok(pbautostart, "the private browsing auto-start checkbox should exist"); michael@0: let alwaysclear = win.document.getElementById("alwaysClear"); michael@0: ok(alwaysclear, "the clear data on close checkbox should exist"); michael@0: let alwaysclearsettings = win.document.getElementById("clearDataSettings"); michael@0: ok(alwaysclearsettings, "the clear data settings button should exist"); michael@0: michael@0: function expect_disabled(disabled) { michael@0: is(alwaysclearsettings.disabled, disabled, michael@0: "the clear data settings should " + (disabled ? "" : "not ") + "be disabled"); michael@0: } michael@0: michael@0: historymode.value = "custom"; michael@0: controlChanged(historymode); michael@0: pbautostart.checked = false; michael@0: controlChanged(pbautostart); michael@0: alwaysclear.checked = false; michael@0: controlChanged(alwaysclear); michael@0: expect_disabled(true); michael@0: michael@0: alwaysclear.checked = true; michael@0: controlChanged(alwaysclear); michael@0: expect_disabled(false); michael@0: michael@0: alwaysclear.checked = false; michael@0: controlChanged(alwaysclear); michael@0: expect_disabled(true); michael@0: } michael@0: michael@0: function test_dependent_prefs(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: let controls = [ michael@0: win.document.getElementById("rememberHistory"), michael@0: win.document.getElementById("rememberForms"), michael@0: win.document.getElementById("acceptCookies") michael@0: ]; michael@0: controls.forEach(function(control) { michael@0: ok(control, "the micro-management controls should exist"); michael@0: }); michael@0: michael@0: let thirdPartyCookieMenu = win.document.getElementById("acceptThirdPartyMenu"); michael@0: ok(thirdPartyCookieMenu, "the third-party cookie control should exist"); michael@0: michael@0: function expect_checked(checked) { michael@0: controls.forEach(function(control) { michael@0: is(control.checked, checked, michael@0: control.getAttribute("id") + " should " + (checked ? "not " : "") + "be checked"); michael@0: }); michael@0: michael@0: is(thirdPartyCookieMenu.value == "always" || thirdPartyCookieMenu.value == "visited", checked, "third-party cookies should " + (checked ? "not " : "") + "be limited"); michael@0: } michael@0: michael@0: // controls should be checked in remember mode michael@0: historymode.value = "remember"; michael@0: controlChanged(historymode); michael@0: expect_checked(true); michael@0: michael@0: // even if they're unchecked in custom mode michael@0: historymode.value = "custom"; michael@0: controlChanged(historymode); michael@0: thirdPartyCookieMenu.value = "never"; michael@0: controlChanged(thirdPartyCookieMenu); michael@0: controls.forEach(function(control) { michael@0: control.checked = false; michael@0: controlChanged(control); michael@0: }); michael@0: expect_checked(false); michael@0: historymode.value = "remember"; michael@0: controlChanged(historymode); michael@0: expect_checked(true); michael@0: } michael@0: michael@0: function test_historymode_retention(mode, expect) { michael@0: return function(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: michael@0: if ((historymode.value == "remember" && mode == "dontremember") || michael@0: (historymode.value == "dontremember" && mode == "remember") || michael@0: (historymode.value == "custom" && mode == "dontremember")) { michael@0: return; michael@0: } michael@0: michael@0: if (expect !== undefined) { michael@0: is(historymode.value, expect, michael@0: "history mode is expected to remain " + expect); michael@0: } michael@0: michael@0: historymode.value = mode; michael@0: controlChanged(historymode); michael@0: }; michael@0: } michael@0: michael@0: function test_custom_retention(controlToChange, expect, valueIncrement) { michael@0: return function(win) { michael@0: let historymode = win.document.getElementById("historyMode"); michael@0: ok(historymode, "history mode menulist should exist"); michael@0: michael@0: if (expect !== undefined) { michael@0: is(historymode.value, expect, michael@0: "history mode is expected to remain " + expect); michael@0: } michael@0: michael@0: historymode.value = "custom"; michael@0: controlChanged(historymode); michael@0: michael@0: controlToChange = win.document.getElementById(controlToChange); michael@0: ok(controlToChange, "the control to change should exist"); michael@0: switch (controlToChange.localName) { michael@0: case "checkbox": michael@0: controlToChange.checked = !controlToChange.checked; michael@0: break; michael@0: case "textbox": michael@0: controlToChange.value = parseInt(controlToChange.value) + valueIncrement; michael@0: break; michael@0: case "menulist": michael@0: controlToChange.value = valueIncrement; michael@0: break; michael@0: } michael@0: controlChanged(controlToChange); michael@0: }; michael@0: } michael@0: michael@0: function test_locbar_suggestion_retention(mode, expect) { michael@0: return function(win) { michael@0: let locbarsuggest = win.document.getElementById("locationBarSuggestion"); michael@0: ok(locbarsuggest, "location bar suggestion menulist should exist"); michael@0: michael@0: if (expect !== undefined) { michael@0: is(locbarsuggest.value, expect, michael@0: "location bar suggestion is expected to remain " + expect); michael@0: } michael@0: michael@0: locbarsuggest.value = mode; michael@0: controlChanged(locbarsuggest); michael@0: }; michael@0: } michael@0: michael@0: function reset_preferences(win) { michael@0: let prefs = win.document.querySelectorAll("#privacyPreferences > preference"); michael@0: for (let i = 0; i < prefs.length; ++i) michael@0: if (prefs[i].hasUserValue) michael@0: prefs[i].reset(); michael@0: } michael@0: michael@0: let testRunner; michael@0: function run_test_subset(subset) { michael@0: Services.prefs.setBoolPref("browser.preferences.instantApply", true); michael@0: dump("subset: " + [x.name for (x of subset)].join(",") + "\n"); michael@0: michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: // Reset pref to its default michael@0: Services.prefs.clearUserPref("browser.preferences.instantApply"); michael@0: }); michael@0: michael@0: testRunner = { michael@0: tests: subset, michael@0: counter: 0, michael@0: runNext: function() { michael@0: if (this.counter == this.tests.length) { michael@0: finish(); michael@0: } else { michael@0: let self = this; michael@0: setTimeout(function() { michael@0: runTestOnPrivacyPrefPane(self.tests[self.counter++]); michael@0: }, 0); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: testRunner.runNext(); michael@0: }