mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
Bug 1633466 - Move common test logic to test/xpcshell/rs-blocklist/head.js r=Gijs
And introduce a helper to get the ExtensionBlocklistMBLF global without using a deprecated API, and remove the exception from eslintrc Differential Revision: https://phabricator.services.mozilla.com/D76712
This commit is contained in:
parent
192006582f
commit
41cc31b26c
@ -931,9 +931,6 @@ module.exports = {
|
||||
"toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf_fetch.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_mlbf_update.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
|
||||
|
@ -12,3 +12,36 @@ const MLBF_RECORD = {
|
||||
attachment_type: "bloomfilter-base",
|
||||
generation_time: 1577833200000,
|
||||
};
|
||||
|
||||
async function load_mlbf_record_as_blob() {
|
||||
const url = Services.io.newFileURI(
|
||||
do_get_file("../data/mlbf-blocked1-unblocked2.bin")
|
||||
).spec;
|
||||
Cu.importGlobalProperties(["fetch"]);
|
||||
return (await fetch(url)).blob();
|
||||
}
|
||||
|
||||
function getExtensionBlocklistMLBF() {
|
||||
// ExtensionBlocklist.Blocklist is an ExtensionBlocklistMLBF if the useMLBF
|
||||
// pref is set to true.
|
||||
// An alternative way to obtain ExtensionBlocklistMLBF is by importing the
|
||||
// global of Blocklist.jsm and reading ExtensionBlocklistMLBF off it, but
|
||||
// to avoid using the deprecated ChromeUtils.import(.., null), bug 1524027
|
||||
// needs to be fixed first. So let's use Blocklist.ExtensionBlocklist.
|
||||
const ExtensionBlocklistMLBF = Blocklist.ExtensionBlocklist;
|
||||
Assert.ok(
|
||||
Services.prefs.getBoolPref("extensions.blocklist.useMLBF", false),
|
||||
"blocklist.useMLBF should be true"
|
||||
);
|
||||
return ExtensionBlocklistMLBF;
|
||||
}
|
||||
|
||||
async function toggleStashPref(val, callbackAfterPrefChange = () => {}) {
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
Assert.ok(!ExtensionBlocklistMLBF._updatePromise, "no pending update");
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF.stashes", val);
|
||||
callbackAfterPrefChange();
|
||||
// A pref observer should trigger an update.
|
||||
Assert.ok(ExtensionBlocklistMLBF._updatePromise, "update pending");
|
||||
await Blocklist.ExtensionBlocklist._updatePromise;
|
||||
}
|
||||
|
@ -5,10 +5,7 @@
|
||||
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF", true);
|
||||
|
||||
const { ExtensionBlocklistMLBF } = ChromeUtils.import(
|
||||
"resource://gre/modules/Blocklist.jsm",
|
||||
null
|
||||
);
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
|
||||
AddonTestUtils.useRealCertChecks = true;
|
||||
|
@ -11,7 +11,7 @@
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF", true);
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF.stashes", true);
|
||||
|
||||
const { ExtensionBlocklist: ExtensionBlocklistMLBF } = Blocklist;
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
|
||||
// A known blocked version from bug 1626602.
|
||||
const blockedAddon = {
|
||||
|
@ -13,10 +13,7 @@ const { Downloader } = ChromeUtils.import(
|
||||
"resource://services-settings/Attachments.jsm"
|
||||
);
|
||||
|
||||
const { ExtensionBlocklistMLBF } = ChromeUtils.import(
|
||||
"resource://gre/modules/Blocklist.jsm",
|
||||
null
|
||||
);
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
|
||||
// This test needs to interact with the RemoteSettings client.
|
||||
ExtensionBlocklistMLBF.ensureInitialized();
|
||||
@ -49,15 +46,9 @@ add_task(async function fetch_invalid_mlbf_record() {
|
||||
|
||||
// Other tests can mock _testMLBF, so let's verify that it works as expected.
|
||||
add_task(async function fetch_valid_mlbf() {
|
||||
const url = Services.io.newFileURI(
|
||||
do_get_file("../data/mlbf-blocked1-unblocked2.bin")
|
||||
).spec;
|
||||
Cu.importGlobalProperties(["fetch"]);
|
||||
const blob = await (await fetch(url)).blob();
|
||||
|
||||
await ExtensionBlocklistMLBF._client.db.saveAttachment(
|
||||
ExtensionBlocklistMLBF.RS_ATTACHMENT_ID,
|
||||
{ record: JSON.parse(JSON.stringify(MLBF_RECORD)), blob }
|
||||
{ record: MLBF_RECORD, blob: await load_mlbf_record_as_blob() }
|
||||
);
|
||||
|
||||
const result = await ExtensionBlocklistMLBF._fetchMLBF(MLBF_RECORD);
|
||||
|
@ -8,7 +8,7 @@ Services.prefs.setBoolPref("extensions.blocklist.useMLBF.stashes", true);
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
|
||||
|
||||
const ExtensionBlocklistMLBF = Blocklist.ExtensionBlocklist;
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
const MLBF_LOAD_ATTEMPTS = [];
|
||||
ExtensionBlocklistMLBF._fetchMLBF = async record => {
|
||||
MLBF_LOAD_ATTEMPTS.push(record);
|
||||
@ -25,14 +25,6 @@ ExtensionBlocklistMLBF._fetchMLBF = async record => {
|
||||
};
|
||||
};
|
||||
|
||||
async function toggleStashPref(val) {
|
||||
Assert.ok(!ExtensionBlocklistMLBF._updatePromise, "no pending update");
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF.stashes", val);
|
||||
// A pref observer should trigger an update.
|
||||
Assert.ok(ExtensionBlocklistMLBF._updatePromise, "update pending");
|
||||
await Blocklist.ExtensionBlocklist._updatePromise;
|
||||
}
|
||||
|
||||
async function checkBlockState(addonId, version, expectBlocked) {
|
||||
let addon = {
|
||||
id: addonId,
|
||||
|
@ -7,10 +7,8 @@
|
||||
* @fileOverview Checks that the MLBF updating logic works reasonably.
|
||||
*/
|
||||
|
||||
const { ExtensionBlocklistMLBF } = ChromeUtils.import(
|
||||
"resource://gre/modules/Blocklist.jsm",
|
||||
null
|
||||
);
|
||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF", true);
|
||||
const ExtensionBlocklistMLBF = getExtensionBlocklistMLBF();
|
||||
|
||||
// This test needs to interact with the RemoteSettings client.
|
||||
ExtensionBlocklistMLBF.ensureInitialized();
|
||||
|
Loading…
x
Reference in New Issue
Block a user