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