1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42", "42");
const QUARANTINE_LIST_PREF = "extensions.quarantinedDomains.list";
async function testQuarantinedDomainsFromRemoteSettings() {
// Same as MAX_PREF_LENGTH as defined in Preferences.cpp,
// see https://searchfox.org/mozilla-central/rev/06510249/modules/libpref/Preferences.cpp#162
const MAX_PREF_LENGTH = 1 * 1024 * 1024;
const quarantinedDomainsSets = {
testSet1: "example.com,example.org",
testSet2: "someothersite.org,testset2.org",
};
await setAndEmitFakeRemoteSettingsData([
{
id: "quarantinedDomains-testSet-toolong",
quarantinedDomains: {
[QUARANTINE_LIST_PREF]: "x".repeat(MAX_PREF_LENGTH + 1),
},
},
{
id: "quarantinedDomains-testSet1",
quarantinedDomains: {
[QUARANTINE_LIST_PREF]: quarantinedDomainsSets.testSet1,
},
},
{
id: "quarantinedDomains-testSet2",
quarantinedDomains: {
[QUARANTINE_LIST_PREF]: quarantinedDomainsSets.testSet2,
},
},
]);
Assert.equal(
Services.prefs.getPrefType(QUARANTINE_LIST_PREF),
Services.prefs.PREF_STRING,
`Expect ${QUARANTINE_LIST_PREF} preference type to be string`
);
// The entry too big to fix in the pref value should throw but not preventing
// the other entries from being processed.
// The Last collection entry setting the pref wins, and so we expect
// the pref to be set to the domains listed in the collection
// entry with id "quarantinedDomains-testSet2".
Assert.equal(
Services.prefs.getStringPref(QUARANTINE_LIST_PREF),
quarantinedDomainsSets.testSet2,
`Got the expected value set on ${QUARANTINE_LIST_PREF}`
);
// Confirm that the updated quarantined domains list is now reflected
// by the results returned by WebExtensionPolicy.isQuarantinedURI.
// NOTE: Additional test coverage over the quarantined domains behaviors
// are part of a separate xpcshell test
// (see toolkit/components/extensions/test/xpcshell/test_QuarantinedDomains.js).
for (const domain of quarantinedDomainsSets.testSet2.split(",")) {
let uri = Services.io.newURI(`https://${domain}/`);
ok(
WebExtensionPolicy.isQuarantinedURI(uri),
`Expect ${domain} to be quarantined`
);
}
for (const domain of quarantinedDomainsSets.testSet1.split(",")) {
let uri = Services.io.newURI(`https://${domain}/`);
ok(
!WebExtensionPolicy.isQuarantinedURI(uri),
`Expect ${domain} to not be quarantined`
);
}
}
add_setup(async () => {
await AddonTestUtils.promiseStartupManager();
});
add_task(testQuarantinedDomainsFromRemoteSettings);
|