diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_metadata_filters.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_metadata_filters.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_metadata_filters.js b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_metadata_filters.js new file mode 100644 index 0000000000..8f7ecbdf29 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_metadata_filters.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests blocking of extensions by ID, name, creator, homepageURL, updateURL +// and RegExps for each. See bug 897735. + +// useMLBF=true only supports blocking by version+ID, not by other fields. +enable_blocklist_v2_instead_of_useMLBF(); + +const BLOCKLIST_DATA = { + extensions: [ + { + guid: null, + name: "/^Mozilla Corp\\.$/", + versionRange: [ + { + severity: "1", + targetApplication: [ + { + guid: "xpcshell@tests.mozilla.org", + maxVersion: "2.*", + minVersion: "1", + }, + ], + }, + ], + }, + { + guid: "/block2/", + name: "/^Moz/", + homepageURL: "/\\.dangerous\\.com/", + updateURL: "/\\.dangerous\\.com/", + versionRange: [ + { + severity: "3", + targetApplication: [ + { + guid: "xpcshell@tests.mozilla.org", + maxVersion: "2.*", + minVersion: "1", + }, + ], + }, + ], + }, + ], +}; + +add_task(async function setup() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1"); + + await promiseStartupManager(); + + // Should get blocked by name + await promiseInstallWebExtension({ + manifest: { + name: "Mozilla Corp.", + version: "1.0", + browser_specific_settings: { gecko: { id: "block1@tests.mozilla.org" } }, + }, + }); + + // Should get blocked by all the attributes. + await promiseInstallWebExtension({ + manifest: { + name: "Moz-addon", + version: "1.0", + homepage_url: "https://www.extension.dangerous.com/", + browser_specific_settings: { + gecko: { + id: "block2@tests.mozilla.org", + update_url: "https://www.extension.dangerous.com/update.json", + }, + }, + }, + }); + + // Fails to get blocked because of a different ID even though other + // attributes match against a blocklist entry. + await promiseInstallWebExtension({ + manifest: { + name: "Moz-addon", + version: "1.0", + homepage_url: "https://www.extension.dangerous.com/", + browser_specific_settings: { + gecko: { + id: "block3@tests.mozilla.org", + update_url: "https://www.extension.dangerous.com/update.json", + }, + }, + }, + }); + + let [a1, a2, a3] = await AddonManager.getAddonsByIDs([ + "block1@tests.mozilla.org", + "block2@tests.mozilla.org", + "block3@tests.mozilla.org", + ]); + Assert.equal(a1.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); + Assert.equal(a2.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); + Assert.equal(a3.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); +}); + +add_task(async function test_blocks() { + await AddonTestUtils.loadBlocklistRawData(BLOCKLIST_DATA); + + let [a1, a2, a3] = await AddonManager.getAddonsByIDs([ + "block1@tests.mozilla.org", + "block2@tests.mozilla.org", + "block3@tests.mozilla.org", + ]); + Assert.equal(a1.blocklistState, Ci.nsIBlocklistService.STATE_SOFTBLOCKED); + Assert.equal(a2.blocklistState, Ci.nsIBlocklistService.STATE_BLOCKED); + Assert.equal(a3.blocklistState, Ci.nsIBlocklistService.STATE_NOT_BLOCKED); +}); |