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