browser/components/preferences/in-content/tests/privacypane_tests_perwindow.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 function runTestOnPrivacyPrefPane(testFunc) {
michael@0 5
michael@0 6 gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
michael@0 7 gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true);
michael@0 8 let browser = aEvent.originalTarget.linkedBrowser;
michael@0 9 browser.addEventListener("Initialized", function(aEvent) {
michael@0 10 browser.removeEventListener("Initialized", arguments.callee, true);
michael@0 11 is(browser.contentWindow.location.href, "about:preferences", "Checking if the preferences tab was opened");
michael@0 12 testFunc(browser.contentWindow);
michael@0 13 gBrowser.removeCurrentTab();
michael@0 14 testRunner.runNext();
michael@0 15 }, true);
michael@0 16 }, true);
michael@0 17
michael@0 18 gBrowser.selectedTab = gBrowser.addTab("about:preferences");
michael@0 19 }
michael@0 20
michael@0 21 function controlChanged(element) {
michael@0 22 element.doCommand();
michael@0 23 }
michael@0 24
michael@0 25 // We can only test the panes that don't trigger a preference update
michael@0 26 function test_pane_visibility(win) {
michael@0 27 let modes = {
michael@0 28 "remember": "historyRememberPane",
michael@0 29 "custom": "historyCustomPane"
michael@0 30 };
michael@0 31
michael@0 32 let historymode = win.document.getElementById("historyMode");
michael@0 33 ok(historymode, "history mode menulist should exist");
michael@0 34 let historypane = win.document.getElementById("historyPane");
michael@0 35 ok(historypane, "history mode pane should exist");
michael@0 36
michael@0 37 for (let mode in modes) {
michael@0 38 historymode.value = mode;
michael@0 39 controlChanged(historymode);
michael@0 40 is(historypane.selectedPanel, win.document.getElementById(modes[mode]),
michael@0 41 "The correct pane should be selected for the " + mode + " mode");
michael@0 42 }
michael@0 43 }
michael@0 44
michael@0 45 function test_dependent_elements(win) {
michael@0 46 let historymode = win.document.getElementById("historyMode");
michael@0 47 ok(historymode, "history mode menulist should exist");
michael@0 48 let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
michael@0 49 ok(pbautostart, "the private browsing auto-start checkbox should exist");
michael@0 50 let controls = [
michael@0 51 win.document.getElementById("rememberHistory"),
michael@0 52 win.document.getElementById("rememberForms"),
michael@0 53 win.document.getElementById("keepUntil"),
michael@0 54 win.document.getElementById("keepCookiesUntil"),
michael@0 55 win.document.getElementById("alwaysClear"),
michael@0 56 ];
michael@0 57 controls.forEach(function(control) {
michael@0 58 ok(control, "the dependent controls should exist");
michael@0 59 });
michael@0 60 let independents = [
michael@0 61 win.document.getElementById("acceptCookies"),
michael@0 62 win.document.getElementById("acceptThirdPartyLabel"),
michael@0 63 win.document.getElementById("acceptThirdPartyMenu")
michael@0 64 ];
michael@0 65 independents.forEach(function(control) {
michael@0 66 ok(control, "the independent controls should exist");
michael@0 67 });
michael@0 68 let cookieexceptions = win.document.getElementById("cookieExceptions");
michael@0 69 ok(cookieexceptions, "the cookie exceptions button should exist");
michael@0 70 let keepuntil = win.document.getElementById("keepCookiesUntil");
michael@0 71 ok(keepuntil, "the keep cookies until menulist should exist");
michael@0 72 let alwaysclear = win.document.getElementById("alwaysClear");
michael@0 73 ok(alwaysclear, "the clear data on close checkbox should exist");
michael@0 74 let rememberhistory = win.document.getElementById("rememberHistory");
michael@0 75 ok(rememberhistory, "the remember history checkbox should exist");
michael@0 76 let rememberforms = win.document.getElementById("rememberForms");
michael@0 77 ok(rememberforms, "the remember forms checkbox should exist");
michael@0 78 let alwaysclearsettings = win.document.getElementById("clearDataSettings");
michael@0 79 ok(alwaysclearsettings, "the clear data settings button should exist");
michael@0 80
michael@0 81 function expect_disabled(disabled) {
michael@0 82 controls.forEach(function(control) {
michael@0 83 is(control.disabled, disabled,
michael@0 84 control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled");
michael@0 85 });
michael@0 86 is(keepuntil.value, disabled ? 2 : 0,
michael@0 87 "the keep cookies until menulist value should be as expected");
michael@0 88 if (disabled) {
michael@0 89 ok(!alwaysclear.checked,
michael@0 90 "the clear data on close checkbox value should be as expected");
michael@0 91 ok(!rememberhistory.checked,
michael@0 92 "the remember history checkbox value should be as expected");
michael@0 93 ok(!rememberforms.checked,
michael@0 94 "the remember forms checkbox value should be as expected");
michael@0 95 }
michael@0 96 }
michael@0 97 function check_independents(expected) {
michael@0 98 independents.forEach(function(control) {
michael@0 99 is(control.disabled, expected,
michael@0 100 control.getAttribute("id") + " should " + (expected ? "" : "not ") + "be disabled");
michael@0 101 });
michael@0 102
michael@0 103 ok(!cookieexceptions.disabled,
michael@0 104 "the cookie exceptions button should never be disabled");
michael@0 105 ok(alwaysclearsettings.disabled,
michael@0 106 "the clear data settings button should always be disabled");
michael@0 107 }
michael@0 108
michael@0 109 // controls should only change in custom mode
michael@0 110 historymode.value = "remember";
michael@0 111 controlChanged(historymode);
michael@0 112 expect_disabled(false);
michael@0 113 check_independents(false);
michael@0 114
michael@0 115 // setting the mode to custom shouldn't change anything
michael@0 116 historymode.value = "custom";
michael@0 117 controlChanged(historymode);
michael@0 118 expect_disabled(false);
michael@0 119 check_independents(false);
michael@0 120 }
michael@0 121
michael@0 122 function test_dependent_cookie_elements(win) {
michael@0 123 let historymode = win.document.getElementById("historyMode");
michael@0 124 ok(historymode, "history mode menulist should exist");
michael@0 125 let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
michael@0 126 ok(pbautostart, "the private browsing auto-start checkbox should exist");
michael@0 127 let controls = [
michael@0 128 win.document.getElementById("acceptThirdPartyLabel"),
michael@0 129 win.document.getElementById("acceptThirdPartyMenu"),
michael@0 130 win.document.getElementById("keepUntil"),
michael@0 131 win.document.getElementById("keepCookiesUntil"),
michael@0 132 ];
michael@0 133 controls.forEach(function(control) {
michael@0 134 ok(control, "the dependent cookie controls should exist");
michael@0 135 });
michael@0 136 let acceptcookies = win.document.getElementById("acceptCookies");
michael@0 137 ok(acceptcookies, "the accept cookies checkbox should exist");
michael@0 138
michael@0 139 function expect_disabled(disabled) {
michael@0 140 controls.forEach(function(control) {
michael@0 141 is(control.disabled, disabled,
michael@0 142 control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled");
michael@0 143 });
michael@0 144 }
michael@0 145
michael@0 146 historymode.value = "custom";
michael@0 147 controlChanged(historymode);
michael@0 148 pbautostart.checked = false;
michael@0 149 controlChanged(pbautostart);
michael@0 150 expect_disabled(false);
michael@0 151
michael@0 152 acceptcookies.checked = false;
michael@0 153 controlChanged(acceptcookies);
michael@0 154 expect_disabled(true);
michael@0 155
michael@0 156 acceptcookies.checked = true;
michael@0 157 controlChanged(acceptcookies);
michael@0 158 expect_disabled(false);
michael@0 159
michael@0 160 let accessthirdparty = controls.shift();
michael@0 161 acceptcookies.checked = false;
michael@0 162 controlChanged(acceptcookies);
michael@0 163 expect_disabled(true);
michael@0 164 ok(accessthirdparty.disabled, "access third party button should be disabled");
michael@0 165
michael@0 166 pbautostart.checked = false;
michael@0 167 controlChanged(pbautostart);
michael@0 168 expect_disabled(true);
michael@0 169 ok(accessthirdparty.disabled, "access third party button should be disabled");
michael@0 170
michael@0 171 acceptcookies.checked = true;
michael@0 172 controlChanged(acceptcookies);
michael@0 173 expect_disabled(false);
michael@0 174 ok(!accessthirdparty.disabled, "access third party button should be enabled");
michael@0 175 }
michael@0 176
michael@0 177 function test_dependent_clearonclose_elements(win) {
michael@0 178 let historymode = win.document.getElementById("historyMode");
michael@0 179 ok(historymode, "history mode menulist should exist");
michael@0 180 let pbautostart = win.document.getElementById("privateBrowsingAutoStart");
michael@0 181 ok(pbautostart, "the private browsing auto-start checkbox should exist");
michael@0 182 let alwaysclear = win.document.getElementById("alwaysClear");
michael@0 183 ok(alwaysclear, "the clear data on close checkbox should exist");
michael@0 184 let alwaysclearsettings = win.document.getElementById("clearDataSettings");
michael@0 185 ok(alwaysclearsettings, "the clear data settings button should exist");
michael@0 186
michael@0 187 function expect_disabled(disabled) {
michael@0 188 is(alwaysclearsettings.disabled, disabled,
michael@0 189 "the clear data settings should " + (disabled ? "" : "not ") + "be disabled");
michael@0 190 }
michael@0 191
michael@0 192 historymode.value = "custom";
michael@0 193 controlChanged(historymode);
michael@0 194 pbautostart.checked = false;
michael@0 195 controlChanged(pbautostart);
michael@0 196 alwaysclear.checked = false;
michael@0 197 controlChanged(alwaysclear);
michael@0 198 expect_disabled(true);
michael@0 199
michael@0 200 alwaysclear.checked = true;
michael@0 201 controlChanged(alwaysclear);
michael@0 202 expect_disabled(false);
michael@0 203
michael@0 204 alwaysclear.checked = false;
michael@0 205 controlChanged(alwaysclear);
michael@0 206 expect_disabled(true);
michael@0 207 }
michael@0 208
michael@0 209 function test_dependent_prefs(win) {
michael@0 210 let historymode = win.document.getElementById("historyMode");
michael@0 211 ok(historymode, "history mode menulist should exist");
michael@0 212 let controls = [
michael@0 213 win.document.getElementById("rememberHistory"),
michael@0 214 win.document.getElementById("rememberForms"),
michael@0 215 win.document.getElementById("acceptCookies")
michael@0 216 ];
michael@0 217 controls.forEach(function(control) {
michael@0 218 ok(control, "the micro-management controls should exist");
michael@0 219 });
michael@0 220
michael@0 221 let thirdPartyCookieMenu = win.document.getElementById("acceptThirdPartyMenu");
michael@0 222 ok(thirdPartyCookieMenu, "the third-party cookie control should exist");
michael@0 223
michael@0 224 function expect_checked(checked) {
michael@0 225 controls.forEach(function(control) {
michael@0 226 is(control.checked, checked,
michael@0 227 control.getAttribute("id") + " should " + (checked ? "not " : "") + "be checked");
michael@0 228 });
michael@0 229
michael@0 230 is(thirdPartyCookieMenu.value == "always" || thirdPartyCookieMenu.value == "visited", checked, "third-party cookies should " + (checked ? "not " : "") + "be limited");
michael@0 231 }
michael@0 232
michael@0 233 // controls should be checked in remember mode
michael@0 234 historymode.value = "remember";
michael@0 235 controlChanged(historymode);
michael@0 236 expect_checked(true);
michael@0 237
michael@0 238 // even if they're unchecked in custom mode
michael@0 239 historymode.value = "custom";
michael@0 240 controlChanged(historymode);
michael@0 241 thirdPartyCookieMenu.value = "never";
michael@0 242 controlChanged(thirdPartyCookieMenu);
michael@0 243 controls.forEach(function(control) {
michael@0 244 control.checked = false;
michael@0 245 controlChanged(control);
michael@0 246 });
michael@0 247 expect_checked(false);
michael@0 248 historymode.value = "remember";
michael@0 249 controlChanged(historymode);
michael@0 250 expect_checked(true);
michael@0 251 }
michael@0 252
michael@0 253 function test_historymode_retention(mode, expect) {
michael@0 254 return function(win) {
michael@0 255 let historymode = win.document.getElementById("historyMode");
michael@0 256 ok(historymode, "history mode menulist should exist");
michael@0 257
michael@0 258 if ((historymode.value == "remember" && mode == "dontremember") ||
michael@0 259 (historymode.value == "dontremember" && mode == "remember") ||
michael@0 260 (historymode.value == "custom" && mode == "dontremember")) {
michael@0 261 return;
michael@0 262 }
michael@0 263
michael@0 264 if (expect !== undefined) {
michael@0 265 is(historymode.value, expect,
michael@0 266 "history mode is expected to remain " + expect);
michael@0 267 }
michael@0 268
michael@0 269 historymode.value = mode;
michael@0 270 controlChanged(historymode);
michael@0 271 };
michael@0 272 }
michael@0 273
michael@0 274 function test_custom_retention(controlToChange, expect, valueIncrement) {
michael@0 275 return function(win) {
michael@0 276 let historymode = win.document.getElementById("historyMode");
michael@0 277 ok(historymode, "history mode menulist should exist");
michael@0 278
michael@0 279 if (expect !== undefined) {
michael@0 280 is(historymode.value, expect,
michael@0 281 "history mode is expected to remain " + expect);
michael@0 282 }
michael@0 283
michael@0 284 historymode.value = "custom";
michael@0 285 controlChanged(historymode);
michael@0 286
michael@0 287 controlToChange = win.document.getElementById(controlToChange);
michael@0 288 ok(controlToChange, "the control to change should exist");
michael@0 289 switch (controlToChange.localName) {
michael@0 290 case "checkbox":
michael@0 291 controlToChange.checked = !controlToChange.checked;
michael@0 292 break;
michael@0 293 case "textbox":
michael@0 294 controlToChange.value = parseInt(controlToChange.value) + valueIncrement;
michael@0 295 break;
michael@0 296 case "menulist":
michael@0 297 controlToChange.value = valueIncrement;
michael@0 298 break;
michael@0 299 }
michael@0 300 controlChanged(controlToChange);
michael@0 301 };
michael@0 302 }
michael@0 303
michael@0 304 function test_locbar_suggestion_retention(mode, expect) {
michael@0 305 return function(win) {
michael@0 306 let locbarsuggest = win.document.getElementById("locationBarSuggestion");
michael@0 307 ok(locbarsuggest, "location bar suggestion menulist should exist");
michael@0 308
michael@0 309 if (expect !== undefined) {
michael@0 310 is(locbarsuggest.value, expect,
michael@0 311 "location bar suggestion is expected to remain " + expect);
michael@0 312 }
michael@0 313
michael@0 314 locbarsuggest.value = mode;
michael@0 315 controlChanged(locbarsuggest);
michael@0 316 };
michael@0 317 }
michael@0 318
michael@0 319 function reset_preferences(win) {
michael@0 320 let prefs = win.document.querySelectorAll("#privacyPreferences > preference");
michael@0 321 for (let i = 0; i < prefs.length; ++i)
michael@0 322 if (prefs[i].hasUserValue)
michael@0 323 prefs[i].reset();
michael@0 324 }
michael@0 325
michael@0 326 let testRunner;
michael@0 327 function run_test_subset(subset) {
michael@0 328 Services.prefs.setBoolPref("browser.preferences.instantApply", true);
michael@0 329 dump("subset: " + [x.name for (x of subset)].join(",") + "\n");
michael@0 330
michael@0 331 waitForExplicitFinish();
michael@0 332 registerCleanupFunction(function() {
michael@0 333 // Reset pref to its default
michael@0 334 Services.prefs.clearUserPref("browser.preferences.instantApply");
michael@0 335 });
michael@0 336
michael@0 337 testRunner = {
michael@0 338 tests: subset,
michael@0 339 counter: 0,
michael@0 340 runNext: function() {
michael@0 341 if (this.counter == this.tests.length) {
michael@0 342 finish();
michael@0 343 } else {
michael@0 344 let self = this;
michael@0 345 setTimeout(function() {
michael@0 346 runTestOnPrivacyPrefPane(self.tests[self.counter++]);
michael@0 347 }, 0);
michael@0 348 }
michael@0 349 }
michael@0 350 };
michael@0 351
michael@0 352 testRunner.runNext();
michael@0 353 }

mercurial