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