|
|
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
|
+"use strict";
|
|
|
6
|
+
|
|
|
7
|
+const {
|
|
|
8
|
+ SelectiveSavingPrefController,
|
|
|
9
|
+ SelectiveSavingModes,
|
|
|
10
|
+ kSelectiveSavingModePref,
|
|
|
11
|
+} = ChromeUtils.importESModule(
|
|
|
12
|
+ "moz-src:///toolkit/components/selectivesavingmode/SelectiveSavingMode.sys.mjs"
|
|
|
13
|
+);
|
|
|
14
|
+
|
|
|
15
|
+// secondary prefs
|
|
|
16
|
+const kSanitizeOnShutdown = "privacy.sanitize.sanitizeOnShutdown";
|
|
|
17
|
+const kPrivateBrowsingAutostart = "browser.privatebrowsing.autostart";
|
|
|
18
|
+const kKeepPermissionInMemory = "permissions.memory_only";
|
|
|
19
|
+
|
|
|
20
|
+const controller = new SelectiveSavingPrefController();
|
|
|
21
|
+
|
|
|
22
|
+function resetToTotalSavingPrefs() {
|
|
|
23
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
24
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
25
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
26
|
+}
|
|
|
27
|
+
|
|
|
28
|
+registerCleanupFunction(async () => {
|
|
|
29
|
+ controller.shutdown();
|
|
|
30
|
+});
|
|
|
31
|
+
|
|
|
32
|
+add_task(async function test_init_from_secondary_prefs() {
|
|
|
33
|
+ Services.prefs.setIntPref(
|
|
|
34
|
+ kSelectiveSavingModePref,
|
|
|
35
|
+ SelectiveSavingModes.unconfigured
|
|
|
36
|
+ );
|
|
|
37
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
38
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
39
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
40
|
+
|
|
|
41
|
+ controller.init();
|
|
|
42
|
+
|
|
|
43
|
+ Assert.equal(
|
|
|
44
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
45
|
+ SelectiveSavingModes.total_clearing,
|
|
|
46
|
+ "After pref controller init from unconfigured state, primary pref should be set to total clearing due to the way secondary prefs were set earlier"
|
|
|
47
|
+ );
|
|
|
48
|
+
|
|
|
49
|
+ controller.shutdown();
|
|
|
50
|
+
|
|
|
51
|
+ Services.prefs.setIntPref(
|
|
|
52
|
+ kSelectiveSavingModePref,
|
|
|
53
|
+ SelectiveSavingModes.unconfigured
|
|
|
54
|
+ );
|
|
|
55
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
56
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
57
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
58
|
+
|
|
|
59
|
+ controller.init();
|
|
|
60
|
+
|
|
|
61
|
+ Assert.equal(
|
|
|
62
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
63
|
+ SelectiveSavingModes.selective_saving,
|
|
|
64
|
+ "After pref controller init from unconfigured state, primary pref should be set to selective saving due to the way secondary prefs were set earlier"
|
|
|
65
|
+ );
|
|
|
66
|
+
|
|
|
67
|
+ controller.shutdown();
|
|
|
68
|
+
|
|
|
69
|
+ Services.prefs.setIntPref(
|
|
|
70
|
+ kSelectiveSavingModePref,
|
|
|
71
|
+ SelectiveSavingModes.unconfigured
|
|
|
72
|
+ );
|
|
|
73
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
74
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
75
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
76
|
+
|
|
|
77
|
+ controller.init();
|
|
|
78
|
+
|
|
|
79
|
+ Assert.equal(
|
|
|
80
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
81
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
82
|
+ "After pref controller init from unconfigured state, primary pref should be set to normal browsing due to the way secondary prefs were set earlier"
|
|
|
83
|
+ );
|
|
|
84
|
+
|
|
|
85
|
+ controller.shutdown();
|
|
|
86
|
+
|
|
|
87
|
+ Services.prefs.setIntPref(
|
|
|
88
|
+ kSelectiveSavingModePref,
|
|
|
89
|
+ SelectiveSavingModes.unconfigured
|
|
|
90
|
+ );
|
|
|
91
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
92
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
93
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
94
|
+
|
|
|
95
|
+ controller.init();
|
|
|
96
|
+
|
|
|
97
|
+ Assert.equal(
|
|
|
98
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
99
|
+ SelectiveSavingModes.custom,
|
|
|
100
|
+ "After pref controller init from unconfigured state, primary pref should be set to custom browsing due to the way secondary prefs were set earlier"
|
|
|
101
|
+ );
|
|
|
102
|
+
|
|
|
103
|
+ controller.shutdown();
|
|
|
104
|
+});
|
|
|
105
|
+
|
|
|
106
|
+add_task(async function test_init_from_secondary_prefs() {
|
|
|
107
|
+ Services.prefs.setIntPref(
|
|
|
108
|
+ kSelectiveSavingModePref,
|
|
|
109
|
+ SelectiveSavingModes.total_clearing
|
|
|
110
|
+ );
|
|
|
111
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
112
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
113
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
114
|
+
|
|
|
115
|
+ controller.init();
|
|
|
116
|
+
|
|
|
117
|
+ Assert.equal(
|
|
|
118
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
119
|
+ SelectiveSavingModes.total_clearing,
|
|
|
120
|
+ "After pref controller init from total clearing mode configured state (primary and secondary), primary pref shouldn't be changed from total clearing"
|
|
|
121
|
+ );
|
|
|
122
|
+
|
|
|
123
|
+ Assert.equal(
|
|
|
124
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
125
|
+ true,
|
|
|
126
|
+ "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
|
|
|
127
|
+ );
|
|
|
128
|
+
|
|
|
129
|
+ Assert.equal(
|
|
|
130
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
131
|
+ true,
|
|
|
132
|
+ "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to true"
|
|
|
133
|
+ );
|
|
|
134
|
+
|
|
|
135
|
+ Assert.equal(
|
|
|
136
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
137
|
+ true,
|
|
|
138
|
+ "After pref controller init from total clearing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to true"
|
|
|
139
|
+ );
|
|
|
140
|
+
|
|
|
141
|
+ controller.shutdown();
|
|
|
142
|
+
|
|
|
143
|
+ Services.prefs.setIntPref(
|
|
|
144
|
+ kSelectiveSavingModePref,
|
|
|
145
|
+ SelectiveSavingModes.selective_saving
|
|
|
146
|
+ );
|
|
|
147
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
148
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
149
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
150
|
+
|
|
|
151
|
+ controller.init();
|
|
|
152
|
+
|
|
|
153
|
+ Assert.equal(
|
|
|
154
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
155
|
+ SelectiveSavingModes.selective_saving,
|
|
|
156
|
+ "After pref controller init from selective saving configured state (primary and secondary), primary pref shouldn't be changed from selective saving"
|
|
|
157
|
+ );
|
|
|
158
|
+
|
|
|
159
|
+ Assert.equal(
|
|
|
160
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
161
|
+ true,
|
|
|
162
|
+ "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
|
|
|
163
|
+ );
|
|
|
164
|
+
|
|
|
165
|
+ Assert.equal(
|
|
|
166
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
167
|
+ false,
|
|
|
168
|
+ "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for pbm autostart should be set to false"
|
|
|
169
|
+ );
|
|
|
170
|
+
|
|
|
171
|
+ Assert.equal(
|
|
|
172
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
173
|
+ false,
|
|
|
174
|
+ "After pref controller init from selective saving mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
|
|
|
175
|
+ );
|
|
|
176
|
+
|
|
|
177
|
+ controller.shutdown();
|
|
|
178
|
+
|
|
|
179
|
+ Services.prefs.setIntPref(
|
|
|
180
|
+ kSelectiveSavingModePref,
|
|
|
181
|
+ SelectiveSavingModes.normal_browsing
|
|
|
182
|
+ );
|
|
|
183
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
184
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
185
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
186
|
+
|
|
|
187
|
+ controller.init();
|
|
|
188
|
+
|
|
|
189
|
+ Assert.equal(
|
|
|
190
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
191
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
192
|
+ "After pref controller init from normal browsing mode configured state (primary and secondary), primary pref shouldn't be changed from normal browsing"
|
|
|
193
|
+ );
|
|
|
194
|
+
|
|
|
195
|
+ Assert.equal(
|
|
|
196
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
197
|
+ false,
|
|
|
198
|
+ "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to false"
|
|
|
199
|
+ );
|
|
|
200
|
+
|
|
|
201
|
+ Assert.equal(
|
|
|
202
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
203
|
+ false,
|
|
|
204
|
+ "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to false"
|
|
|
205
|
+ );
|
|
|
206
|
+
|
|
|
207
|
+ Assert.equal(
|
|
|
208
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
209
|
+ false,
|
|
|
210
|
+ "After pref controller init from normal browsing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
|
|
|
211
|
+ );
|
|
|
212
|
+
|
|
|
213
|
+ controller.shutdown();
|
|
|
214
|
+
|
|
|
215
|
+ Services.prefs.setIntPref(
|
|
|
216
|
+ kSelectiveSavingModePref,
|
|
|
217
|
+ SelectiveSavingModes.custom
|
|
|
218
|
+ );
|
|
|
219
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
220
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
221
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
222
|
+
|
|
|
223
|
+ controller.init();
|
|
|
224
|
+
|
|
|
225
|
+ Assert.equal(
|
|
|
226
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
227
|
+ SelectiveSavingModes.custom,
|
|
|
228
|
+ "After pref controller init from custom mode configured state (primary and secondary), primary pref shouldn't be changed from custom"
|
|
|
229
|
+ );
|
|
|
230
|
+
|
|
|
231
|
+ Assert.equal(
|
|
|
232
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
233
|
+ true,
|
|
|
234
|
+ "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for sanitize on shutdown should be set to true"
|
|
|
235
|
+ );
|
|
|
236
|
+
|
|
|
237
|
+ Assert.equal(
|
|
|
238
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
239
|
+ true,
|
|
|
240
|
+ "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for pbm autostart should be set to true"
|
|
|
241
|
+ );
|
|
|
242
|
+
|
|
|
243
|
+ Assert.equal(
|
|
|
244
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
245
|
+ false,
|
|
|
246
|
+ "After pref contoller init from total clearing mode configured state (primary and secondary), secondary pref for memory only permissions should be set to false"
|
|
|
247
|
+ );
|
|
|
248
|
+
|
|
|
249
|
+ controller.shutdown();
|
|
|
250
|
+
|
|
|
251
|
+ Services.prefs.setIntPref(
|
|
|
252
|
+ kSelectiveSavingModePref,
|
|
|
253
|
+ SelectiveSavingModes.total_clearing
|
|
|
254
|
+ );
|
|
|
255
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
256
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
257
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
258
|
+
|
|
|
259
|
+ controller.init();
|
|
|
260
|
+
|
|
|
261
|
+ Assert.equal(
|
|
|
262
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
263
|
+ SelectiveSavingModes.total_clearing,
|
|
|
264
|
+ "After pref controller init from configured state, primary pref shouldn't be changed from total clearing"
|
|
|
265
|
+ );
|
|
|
266
|
+
|
|
|
267
|
+ Assert.equal(
|
|
|
268
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
269
|
+ true,
|
|
|
270
|
+ "After pref contoller init from total clearing mode configured state, secondary pref for sanitize on shutdown should be set to true"
|
|
|
271
|
+ );
|
|
|
272
|
+
|
|
|
273
|
+ Assert.equal(
|
|
|
274
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
275
|
+ true,
|
|
|
276
|
+ "After pref contoller init from total clearing mode configured state, secondary pref for pbm autostart should be set to true"
|
|
|
277
|
+ );
|
|
|
278
|
+
|
|
|
279
|
+ Assert.equal(
|
|
|
280
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
281
|
+ true,
|
|
|
282
|
+ "After pref contoller init from total clearing mode configured state, secondary pref for memory only permissions should be set to true"
|
|
|
283
|
+ );
|
|
|
284
|
+
|
|
|
285
|
+ controller.shutdown();
|
|
|
286
|
+
|
|
|
287
|
+ Services.prefs.setIntPref(
|
|
|
288
|
+ kSelectiveSavingModePref,
|
|
|
289
|
+ SelectiveSavingModes.selective_saving
|
|
|
290
|
+ );
|
|
|
291
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
292
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
293
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
294
|
+
|
|
|
295
|
+ controller.init();
|
|
|
296
|
+
|
|
|
297
|
+ Assert.equal(
|
|
|
298
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
299
|
+ SelectiveSavingModes.selective_saving,
|
|
|
300
|
+ "After pref controller init from configured state, primary pref shouldn't be changed from normal browsing"
|
|
|
301
|
+ );
|
|
|
302
|
+
|
|
|
303
|
+ Assert.equal(
|
|
|
304
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
305
|
+ true,
|
|
|
306
|
+ "After pref contoller init from selective saving mode configured state, secondary pref for sanitize on shutdown should be set to true"
|
|
|
307
|
+ );
|
|
|
308
|
+
|
|
|
309
|
+ Assert.equal(
|
|
|
310
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
311
|
+ false,
|
|
|
312
|
+ "After pref contoller init from selective saving mode configured state, secondary pref for pbm autostart should be set to false"
|
|
|
313
|
+ );
|
|
|
314
|
+
|
|
|
315
|
+ Assert.equal(
|
|
|
316
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
317
|
+ false,
|
|
|
318
|
+ "After pref contoller init from selective saving mode configured state, secondary pref for memory only permissions should be set to false"
|
|
|
319
|
+ );
|
|
|
320
|
+
|
|
|
321
|
+ controller.shutdown();
|
|
|
322
|
+
|
|
|
323
|
+ Services.prefs.setIntPref(
|
|
|
324
|
+ kSelectiveSavingModePref,
|
|
|
325
|
+ SelectiveSavingModes.normal_browsing
|
|
|
326
|
+ );
|
|
|
327
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
328
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
329
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
330
|
+
|
|
|
331
|
+ controller.init();
|
|
|
332
|
+
|
|
|
333
|
+ Assert.equal(
|
|
|
334
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
335
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
336
|
+ "After pref controller init from configured state, primary pref shouldn't be changed from normal browsing"
|
|
|
337
|
+ );
|
|
|
338
|
+
|
|
|
339
|
+ Assert.equal(
|
|
|
340
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
341
|
+ false,
|
|
|
342
|
+ "After pref contoller init from normal browsing mode configured state, secondary pref for sanitize on shutdown should be set to false"
|
|
|
343
|
+ );
|
|
|
344
|
+
|
|
|
345
|
+ Assert.equal(
|
|
|
346
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
347
|
+ false,
|
|
|
348
|
+ "After pref contoller init from normal browsing mode configured state, secondary pref for pbm autostart should be set to false"
|
|
|
349
|
+ );
|
|
|
350
|
+
|
|
|
351
|
+ Assert.equal(
|
|
|
352
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
353
|
+ false,
|
|
|
354
|
+ "After pref contoller init from normal browsing mode configured state, secondary pref for memory only permissions should be set to false"
|
|
|
355
|
+ );
|
|
|
356
|
+
|
|
|
357
|
+ controller.shutdown();
|
|
|
358
|
+
|
|
|
359
|
+ Services.prefs.setIntPref(
|
|
|
360
|
+ kSelectiveSavingModePref,
|
|
|
361
|
+ SelectiveSavingModes.custom
|
|
|
362
|
+ );
|
|
|
363
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
364
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
365
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
366
|
+
|
|
|
367
|
+ controller.init();
|
|
|
368
|
+
|
|
|
369
|
+ Assert.equal(
|
|
|
370
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
371
|
+ SelectiveSavingModes.custom,
|
|
|
372
|
+ "After pref controller init from configured state, primary pref shouldn't be changed from custom"
|
|
|
373
|
+ );
|
|
|
374
|
+
|
|
|
375
|
+ Assert.equal(
|
|
|
376
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
377
|
+ false,
|
|
|
378
|
+ "After pref contoller init from custom mode configured state, secondary pref for sanitize on shutdown should remain unchanged"
|
|
|
379
|
+ );
|
|
|
380
|
+
|
|
|
381
|
+ Assert.equal(
|
|
|
382
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
383
|
+ false,
|
|
|
384
|
+ "After pref contoller init from custom mode configured state, secondary pref for pbm autostart should remain unchanged"
|
|
|
385
|
+ );
|
|
|
386
|
+
|
|
|
387
|
+ Assert.equal(
|
|
|
388
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
389
|
+ false,
|
|
|
390
|
+ "After pref contoller init from custom mode configured state, secondary pref for memory only permissions should remain unchanged"
|
|
|
391
|
+ );
|
|
|
392
|
+});
|
|
|
393
|
+
|
|
|
394
|
+add_task(async function test_secondary_prefs_update_mode() {
|
|
|
395
|
+ controller.init();
|
|
|
396
|
+
|
|
|
397
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
398
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
399
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
400
|
+
|
|
|
401
|
+ Assert.equal(
|
|
|
402
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
403
|
+ SelectiveSavingModes.total_clearing,
|
|
|
404
|
+ "After pref update mode should be set to total clearing"
|
|
|
405
|
+ );
|
|
|
406
|
+
|
|
|
407
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
408
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
409
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
410
|
+
|
|
|
411
|
+ Assert.equal(
|
|
|
412
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
413
|
+ SelectiveSavingModes.selective_saving,
|
|
|
414
|
+ "After pref update mode should be set to selective saving"
|
|
|
415
|
+ );
|
|
|
416
|
+
|
|
|
417
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
418
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
419
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
420
|
+
|
|
|
421
|
+ Assert.equal(
|
|
|
422
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
423
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
424
|
+ "After pref update mode should be set to normal browsing"
|
|
|
425
|
+ );
|
|
|
426
|
+
|
|
|
427
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
428
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
429
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
430
|
+
|
|
|
431
|
+ Assert.equal(
|
|
|
432
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
433
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
434
|
+ "Duplicate for idempotency. after pref update mode should be set to normal browsing"
|
|
|
435
|
+ );
|
|
|
436
|
+
|
|
|
437
|
+ Assert.equal(
|
|
|
438
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
439
|
+ false,
|
|
|
440
|
+ "Duplicate for idempotency. Changing browsing mode to normal browsing should set sanitize on shutdown to false"
|
|
|
441
|
+ );
|
|
|
442
|
+
|
|
|
443
|
+ Assert.equal(
|
|
|
444
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
445
|
+ false,
|
|
|
446
|
+ "Duplicate for idempotency. Changing browsing mode to normal browsing should set pbm autostart to false"
|
|
|
447
|
+ );
|
|
|
448
|
+
|
|
|
449
|
+ Assert.equal(
|
|
|
450
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
451
|
+ false,
|
|
|
452
|
+ "Duplicate for idempotency. Changing browsing mode to normal browsing should set memory only permissions to false"
|
|
|
453
|
+ );
|
|
|
454
|
+
|
|
|
455
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
456
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
457
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
458
|
+
|
|
|
459
|
+ Assert.equal(
|
|
|
460
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
461
|
+ SelectiveSavingModes.custom,
|
|
|
462
|
+ "After pref update mode should be set to custom"
|
|
|
463
|
+ );
|
|
|
464
|
+
|
|
|
465
|
+ resetToTotalSavingPrefs();
|
|
|
466
|
+
|
|
|
467
|
+ Services.prefs.setIntPref(
|
|
|
468
|
+ kSelectiveSavingModePref,
|
|
|
469
|
+ SelectiveSavingModes.custom
|
|
|
470
|
+ );
|
|
|
471
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
472
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
473
|
+
|
|
|
474
|
+ Assert.equal(
|
|
|
475
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
476
|
+ SelectiveSavingModes.selective_saving,
|
|
|
477
|
+ "Manually changing to custom browsing via primary pref then changing secondary prefs to match another browsing mode should leave custom browsing"
|
|
|
478
|
+ );
|
|
|
479
|
+
|
|
|
480
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
481
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
482
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
483
|
+
|
|
|
484
|
+ Assert.equal(
|
|
|
485
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
486
|
+ SelectiveSavingModes.custom,
|
|
|
487
|
+ "Secondary Prefs set to (true, true, false) should result in Custom Browsing Mode"
|
|
|
488
|
+ );
|
|
|
489
|
+
|
|
|
490
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, true);
|
|
|
491
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
492
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
493
|
+
|
|
|
494
|
+ Assert.equal(
|
|
|
495
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
496
|
+ SelectiveSavingModes.custom,
|
|
|
497
|
+ "Secondary Prefs set to (true, false, true) should result in Custom Browsing Mode"
|
|
|
498
|
+ );
|
|
|
499
|
+
|
|
|
500
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
501
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
502
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
503
|
+
|
|
|
504
|
+ Assert.equal(
|
|
|
505
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
506
|
+ SelectiveSavingModes.custom,
|
|
|
507
|
+ "Secondary Prefs set to (false, false, true) should result in Custom Browsing Mode"
|
|
|
508
|
+ );
|
|
|
509
|
+
|
|
|
510
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
511
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
512
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
513
|
+
|
|
|
514
|
+ Assert.equal(
|
|
|
515
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
516
|
+ SelectiveSavingModes.custom,
|
|
|
517
|
+ "Secondary Prefs set to (false, true, false) should result in Custom Browsing Mode"
|
|
|
518
|
+ );
|
|
|
519
|
+
|
|
|
520
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
521
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, true);
|
|
|
522
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, true);
|
|
|
523
|
+
|
|
|
524
|
+ Assert.equal(
|
|
|
525
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
526
|
+ SelectiveSavingModes.custom,
|
|
|
527
|
+ "Secondary Prefs set to (false, true, true) should result in Custom Browsing Mode"
|
|
|
528
|
+ );
|
|
|
529
|
+});
|
|
|
530
|
+
|
|
|
531
|
+add_task(async function test_mode_updates_from_secondary_prefs() {
|
|
|
532
|
+ controller.init();
|
|
|
533
|
+
|
|
|
534
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, false);
|
|
|
535
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, false);
|
|
|
536
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, false);
|
|
|
537
|
+
|
|
|
538
|
+ Services.prefs.setIntPref(
|
|
|
539
|
+ kSelectiveSavingModePref,
|
|
|
540
|
+ SelectiveSavingModes.total_clearing
|
|
|
541
|
+ );
|
|
|
542
|
+
|
|
|
543
|
+ Assert.equal(
|
|
|
544
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
545
|
+ SelectiveSavingModes.total_clearing,
|
|
|
546
|
+ "Changing browsing mode to total clearing should set browsing mode to match"
|
|
|
547
|
+ );
|
|
|
548
|
+
|
|
|
549
|
+ Assert.equal(
|
|
|
550
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
551
|
+ true,
|
|
|
552
|
+ "Changing browsing mode to total clearing should set sanitize on shutdown to true"
|
|
|
553
|
+ );
|
|
|
554
|
+
|
|
|
555
|
+ Assert.equal(
|
|
|
556
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
557
|
+ true,
|
|
|
558
|
+ "Changing browsing mode to total clearing should set pbm autostart to true"
|
|
|
559
|
+ );
|
|
|
560
|
+
|
|
|
561
|
+ Assert.equal(
|
|
|
562
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
563
|
+ true,
|
|
|
564
|
+ "Changing browsing mode to total clearing should set memory only permissions to true"
|
|
|
565
|
+ );
|
|
|
566
|
+
|
|
|
567
|
+ Services.prefs.setIntPref(
|
|
|
568
|
+ kSelectiveSavingModePref,
|
|
|
569
|
+ SelectiveSavingModes.total_clearing
|
|
|
570
|
+ );
|
|
|
571
|
+
|
|
|
572
|
+ Assert.equal(
|
|
|
573
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
574
|
+ SelectiveSavingModes.total_clearing,
|
|
|
575
|
+ "Duplicate for idempotency. Changing browsing mode to total clearing should set browsing mode to match"
|
|
|
576
|
+ );
|
|
|
577
|
+
|
|
|
578
|
+ Assert.equal(
|
|
|
579
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
580
|
+ true,
|
|
|
581
|
+ "Duplicate for idempotency. Changing browsing mode to total clearing should set sanitize on shutdown to true"
|
|
|
582
|
+ );
|
|
|
583
|
+
|
|
|
584
|
+ Assert.equal(
|
|
|
585
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
586
|
+ true,
|
|
|
587
|
+ "Duplicate for idempotency. Changing browsing mode to total clearing should set pbm autostart to true"
|
|
|
588
|
+ );
|
|
|
589
|
+
|
|
|
590
|
+ Assert.equal(
|
|
|
591
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
592
|
+ true,
|
|
|
593
|
+ "Duplicate for idempotency. Changing browsing mode to total clearing should set memory only permissions to true"
|
|
|
594
|
+ );
|
|
|
595
|
+
|
|
|
596
|
+ resetToTotalSavingPrefs();
|
|
|
597
|
+
|
|
|
598
|
+ Services.prefs.setIntPref(
|
|
|
599
|
+ kSelectiveSavingModePref,
|
|
|
600
|
+ SelectiveSavingModes.selective_saving
|
|
|
601
|
+ );
|
|
|
602
|
+
|
|
|
603
|
+ Assert.equal(
|
|
|
604
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
605
|
+ SelectiveSavingModes.selective_saving,
|
|
|
606
|
+ "Changing browsing mode to selective saving should set browsing mode to match"
|
|
|
607
|
+ );
|
|
|
608
|
+
|
|
|
609
|
+ Assert.equal(
|
|
|
610
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
611
|
+ true,
|
|
|
612
|
+ "Changing browsing mode to selective saving should set sanitize on shutdown to true"
|
|
|
613
|
+ );
|
|
|
614
|
+
|
|
|
615
|
+ Assert.equal(
|
|
|
616
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
617
|
+ false,
|
|
|
618
|
+ "Changing browsing mode to selective saving should set pbm autostart to false"
|
|
|
619
|
+ );
|
|
|
620
|
+
|
|
|
621
|
+ Assert.equal(
|
|
|
622
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
623
|
+ false,
|
|
|
624
|
+ "Changing browsing mode to selective saving should set memory only permissions to false"
|
|
|
625
|
+ );
|
|
|
626
|
+
|
|
|
627
|
+ resetToTotalSavingPrefs();
|
|
|
628
|
+
|
|
|
629
|
+ Services.prefs.setIntPref(
|
|
|
630
|
+ kSelectiveSavingModePref,
|
|
|
631
|
+ SelectiveSavingModes.normal_browsing
|
|
|
632
|
+ );
|
|
|
633
|
+
|
|
|
634
|
+ Assert.equal(
|
|
|
635
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
636
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
637
|
+ "Changing browsing mode to normal browsing should set browsing mode to match"
|
|
|
638
|
+ );
|
|
|
639
|
+
|
|
|
640
|
+ Assert.equal(
|
|
|
641
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
642
|
+ false,
|
|
|
643
|
+ "Changing browsing mode to normal browsing should set sanitize on shutdown to true"
|
|
|
644
|
+ );
|
|
|
645
|
+
|
|
|
646
|
+ Assert.equal(
|
|
|
647
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
648
|
+ false,
|
|
|
649
|
+ "Changing browsing mode to normal browsing should set pbm autostart to false"
|
|
|
650
|
+ );
|
|
|
651
|
+
|
|
|
652
|
+ Assert.equal(
|
|
|
653
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
654
|
+ false,
|
|
|
655
|
+ "Changing browsing mode to normal browsing should set memory only permissions to false"
|
|
|
656
|
+ );
|
|
|
657
|
+
|
|
|
658
|
+ resetToTotalSavingPrefs();
|
|
|
659
|
+
|
|
|
660
|
+ for (const sanitize of [false, true]) {
|
|
|
661
|
+ for (const pbmAutostart of [false, true]) {
|
|
|
662
|
+ for (const permissions of [false, true]) {
|
|
|
663
|
+ Services.prefs.setBoolPref(kSanitizeOnShutdown, sanitize);
|
|
|
664
|
+ Services.prefs.setBoolPref(kPrivateBrowsingAutostart, pbmAutostart);
|
|
|
665
|
+ Services.prefs.setBoolPref(kKeepPermissionInMemory, permissions);
|
|
|
666
|
+
|
|
|
667
|
+ if (sanitize && pbmAutostart && permissions) {
|
|
|
668
|
+ Assert.equal(
|
|
|
669
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
670
|
+ SelectiveSavingModes.total_clearing,
|
|
|
671
|
+ "pref settings for true true true should result in total clearing"
|
|
|
672
|
+ );
|
|
|
673
|
+ } else if (sanitize && !pbmAutostart && !permissions) {
|
|
|
674
|
+ Assert.equal(
|
|
|
675
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
676
|
+ SelectiveSavingModes.selective_saving,
|
|
|
677
|
+ "pref settings for true false false should result in selective saving"
|
|
|
678
|
+ );
|
|
|
679
|
+ } else if (!sanitize && !pbmAutostart && !permissions) {
|
|
|
680
|
+ Assert.equal(
|
|
|
681
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
682
|
+ SelectiveSavingModes.normal_browsing,
|
|
|
683
|
+ "pref settings for false false false should result in normal browsing"
|
|
|
684
|
+ );
|
|
|
685
|
+ } else {
|
|
|
686
|
+ Assert.equal(
|
|
|
687
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
688
|
+ SelectiveSavingModes.custom,
|
|
|
689
|
+ `pref settings of ${sanitize} ${pbmAutostart} ${permissions} should result in custom browsing`
|
|
|
690
|
+ );
|
|
|
691
|
+ }
|
|
|
692
|
+ }
|
|
|
693
|
+ }
|
|
|
694
|
+ }
|
|
|
695
|
+
|
|
|
696
|
+ Services.prefs.setIntPref(
|
|
|
697
|
+ kSelectiveSavingModePref,
|
|
|
698
|
+ SelectiveSavingModes.custom
|
|
|
699
|
+ );
|
|
|
700
|
+
|
|
|
701
|
+ Assert.equal(
|
|
|
702
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
703
|
+ SelectiveSavingModes.custom,
|
|
|
704
|
+ "Manually changing to custom browsing via primary pref should happen regardless of secondary prefs"
|
|
|
705
|
+ );
|
|
|
706
|
+
|
|
|
707
|
+ Assert.equal(
|
|
|
708
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
709
|
+ true,
|
|
|
710
|
+ "Changing browsing mode to custom should leave sanitize on shutdown as previously set"
|
|
|
711
|
+ );
|
|
|
712
|
+
|
|
|
713
|
+ Assert.equal(
|
|
|
714
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
715
|
+ true,
|
|
|
716
|
+ "Changing browsing mode to custom should leave pbm autostart as previously set"
|
|
|
717
|
+ );
|
|
|
718
|
+
|
|
|
719
|
+ Assert.equal(
|
|
|
720
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
721
|
+ true,
|
|
|
722
|
+ "Changing browsing mode to custom should leave memory only permissions as previously set"
|
|
|
723
|
+ );
|
|
|
724
|
+
|
|
|
725
|
+ resetToTotalSavingPrefs();
|
|
|
726
|
+
|
|
|
727
|
+ Services.prefs.setIntPref(
|
|
|
728
|
+ kSelectiveSavingModePref,
|
|
|
729
|
+ SelectiveSavingModes.unconfigured
|
|
|
730
|
+ );
|
|
|
731
|
+
|
|
|
732
|
+ Assert.notEqual(
|
|
|
733
|
+ Services.prefs.getIntPref(kSelectiveSavingModePref),
|
|
|
734
|
+ SelectiveSavingModes.unconfigured,
|
|
|
735
|
+ "Manually changing to unconfigured mode via primary pref should set primary pref based on secondary prefs"
|
|
|
736
|
+ );
|
|
|
737
|
+
|
|
|
738
|
+ Assert.equal(
|
|
|
739
|
+ Services.prefs.getBoolPref(kSanitizeOnShutdown),
|
|
|
740
|
+ true,
|
|
|
741
|
+ "Changing browsing mode to unconfigured should leave sanitize on shutdown as previously set"
|
|
|
742
|
+ );
|
|
|
743
|
+
|
|
|
744
|
+ Assert.equal(
|
|
|
745
|
+ Services.prefs.getBoolPref(kPrivateBrowsingAutostart),
|
|
|
746
|
+ true,
|
|
|
747
|
+ "Changing browsing mode to unconfigured should leave pbm autostart to true as previously set"
|
|
|
748
|
+ );
|
|
|
749
|
+
|
|
|
750
|
+ Assert.equal(
|
|
|
751
|
+ Services.prefs.getBoolPref(kKeepPermissionInMemory),
|
|
|
752
|
+ true,
|
|
|
753
|
+ "Changing browsing mode to unconfigured should leave memory only permissions to true as previously set"
|
|
|
754
|
+ );
|
|
|
755
|
+}); |