Bug 1746751 - Use ChromeUtils.import with one parameter in blocklist test code. r=robwu DONTBUILD
Export new `BlocklistPrivate` to allow tests to reach implementation objects. Differential Revision: https://phabricator.services.mozilla.com/D134234
This commit is contained in:
@@ -560,11 +560,6 @@ module.exports = {
|
|||||||
"toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
|
"toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
|
||||||
"toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
|
"toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
|
||||||
"toolkit/mozapps/extensions/test/xpcshell/head_addons.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_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",
|
|
||||||
"toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklistchange.js",
|
|
||||||
"toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
|
"toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
|
||||||
"toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
|
"toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
|
||||||
"toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
|
"toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
/* eslint "valid-jsdoc": [2, {requireReturn: false}] */
|
/* eslint "valid-jsdoc": [2, {requireReturn: false}] */
|
||||||
|
|
||||||
var EXPORTED_SYMBOLS = ["Blocklist"];
|
var EXPORTED_SYMBOLS = ["Blocklist", "BlocklistPrivate"];
|
||||||
|
|
||||||
const { XPCOMUtils } = ChromeUtils.import(
|
const { XPCOMUtils } = ChromeUtils.import(
|
||||||
"resource://gre/modules/XPCOMUtils.jsm"
|
"resource://gre/modules/XPCOMUtils.jsm"
|
||||||
@@ -263,8 +263,6 @@ const BlocklistTelemetry = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.BlocklistTelemetry = BlocklistTelemetry;
|
|
||||||
|
|
||||||
const Utils = {
|
const Utils = {
|
||||||
/**
|
/**
|
||||||
* Checks whether this entry is valid for the current OS and ABI.
|
* Checks whether this entry is valid for the current OS and ABI.
|
||||||
@@ -509,10 +507,8 @@ async function targetAppFilter(entry, environment) {
|
|||||||
* The RemoteSetttings client takes care of filtering out versions that don't apply.
|
* The RemoteSetttings client takes care of filtering out versions that don't apply.
|
||||||
* The code here stores entries in memory and sends them to the gfx component in
|
* The code here stores entries in memory and sends them to the gfx component in
|
||||||
* serialized text form, using ',', '\t' and '\n' as separators.
|
* serialized text form, using ',', '\t' and '\n' as separators.
|
||||||
*
|
|
||||||
* Note: we assign to the global to allow tests to reach the object directly.
|
|
||||||
*/
|
*/
|
||||||
this.GfxBlocklistRS = {
|
const GfxBlocklistRS = {
|
||||||
_ensureInitialized() {
|
_ensureInitialized() {
|
||||||
if (this._initialized || !gBlocklistEnabled) {
|
if (this._initialized || !gBlocklistEnabled) {
|
||||||
return;
|
return;
|
||||||
@@ -686,10 +682,8 @@ this.GfxBlocklistRS = {
|
|||||||
*
|
*
|
||||||
* This is a legacy format, and implements deprecated operations (bug 1620580).
|
* This is a legacy format, and implements deprecated operations (bug 1620580).
|
||||||
* ExtensionBlocklistMLBF supersedes this implementation.
|
* ExtensionBlocklistMLBF supersedes this implementation.
|
||||||
*
|
|
||||||
* Note: we assign to the global to allow tests to reach the object directly.
|
|
||||||
*/
|
*/
|
||||||
this.ExtensionBlocklistRS = {
|
const ExtensionBlocklistRS = {
|
||||||
async _ensureEntries() {
|
async _ensureEntries() {
|
||||||
this.ensureInitialized();
|
this.ensureInitialized();
|
||||||
if (!this._entries && gBlocklistEnabled) {
|
if (!this._entries && gBlocklistEnabled) {
|
||||||
@@ -956,10 +950,8 @@ this.ExtensionBlocklistRS = {
|
|||||||
*
|
*
|
||||||
* Stashes can be used to update the blocklist without forcing the whole MLBF
|
* Stashes can be used to update the blocklist without forcing the whole MLBF
|
||||||
* to be downloaded again. These stashes are applied on top of the base MLBF.
|
* to be downloaded again. These stashes are applied on top of the base MLBF.
|
||||||
*
|
|
||||||
* Note: we assign to the global to allow tests to reach the object directly.
|
|
||||||
*/
|
*/
|
||||||
this.ExtensionBlocklistMLBF = {
|
const ExtensionBlocklistMLBF = {
|
||||||
RS_ATTACHMENT_ID: "addons-mlbf.bin",
|
RS_ATTACHMENT_ID: "addons-mlbf.bin",
|
||||||
|
|
||||||
async _fetchMLBF(record) {
|
async _fetchMLBF(record) {
|
||||||
@@ -1484,3 +1476,11 @@ let Blocklist = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Blocklist._init();
|
Blocklist._init();
|
||||||
|
|
||||||
|
// Allow tests to reach implementation objects.
|
||||||
|
const BlocklistPrivate = {
|
||||||
|
BlocklistTelemetry,
|
||||||
|
ExtensionBlocklistMLBF,
|
||||||
|
ExtensionBlocklistRS,
|
||||||
|
GfxBlocklistRS,
|
||||||
|
};
|
||||||
|
|||||||
@@ -774,13 +774,12 @@ var AddonTestUtils = {
|
|||||||
* The data to load.
|
* The data to load.
|
||||||
*/
|
*/
|
||||||
async loadBlocklistRawData(data) {
|
async loadBlocklistRawData(data) {
|
||||||
const bsPass = ChromeUtils.import(
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Blocklist.jsm",
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
null
|
|
||||||
);
|
);
|
||||||
const blocklistMapping = {
|
const blocklistMapping = {
|
||||||
extensions: bsPass.ExtensionBlocklistRS,
|
extensions: BlocklistPrivate.ExtensionBlocklistRS,
|
||||||
extensionsMLBF: bsPass.ExtensionBlocklistMLBF,
|
extensionsMLBF: BlocklistPrivate.ExtensionBlocklistMLBF,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Since we load the specified test data, we shouldn't let the
|
// Since we load the specified test data, we shouldn't let the
|
||||||
|
|||||||
@@ -1200,7 +1200,9 @@ async function mockGfxBlocklistItemsFromDisk(path) {
|
|||||||
|
|
||||||
async function mockGfxBlocklistItems(items) {
|
async function mockGfxBlocklistItems(items) {
|
||||||
const { generateUUID } = Services.uuid;
|
const { generateUUID } = Services.uuid;
|
||||||
let bsPass = ChromeUtils.import("resource://gre/modules/Blocklist.jsm", null);
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
|
);
|
||||||
const client = RemoteSettings(
|
const client = RemoteSettings(
|
||||||
Services.prefs.getCharPref("services.blocklist.gfx.collection"),
|
Services.prefs.getCharPref("services.blocklist.gfx.collection"),
|
||||||
{ bucketNamePref: "services.blocklist.bucket" }
|
{ bucketNamePref: "services.blocklist.bucket" }
|
||||||
@@ -1221,7 +1223,7 @@ async function mockGfxBlocklistItems(items) {
|
|||||||
await client.db.importChanges({}, collectionTimestamp, records, {
|
await client.db.importChanges({}, collectionTimestamp, records, {
|
||||||
clear: true,
|
clear: true,
|
||||||
});
|
});
|
||||||
let rv = await bsPass.GfxBlocklistRS.checkForEntries();
|
let rv = await BlocklistPrivate.GfxBlocklistRS.checkForEntries();
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ function enable_blocklist_v2_instead_of_useMLBF() {
|
|||||||
Blocklist.allowDeprecatedBlocklistV2 = true;
|
Blocklist.allowDeprecatedBlocklistV2 = true;
|
||||||
Services.prefs.setBoolPref("extensions.blocklist.useMLBF", false);
|
Services.prefs.setBoolPref("extensions.blocklist.useMLBF", false);
|
||||||
// Sanity check: blocklist v2 has been enabled.
|
// Sanity check: blocklist v2 has been enabled.
|
||||||
Assert.ok(
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
!!Blocklist.ExtensionBlocklist._updateEntries,
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
|
);
|
||||||
|
Assert.equal(
|
||||||
|
Blocklist.ExtensionBlocklist,
|
||||||
|
BlocklistPrivate.ExtensionBlocklistRS,
|
||||||
"ExtensionBlocklistRS should have been enabled"
|
"ExtensionBlocklistRS should have been enabled"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -39,11 +43,9 @@ async function load_mlbf_record_as_blob() {
|
|||||||
function getExtensionBlocklistMLBF() {
|
function getExtensionBlocklistMLBF() {
|
||||||
// ExtensionBlocklist.Blocklist is an ExtensionBlocklistMLBF if the useMLBF
|
// ExtensionBlocklist.Blocklist is an ExtensionBlocklistMLBF if the useMLBF
|
||||||
// pref is set to true.
|
// pref is set to true.
|
||||||
// An alternative way to obtain ExtensionBlocklistMLBF is by importing the
|
const {
|
||||||
// global of Blocklist.jsm and reading ExtensionBlocklistMLBF off it, but
|
BlocklistPrivate: { ExtensionBlocklistMLBF },
|
||||||
// to avoid using the deprecated ChromeUtils.import(.., null), bug 1524027
|
} = ChromeUtils.import("resource://gre/modules/Blocklist.jsm");
|
||||||
// needs to be fixed first. So let's use Blocklist.ExtensionBlocklist.
|
|
||||||
const ExtensionBlocklistMLBF = Blocklist.ExtensionBlocklist;
|
|
||||||
Assert.ok(
|
Assert.ok(
|
||||||
Services.prefs.getBoolPref("extensions.blocklist.useMLBF", false),
|
Services.prefs.getBoolPref("extensions.blocklist.useMLBF", false),
|
||||||
"blocklist.useMLBF should be true"
|
"blocklist.useMLBF should be true"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const BlocklistGlobal = ChromeUtils.import(
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Blocklist.jsm",
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
null
|
|
||||||
);
|
);
|
||||||
const { Utils: RemoteSettingsUtils } = ChromeUtils.import(
|
const { Utils: RemoteSettingsUtils } = ChromeUtils.import(
|
||||||
"resource://services-settings/Utils.jsm"
|
"resource://services-settings/Utils.jsm"
|
||||||
@@ -29,17 +28,17 @@ add_task(async function setup() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// This will initialize the remote settings clients for blocklists.
|
// This will initialize the remote settings clients for blocklists.
|
||||||
BlocklistGlobal.ExtensionBlocklistRS.ensureInitialized();
|
BlocklistPrivate.ExtensionBlocklistRS.ensureInitialized();
|
||||||
BlocklistGlobal.GfxBlocklistRS._ensureInitialized();
|
BlocklistPrivate.GfxBlocklistRS._ensureInitialized();
|
||||||
|
|
||||||
// ExtensionBlocklistMLBF is covered by test_blocklist_mlbf_dump.js.
|
// ExtensionBlocklistMLBF is covered by test_blocklist_mlbf_dump.js.
|
||||||
gBlocklistClients = [
|
gBlocklistClients = [
|
||||||
{
|
{
|
||||||
client: BlocklistGlobal.ExtensionBlocklistRS._client,
|
client: BlocklistPrivate.ExtensionBlocklistRS._client,
|
||||||
expectHasDump: IS_ANDROID,
|
expectHasDump: IS_ANDROID,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
client: BlocklistGlobal.GfxBlocklistRS._client,
|
client: BlocklistPrivate.GfxBlocklistRS._client,
|
||||||
expectHasDump: !IS_ANDROID,
|
expectHasDump: !IS_ANDROID,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -57,11 +57,10 @@ add_task(async function test_check_matching_works() {
|
|||||||
extensions: BLOCKLIST_DATA,
|
extensions: BLOCKLIST_DATA,
|
||||||
});
|
});
|
||||||
|
|
||||||
let blocklistGlobal = ChromeUtils.import(
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Blocklist.jsm",
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
null
|
|
||||||
);
|
);
|
||||||
let parsedEntries = blocklistGlobal.ExtensionBlocklistRS._entries;
|
let parsedEntries = BlocklistPrivate.ExtensionBlocklistRS._entries;
|
||||||
|
|
||||||
// Unfortunately, the parsed entries aren't in the same order as the original.
|
// Unfortunately, the parsed entries aren't in the same order as the original.
|
||||||
function strForTypeOf(val) {
|
function strForTypeOf(val) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const BlocklistGlobal = ChromeUtils.import(
|
const { BlocklistPrivate } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Blocklist.jsm",
|
"resource://gre/modules/Blocklist.jsm"
|
||||||
null
|
|
||||||
);
|
);
|
||||||
const { RemoteSettings } = ChromeUtils.import(
|
const { RemoteSettings } = ChromeUtils.import(
|
||||||
"resource://services-settings/remote-settings.js"
|
"resource://services-settings/remote-settings.js"
|
||||||
@@ -33,7 +32,7 @@ function run_test() {
|
|||||||
);
|
);
|
||||||
// This will initialize the remote settings clients for blocklists,
|
// This will initialize the remote settings clients for blocklists,
|
||||||
// with their specific options etc.
|
// with their specific options etc.
|
||||||
BlocklistGlobal.ExtensionBlocklistRS.ensureInitialized();
|
BlocklistPrivate.ExtensionBlocklistRS.ensureInitialized();
|
||||||
// Obtain one of the instantiated client for our tests.
|
// Obtain one of the instantiated client for our tests.
|
||||||
client = RemoteSettings("addons", { bucketName: "blocklists" });
|
client = RemoteSettings("addons", { bucketName: "blocklists" });
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,12 @@ add_task(async function test_blocklist_lastModified_rs_scalars() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
BlocklistPrivate: {
|
||||||
BlocklistTelemetry,
|
BlocklistTelemetry,
|
||||||
ExtensionBlocklistRS,
|
|
||||||
ExtensionBlocklistMLBF,
|
ExtensionBlocklistMLBF,
|
||||||
} = ChromeUtils.import("resource://gre/modules/Blocklist.jsm", null);
|
ExtensionBlocklistRS,
|
||||||
|
},
|
||||||
|
} = ChromeUtils.import("resource://gre/modules/Blocklist.jsm");
|
||||||
|
|
||||||
// Return a promise resolved when the recordRSBlocklistLastModified method
|
// Return a promise resolved when the recordRSBlocklistLastModified method
|
||||||
// has been called (by temporarily replacing the method with a function that
|
// has been called (by temporarily replacing the method with a function that
|
||||||
|
|||||||
Reference in New Issue
Block a user