Source code

Revision control

Other Tools

1
<!DOCTYPE HTML>
2
<html>
3
<head>
4
<title>BrowsingData Settings test</title>
7
<script type="text/javascript" src="head.js"></script>
8
<link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
9
</head>
10
<body>
11
12
<script type="text/javascript">
13
"use strict";
14
15
var {SharedPreferences} = ChromeUtils.import("resource://gre/modules/SharedPreferences.jsm");
16
17
const PREF_DOMAIN = "android.not_a_preference.privacy.clear";
18
const PREF_KEY_PREFIX = "private.data.";
19
const SETTINGS_LIST = ["cache", "cookies", "history", "formData", "downloads"];
20
21
function checkPrefs(key, actualValue, prefs, prefSuffix) {
22
let prefValue = prefs.includes(`${PREF_KEY_PREFIX}${prefSuffix}`);
23
is(actualValue, prefValue, `${key} property of dataToRemove matches the expected pref.`);
24
}
25
26
function testSettingsPreferences(dataToRemove) {
27
let prefs = SharedPreferences.forProfile().getSetPref(PREF_DOMAIN);
28
29
for (let key of Object.keys(dataToRemove)) {
30
switch (key) {
31
case "formData":
32
checkPrefs(key, dataToRemove[key], prefs, "formdata");
33
break;
34
case "cookies":
35
checkPrefs(key, dataToRemove[key], prefs, "cookies_sessions");
36
break;
37
case "downloads":
38
checkPrefs(key, dataToRemove[key], prefs, "downloadFiles");
39
break;
40
default:
41
checkPrefs(key, dataToRemove[key], prefs, key);
42
}
43
}
44
}
45
46
add_task(async function testSettings() {
47
function background() {
48
browser.test.onMessage.addListener(async (msg) => {
49
if (msg == "retrieve-settings") {
50
let settings = await browser.browsingData.settings();
51
browser.test.sendMessage("settings", settings);
52
}
53
});
54
}
55
56
let extension = ExtensionTestUtils.loadExtension({
57
background,
58
manifest: {
59
"permissions": ["browsingData"],
60
},
61
});
62
63
await extension.startup();
64
65
extension.sendMessage("retrieve-settings");
66
let {options, dataToRemove, dataRemovalPermitted} = await extension.awaitMessage("settings");
67
68
// Verify that we get the keys we expect.
69
is(SETTINGS_LIST.length, Object.keys(dataToRemove).length, `dataToRemove contains expected no of keys`);
70
is(SETTINGS_LIST.length, Object.keys(dataRemovalPermitted).length, `dataRemovalPermitted contains expected no of keys`);
71
for (let key of SETTINGS_LIST) {
72
is(true, dataRemovalPermitted[key],
73
`${key} property of dataRemovalPermitted matches the expected value.`);
74
}
75
76
// Verify values of dataToRemove keys are as expected.
77
testSettingsPreferences(dataToRemove);
78
79
// Verify object options returned as expected.
80
// For now, We do not provide option to delete history by time, so,
81
// since value is given 0, which means Everything.
82
is(options.since, 0, `options contains expected value.`);
83
84
// Explicitly set some prefs to true
85
const NEW_PREFS = ["private.data.cache", "private.data.cookies_sessions"];
86
87
SharedPreferences.forProfile().setSetPref(PREF_DOMAIN, NEW_PREFS);
88
89
extension.sendMessage("retrieve-settings");
90
let settings = await extension.awaitMessage("settings");
91
testSettingsPreferences(settings.dataToRemove);
92
93
await extension.unload();
94
});
95
</script>
96
97
</body>
98
</html>