зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1746686 - Use `ChromeUtils.import` with one parameter in add-ons test code. r=robwu
Export some new TestUtils objects for code only used by tests. Remove obsolete code for the Adobe EME plugin. Differential Revision: https://phabricator.services.mozilla.com/D134220
This commit is contained in:
Родитель
89585cfcc9
Коммит
b1bff09171
18
.eslintrc.js
18
.eslintrc.js
|
@ -537,24 +537,6 @@ module.exports = {
|
|||
"mozilla/prefer-boolean-length-check": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
// TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
|
||||
files: [
|
||||
"toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
|
||||
"toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.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_signed_updatepref.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
|
||||
"toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
|
||||
],
|
||||
rules: {
|
||||
"mozilla/reject-chromeutils-import-params": "warn",
|
||||
},
|
||||
},
|
||||
{
|
||||
// Rules of Hooks broadly checks for camelCase "use" identifiers, so
|
||||
// enable only for paths actually using React to avoid false positives.
|
||||
|
|
|
@ -12,9 +12,7 @@ const { PromiseUtils } = ChromeUtils.import(
|
|||
"resource://gre/modules/PromiseUtils.jsm"
|
||||
);
|
||||
const { Log } = ChromeUtils.import("resource://gre/modules/Log.jsm");
|
||||
// These symbols are, unfortunately, accessed via the module global from
|
||||
// tests, and therefore cannot be lexical definitions.
|
||||
var { GMPPrefs, GMPUtils, GMP_PLUGIN_IDS } = ChromeUtils.import(
|
||||
const { GMPPrefs, GMPUtils, GMP_PLUGIN_IDS, WIDEVINE_ID } = ChromeUtils.import(
|
||||
"resource://gre/modules/GMPUtils.jsm"
|
||||
);
|
||||
const { ProductAddonChecker } = ChromeUtils.import(
|
||||
|
@ -647,7 +645,7 @@ GMPAddon.prototype = {
|
|||
);
|
||||
},
|
||||
get isEME() {
|
||||
return this.id == "gmp-widevinecdm" || this.id.indexOf("gmp-eme-") == 0;
|
||||
return this.id == WIDEVINE_ID;
|
||||
},
|
||||
get isOpenH264() {
|
||||
return this.id == "gmp-gmpopenh264";
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
var EXPORTED_SYMBOLS = ["PermissionsUtils"];
|
||||
var EXPORTED_SYMBOLS = ["PermissionsUtils", "PermissionsTestUtils"];
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
|
@ -102,3 +102,10 @@ var PermissionsUtils = {
|
|||
gImportedPrefBranches.add(aPrefBranch);
|
||||
},
|
||||
};
|
||||
|
||||
// For test use only.
|
||||
const PermissionsTestUtils = {
|
||||
clearImportedPrefBranches() {
|
||||
gImportedPrefBranches.clear();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3728,6 +3728,16 @@ var AddonManagerPrivate = {
|
|||
get finalShutdown() {
|
||||
return gFinalShutdownBarrier.client;
|
||||
},
|
||||
|
||||
// Used by tests to call repo shutdown.
|
||||
overrideAddonRepository(mockRepo) {
|
||||
AddonRepository = mockRepo;
|
||||
},
|
||||
|
||||
// Used by tests to shut down AddonManager.
|
||||
overrideAsyncShutdown(mockAsyncShutdown) {
|
||||
AsyncShutdown = mockAsyncShutdown;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -13,6 +13,9 @@ const CERTDB_CONTRACTID = "@mozilla.org/security/x509certdb;1";
|
|||
|
||||
Cu.importGlobalProperties(["fetch"]);
|
||||
|
||||
const { AddonManager, AddonManagerPrivate } = ChromeUtils.import(
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
const { AsyncShutdown } = ChromeUtils.import(
|
||||
"resource://gre/modules/AsyncShutdown.jsm"
|
||||
);
|
||||
|
@ -80,13 +83,6 @@ function isRegExp(val) {
|
|||
return val && typeof val === "object" && typeof val.test === "function";
|
||||
}
|
||||
|
||||
// We need some internal bits of AddonManager
|
||||
var AMscope = ChromeUtils.import(
|
||||
"resource://gre/modules/AddonManager.jsm",
|
||||
null
|
||||
);
|
||||
var { AddonManager, AddonManagerPrivate } = AMscope;
|
||||
|
||||
class MockBarrier {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
|
@ -129,7 +125,7 @@ var MockAsyncShutdown = {
|
|||
Barrier: AsyncShutdown.Barrier,
|
||||
};
|
||||
|
||||
AMscope.AsyncShutdown = MockAsyncShutdown;
|
||||
AddonManagerPrivate.overrideAsyncShutdown(MockAsyncShutdown);
|
||||
|
||||
class AddonsList {
|
||||
constructor(file) {
|
||||
|
@ -779,13 +775,12 @@ var AddonTestUtils = {
|
|||
// promiseShutdown to allow re-initialization.
|
||||
ExtensionAddonObserver.init();
|
||||
|
||||
let XPIScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIInternal, XPIProvider } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
XPIScope.AsyncShutdown = MockAsyncShutdown;
|
||||
XPIInternal.overrideAsyncShutdown(MockAsyncShutdown);
|
||||
|
||||
XPIScope.XPIInternal.BootstrapScope.prototype._beforeCallBootstrapMethod = (
|
||||
XPIInternal.BootstrapScope.prototype._beforeCallBootstrapMethod = (
|
||||
method,
|
||||
params,
|
||||
reason
|
||||
|
@ -809,15 +804,12 @@ var AddonTestUtils = {
|
|||
|
||||
this.emit("addon-manager-started");
|
||||
|
||||
await Promise.all(XPIScope.XPIProvider.startupPromises);
|
||||
await Promise.all(XPIProvider.startupPromises);
|
||||
|
||||
// Load the add-ons list as it was after extension registration
|
||||
await this.loadAddonsList(true);
|
||||
|
||||
// Wait for all add-ons to finish starting up before resolving.
|
||||
const { XPIProvider } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
await Promise.all(
|
||||
Array.from(
|
||||
XPIProvider.activeAddons.values(),
|
||||
|
@ -845,9 +837,11 @@ var AddonTestUtils = {
|
|||
this.overrideEntry = null;
|
||||
}
|
||||
|
||||
const XPIscope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIProvider } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
const { XPIDatabase } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIDatabase.jsm"
|
||||
);
|
||||
|
||||
// Ensure some startup observers in XPIProvider are released.
|
||||
|
@ -860,7 +854,7 @@ var AddonTestUtils = {
|
|||
// a promise, potentially still pending. Wait for it to settle before
|
||||
// triggering profileBeforeChange, because the latter can trigger errors in
|
||||
// the pending asyncLoadDB() by an indirect call to XPIDatabase.shutdown().
|
||||
await XPIscope.XPIDatabase._dbPromise;
|
||||
await XPIDatabase._dbPromise;
|
||||
|
||||
await MockAsyncShutdown.profileBeforeChange.trigger();
|
||||
await MockAsyncShutdown.profileChangeTeardown.trigger();
|
||||
|
@ -891,23 +885,14 @@ var AddonTestUtils = {
|
|||
|
||||
// This would be cleaner if I could get it as the rejection reason from
|
||||
// the AddonManagerInternal.shutdown() promise
|
||||
let shutdownError = XPIscope.XPIDatabase._saveError;
|
||||
let shutdownError = XPIDatabase._saveError;
|
||||
|
||||
AddonManagerPrivate.unregisterProvider(XPIscope.XPIProvider);
|
||||
AddonManagerPrivate.unregisterProvider(XPIProvider);
|
||||
Cu.unload("resource://gre/modules/addons/XPIProvider.jsm");
|
||||
Cu.unload("resource://gre/modules/addons/XPIDatabase.jsm");
|
||||
Cu.unload("resource://gre/modules/addons/XPIInstall.jsm");
|
||||
|
||||
let ExtensionScope = ChromeUtils.import(
|
||||
"resource://gre/modules/Extension.jsm",
|
||||
null
|
||||
);
|
||||
ExtensionAddonObserver.uninit();
|
||||
ChromeUtils.defineModuleGetter(
|
||||
ExtensionScope,
|
||||
"XPIProvider",
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
|
||||
ExtensionTestCommon.resetStartupPromises();
|
||||
|
||||
|
@ -955,12 +940,11 @@ var AddonTestUtils = {
|
|||
|
||||
async loadAddonsList(flush = false) {
|
||||
if (flush) {
|
||||
let XPIScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIInternal } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
XPIScope.XPIStates.save();
|
||||
await XPIScope.XPIStates._jsonFile._save();
|
||||
XPIInternal.XPIStates.save();
|
||||
await XPIInternal.XPIStates._jsonFile._save();
|
||||
}
|
||||
|
||||
this.addonsList = new AddonsList(this.addonStartup);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var EXPORTED_SYMBOLS = [];
|
||||
var EXPORTED_SYMBOLS = ["GMPTestUtils"];
|
||||
|
||||
const { XPCOMUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/XPCOMUtils.jsm"
|
||||
|
@ -867,3 +867,25 @@ var GMPProvider = {
|
|||
};
|
||||
|
||||
GMPProvider.addObserver();
|
||||
|
||||
// For test use only.
|
||||
const GMPTestUtils = {
|
||||
/**
|
||||
* Used to override the GMP service with a mock.
|
||||
*
|
||||
* @param {object} mockService
|
||||
* The mocked gmpService object.
|
||||
* @param {function} callback
|
||||
* Method called with the overridden gmpService. The override
|
||||
* is undone after the callback returns.
|
||||
*/
|
||||
async overrideGmpService(mockService, callback) {
|
||||
let originalGmpService = gmpService;
|
||||
gmpService = mockService;
|
||||
try {
|
||||
return await callback();
|
||||
} finally {
|
||||
gmpService = originalGmpService;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -3312,6 +3312,11 @@ var XPIInternal = {
|
|||
maybeResolveURI,
|
||||
migrateAddonLoader,
|
||||
resolveDBReady,
|
||||
|
||||
// Used by tests to shut down AddonManager.
|
||||
overrideAsyncShutdown(mockAsyncShutdown) {
|
||||
AsyncShutdown = mockAsyncShutdown;
|
||||
},
|
||||
};
|
||||
|
||||
AddonManagerPrivate.registerProvider(XPIProvider, Array.from(ALL_XPI_TYPES));
|
||||
|
|
|
@ -10,23 +10,23 @@ const { PromiseUtils } = ChromeUtils.import(
|
|||
const { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
var GMPScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/GMPProvider.jsm",
|
||||
null
|
||||
const { GMPInstallManager } = ChromeUtils.import(
|
||||
"resource://gre/modules/GMPInstallManager.jsm"
|
||||
);
|
||||
const { GMPPrefs, GMP_PLUGIN_IDS, WIDEVINE_ID } = ChromeUtils.import(
|
||||
"resource://gre/modules/GMPUtils.jsm"
|
||||
);
|
||||
|
||||
const TEST_DATE = new Date(2013, 0, 1, 12);
|
||||
|
||||
var gMockAddons = [];
|
||||
|
||||
for (let plugin of GMPScope.GMP_PLUGINS) {
|
||||
for (let pluginId of GMP_PLUGIN_IDS) {
|
||||
let mockAddon = Object.freeze({
|
||||
id: plugin.id,
|
||||
id: pluginId,
|
||||
isValid: true,
|
||||
isInstalled: false,
|
||||
isEME: !!(
|
||||
plugin.id == "gmp-widevinecdm" || plugin.id.indexOf("gmp-eme-") == 0
|
||||
),
|
||||
isEME: pluginId == WIDEVINE_ID,
|
||||
});
|
||||
gMockAddons.push(mockAddon);
|
||||
}
|
||||
|
@ -34,11 +34,9 @@ for (let plugin of GMPScope.GMP_PLUGINS) {
|
|||
var gInstalledAddonId = "";
|
||||
var gInstallDeferred = null;
|
||||
var gPrefs = Services.prefs;
|
||||
var getKey = GMPScope.GMPPrefs.getPrefKey;
|
||||
var getKey = GMPPrefs.getPrefKey;
|
||||
|
||||
function MockGMPInstallManager() {}
|
||||
|
||||
MockGMPInstallManager.prototype = {
|
||||
const MockGMPInstallManagerPrototype = {
|
||||
checkForAddons: () =>
|
||||
Promise.resolve({
|
||||
usedFallback: true,
|
||||
|
@ -63,69 +61,40 @@ function openDetailsView(win, id) {
|
|||
}
|
||||
|
||||
add_task(async function initializeState() {
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_LOGGING_DUMP, true);
|
||||
gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_LOGGING_LEVEL, 0);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_LOGGING_DUMP, true);
|
||||
gPrefs.setIntPref(GMPPrefs.KEY_LOGGING_LEVEL, 0);
|
||||
|
||||
registerCleanupFunction(async function() {
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id));
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id));
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id));
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id));
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id));
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id)
|
||||
getKey(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id)
|
||||
);
|
||||
}
|
||||
gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_LOGGING_DUMP);
|
||||
gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_LOGGING_LEVEL);
|
||||
gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK);
|
||||
gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_EME_ENABLED);
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
gPrefs.clearUserPref(GMPPrefs.KEY_LOGGING_DUMP);
|
||||
gPrefs.clearUserPref(GMPPrefs.KEY_LOGGING_LEVEL);
|
||||
gPrefs.clearUserPref(GMPPrefs.KEY_UPDATE_LAST_CHECK);
|
||||
gPrefs.clearUserPref(GMPPrefs.KEY_EME_ENABLED);
|
||||
});
|
||||
|
||||
// Start out with plugins not being installed, disabled and automatic updates
|
||||
// disabled.
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, true);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, true);
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), false);
|
||||
gPrefs.setIntPref(getKey(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id), 0);
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id), false);
|
||||
gPrefs.setCharPref(getKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id), "");
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id), true);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setIntPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id),
|
||||
0
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setCharPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
""
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
true
|
||||
);
|
||||
}
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
});
|
||||
|
||||
add_task(async function testNotInstalledDisabled() {
|
||||
|
@ -180,10 +149,7 @@ add_task(async function testNotInstalled() {
|
|||
let win = await loadInitialView("plugin");
|
||||
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), true);
|
||||
let item = getAddonCard(win, addon.id);
|
||||
Assert.ok(item, "Got add-on element:" + addon.id);
|
||||
|
||||
|
@ -238,15 +204,12 @@ add_task(async function testInstalled() {
|
|||
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.setIntPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, addon.id),
|
||||
TEST_DATE.getTime()
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id), false);
|
||||
gPrefs.setCharPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
"1.2.3.4"
|
||||
);
|
||||
|
||||
|
@ -292,7 +255,7 @@ add_task(async function testInstalledDetails() {
|
|||
|
||||
add_task(async function testInstalledGlobalEmeDisabled() {
|
||||
let win = await loadInitialView("plugin");
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, false);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, false);
|
||||
|
||||
for (let addon of gMockAddons) {
|
||||
let item = getAddonCard(win, addon.id);
|
||||
|
@ -303,7 +266,7 @@ add_task(async function testInstalledGlobalEmeDisabled() {
|
|||
}
|
||||
}
|
||||
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, true);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, true);
|
||||
await closeView(win);
|
||||
});
|
||||
|
||||
|
@ -323,11 +286,11 @@ add_task(async function testPreferencesButton() {
|
|||
for (let addon of gMockAddons) {
|
||||
let win = await loadInitialView("plugin");
|
||||
gPrefs.setCharPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
preferences.version
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
preferences.enabled
|
||||
);
|
||||
|
||||
|
@ -356,15 +319,12 @@ add_task(async function testPreferencesButton() {
|
|||
});
|
||||
|
||||
add_task(async function testUpdateButton() {
|
||||
gPrefs.clearUserPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK);
|
||||
gPrefs.clearUserPref(GMPPrefs.KEY_UPDATE_LAST_CHECK);
|
||||
|
||||
let originalInstallManager = GMPScope.GMPInstallManager;
|
||||
Object.defineProperty(GMPScope, "GMPInstallManager", {
|
||||
value: MockGMPInstallManager,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
// The GMPInstallManager constructor has an empty body,
|
||||
// so replacing the prototype is safe.
|
||||
let originalInstallManager = GMPInstallManager.prototype;
|
||||
GMPInstallManager.prototype = MockGMPInstallManagerPrototype;
|
||||
|
||||
let win = await loadInitialView("plugin");
|
||||
|
||||
|
@ -385,39 +345,22 @@ add_task(async function testUpdateButton() {
|
|||
|
||||
await switchView(win, "plugin");
|
||||
}
|
||||
Object.defineProperty(GMPScope, "GMPInstallManager", {
|
||||
value: originalInstallManager,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
GMPInstallManager.prototype = originalInstallManager;
|
||||
|
||||
await closeView(win);
|
||||
});
|
||||
|
||||
add_task(async function testEmeSupport() {
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.clearUserPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(getKey(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id));
|
||||
}
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
|
||||
let win = await loadInitialView("plugin");
|
||||
|
||||
for (let addon of gMockAddons) {
|
||||
let item = getAddonCard(win, addon.id);
|
||||
if (addon.id == GMPScope.EME_ADOBE_ID) {
|
||||
if (AppConstants.isPlatformAndVersionAtLeast("win", "6")) {
|
||||
Assert.ok(item, "Adobe EME supported, found add-on element.");
|
||||
} else {
|
||||
Assert.ok(
|
||||
!item,
|
||||
"Adobe EME not supported, couldn't find add-on element."
|
||||
);
|
||||
}
|
||||
} else if (addon.id == GMPScope.WIDEVINE_ID) {
|
||||
if (addon.id == WIDEVINE_ID) {
|
||||
if (
|
||||
AppConstants.isPlatformAndVersionAtLeast("win", "6") ||
|
||||
AppConstants.platform == "macosx" ||
|
||||
|
@ -438,15 +381,10 @@ add_task(async function testEmeSupport() {
|
|||
await closeView(win);
|
||||
|
||||
for (let addon of gMockAddons) {
|
||||
gPrefs.setBoolPref(getKey(GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id), true);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
getKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
getKey(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
true
|
||||
);
|
||||
}
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
});
|
||||
|
|
|
@ -30,6 +30,9 @@ const MAX_TIME_DIFFERENCE = 3000;
|
|||
// times are modified (10 hours old).
|
||||
const MAKE_FILE_OLD_DIFFERENCE = 10 * 3600 * 1000;
|
||||
|
||||
const { AddonManager, AddonManagerPrivate } = ChromeUtils.import(
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
var { AppConstants } = ChromeUtils.import(
|
||||
"resource://gre/modules/AppConstants.jsm"
|
||||
);
|
||||
|
@ -208,13 +211,6 @@ Object.defineProperty(this, "TEST_UNPACKED", {
|
|||
},
|
||||
});
|
||||
|
||||
// We need some internal bits of AddonManager
|
||||
var AMscope = ChromeUtils.import(
|
||||
"resource://gre/modules/AddonManager.jsm",
|
||||
null
|
||||
);
|
||||
var { AddonManager, AddonManagerInternal, AddonManagerPrivate } = AMscope;
|
||||
|
||||
const promiseAddonByID = AddonManager.getAddonByID;
|
||||
const promiseAddonsByIDs = AddonManager.getAddonsByIDs;
|
||||
|
||||
|
|
|
@ -657,7 +657,7 @@ add_task(async function run_test_13() {
|
|||
Assert.ok(gDBFile.exists());
|
||||
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, EMPTY_RESULT);
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
// Database should have been deleted
|
||||
Assert.ok(!gDBFile.exists());
|
||||
|
||||
|
@ -670,7 +670,7 @@ add_task(async function run_test_13() {
|
|||
add_task(async function run_test_14() {
|
||||
Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true);
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
await AddonRepository.flush();
|
||||
Assert.ok(gDBFile.exists());
|
||||
|
||||
|
@ -683,7 +683,7 @@ add_task(async function run_test_14() {
|
|||
add_task(async function run_test_15() {
|
||||
Services.prefs.setCharPref(PREF_GETADDONS_BYIDS, GETADDONS_RESULTS);
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
let aAddons = await promiseAddonsByIDs(ADDON_IDS);
|
||||
check_results(aAddons, WITH_CACHE);
|
||||
});
|
||||
|
@ -705,7 +705,7 @@ add_task(async function run_test_17() {
|
|||
"foo,bar,extension,baz"
|
||||
);
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
let aAddons = await promiseAddonsByIDs(ADDON_IDS);
|
||||
check_results(aAddons, WITH_EXTENSION_CACHE);
|
||||
});
|
||||
|
|
|
@ -71,7 +71,7 @@ add_task(async function test_paged_api() {
|
|||
});
|
||||
}
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
|
||||
let ids = [];
|
||||
for (let i = 0; i <= MAX_ADDON; i++) {
|
||||
|
|
|
@ -52,11 +52,10 @@ function checkChange(XS, aPath, aChange) {
|
|||
|
||||
// Get a reference to the XPIState (loaded by startupManager) so we can unit test it.
|
||||
function getXS() {
|
||||
let XPI = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIInternal } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm"
|
||||
);
|
||||
return XPI.XPIStates;
|
||||
return XPIInternal.XPIStates;
|
||||
}
|
||||
|
||||
async function getXSJSON() {
|
||||
|
|
|
@ -3,10 +3,18 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var GMPScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/GMPProvider.jsm",
|
||||
null
|
||||
const { GMPTestUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/GMPProvider.jsm"
|
||||
);
|
||||
const { GMPInstallManager } = ChromeUtils.import(
|
||||
"resource://gre/modules/GMPInstallManager.jsm"
|
||||
);
|
||||
const {
|
||||
GMPPrefs,
|
||||
GMP_PLUGIN_IDS,
|
||||
OPEN_H264_ID,
|
||||
WIDEVINE_ID,
|
||||
} = ChromeUtils.import("resource://gre/modules/GMPUtils.jsm");
|
||||
const { UpdateUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/UpdateUtils.jsm"
|
||||
);
|
||||
|
@ -20,32 +28,30 @@ XPCOMUtils.defineLazyGetter(
|
|||
var gMockAddons = new Map();
|
||||
var gMockEmeAddons = new Map();
|
||||
|
||||
for (let plugin of GMPScope.GMP_PLUGINS) {
|
||||
let mockAddon = Object.freeze({
|
||||
id: plugin.id,
|
||||
isValid: true,
|
||||
isInstalled: false,
|
||||
nameId: plugin.name,
|
||||
descriptionId: plugin.description,
|
||||
missingKey: plugin.missingKey,
|
||||
missingFilesKey: plugin.missingFilesKey,
|
||||
});
|
||||
gMockAddons.set(mockAddon.id, mockAddon);
|
||||
if (
|
||||
mockAddon.id == "gmp-widevinecdm" ||
|
||||
mockAddon.id.indexOf("gmp-eme-") == 0
|
||||
) {
|
||||
gMockEmeAddons.set(mockAddon.id, mockAddon);
|
||||
}
|
||||
}
|
||||
const mockH264Addon = Object.freeze({
|
||||
id: OPEN_H264_ID,
|
||||
isValid: true,
|
||||
isInstalled: false,
|
||||
nameId: "plugins-openh264-name",
|
||||
descriptionId: "plugins-openh264-description",
|
||||
});
|
||||
gMockAddons.set(mockH264Addon.id, mockH264Addon);
|
||||
|
||||
const mockWidevineAddon = Object.freeze({
|
||||
id: WIDEVINE_ID,
|
||||
isValid: true,
|
||||
isInstalled: false,
|
||||
nameId: "plugins-widevine-name",
|
||||
descriptionId: "plugins-widevine-description",
|
||||
});
|
||||
gMockAddons.set(mockWidevineAddon.id, mockWidevineAddon);
|
||||
gMockEmeAddons.set(mockWidevineAddon.id, mockWidevineAddon);
|
||||
|
||||
var gInstalledAddonId = "";
|
||||
var gPrefs = Services.prefs;
|
||||
var gGetKey = GMPScope.GMPPrefs.getPrefKey;
|
||||
var gGetKey = GMPPrefs.getPrefKey;
|
||||
|
||||
function MockGMPInstallManager() {}
|
||||
|
||||
MockGMPInstallManager.prototype = {
|
||||
const MockGMPInstallManagerPrototype = {
|
||||
checkForAddons: () =>
|
||||
Promise.resolve({
|
||||
usedFallback: true,
|
||||
|
@ -58,7 +64,13 @@ MockGMPInstallManager.prototype = {
|
|||
},
|
||||
};
|
||||
|
||||
add_task(async function setup() {
|
||||
add_setup(async () => {
|
||||
Assert.deepEqual(
|
||||
GMP_PLUGIN_IDS,
|
||||
Array.from(gMockAddons.keys()),
|
||||
"set of mock addons matches the actual set of plugins"
|
||||
);
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
|
||||
// The GMPProvider does not register until the first content process
|
||||
|
@ -67,36 +79,22 @@ add_task(async function setup() {
|
|||
|
||||
await promiseStartupManager();
|
||||
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_LOGGING_DUMP, true);
|
||||
gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_LOGGING_LEVEL, 0);
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, true);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_LOGGING_DUMP, true);
|
||||
gPrefs.setIntPref(GMPPrefs.KEY_LOGGING_LEVEL, 0);
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, true);
|
||||
for (let addon of gMockAddons.values()) {
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id), true);
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
|
||||
true
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function init() {
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
});
|
||||
|
||||
add_task(async function test_notInstalled() {
|
||||
for (let addon of gMockAddons.values()) {
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
""
|
||||
);
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setCharPref(gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id), "");
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), false);
|
||||
}
|
||||
|
||||
let addons = await promiseAddonsByIDs([...gMockAddons.keys()]);
|
||||
|
@ -162,15 +160,15 @@ add_task(async function test_installed() {
|
|||
file.append(addon.id);
|
||||
file.append(TEST_VERSION);
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, mockAddon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, mockAddon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setIntPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_LAST_UPDATE, mockAddon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_LAST_UPDATE, mockAddon.id),
|
||||
TEST_TIME_SEC
|
||||
);
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, mockAddon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, mockAddon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
|
||||
|
@ -206,10 +204,7 @@ add_task(async function test_enable() {
|
|||
Assert.equal(addons.length, gMockAddons.size);
|
||||
|
||||
for (let addon of addons) {
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), true);
|
||||
|
||||
Assert.ok(addon.isActive);
|
||||
Assert.ok(!addon.appDisabled);
|
||||
|
@ -226,9 +221,7 @@ add_task(async function test_globalEmeDisabled() {
|
|||
let addons = await promiseAddonsByIDs([...gMockEmeAddons.keys()]);
|
||||
Assert.equal(addons.length, gMockEmeAddons.size);
|
||||
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, false);
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, false);
|
||||
for (let addon of addons) {
|
||||
Assert.ok(!addon.isActive);
|
||||
Assert.ok(addon.appDisabled);
|
||||
|
@ -236,9 +229,7 @@ add_task(async function test_globalEmeDisabled() {
|
|||
|
||||
Assert.equal(addon.permissions, 0);
|
||||
}
|
||||
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, true);
|
||||
await GMPScope.GMPProvider.shutdown();
|
||||
GMPScope.GMPProvider.startup();
|
||||
gPrefs.setBoolPref(GMPPrefs.KEY_EME_ENABLED, true);
|
||||
});
|
||||
|
||||
add_task(async function test_autoUpdatePrefPersistance() {
|
||||
|
@ -246,10 +237,7 @@ add_task(async function test_autoUpdatePrefPersistance() {
|
|||
Assert.equal(addons.length, gMockAddons.size);
|
||||
|
||||
for (let addon of addons) {
|
||||
let autoupdateKey = gGetKey(
|
||||
GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE,
|
||||
addon.id
|
||||
);
|
||||
let autoupdateKey = gGetKey(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id);
|
||||
gPrefs.clearUserPref(autoupdateKey);
|
||||
|
||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
|
||||
|
@ -277,68 +265,59 @@ function createMockPluginFilesIfNeeded(aFile, aPluginId) {
|
|||
let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX;
|
||||
|
||||
createFile(libName);
|
||||
if (aPluginId == "gmp-widevinecdm") {
|
||||
if (aPluginId == WIDEVINE_ID) {
|
||||
createFile("manifest.json");
|
||||
} else {
|
||||
createFile(id + ".info");
|
||||
}
|
||||
if (aPluginId == "gmp-eme-adobe") {
|
||||
createFile(id + ".voucher");
|
||||
}
|
||||
}
|
||||
|
||||
// Array.includes() is only in Nightly channel, so polyfill so we don't fail
|
||||
// on other branches.
|
||||
if (![].includes) {
|
||||
Array.prototype.includes = function(element) {
|
||||
return Object(this).includes(element);
|
||||
};
|
||||
}
|
||||
|
||||
add_task(async function test_pluginRegistration() {
|
||||
const TEST_VERSION = "1.2.3.4";
|
||||
|
||||
let addedPaths = [];
|
||||
let removedPaths = [];
|
||||
let clearPaths = () => {
|
||||
addedPaths = [];
|
||||
removedPaths = [];
|
||||
};
|
||||
|
||||
const MockGMPService = {
|
||||
addPluginDirectory: path => {
|
||||
if (!addedPaths.includes(path)) {
|
||||
addedPaths.push(path);
|
||||
}
|
||||
},
|
||||
removePluginDirectory: path => {
|
||||
if (!removedPaths.includes(path)) {
|
||||
removedPaths.push(path);
|
||||
}
|
||||
},
|
||||
removeAndDeletePluginDirectory: path => {
|
||||
if (!removedPaths.includes(path)) {
|
||||
removedPaths.push(path);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let profD = do_get_profile();
|
||||
for (let addon of gMockAddons.values()) {
|
||||
await GMPTestUtils.overrideGmpService(MockGMPService, () =>
|
||||
testAddon(addon)
|
||||
);
|
||||
}
|
||||
|
||||
async function testAddon(addon) {
|
||||
let file = profD.clone();
|
||||
file.append(addon.id);
|
||||
file.append(TEST_VERSION);
|
||||
|
||||
let addedPaths = [];
|
||||
let removedPaths = [];
|
||||
let clearPaths = () => {
|
||||
addedPaths = [];
|
||||
removedPaths = [];
|
||||
};
|
||||
|
||||
let MockGMPService = {
|
||||
addPluginDirectory: path => {
|
||||
if (!addedPaths.includes(path)) {
|
||||
addedPaths.push(path);
|
||||
}
|
||||
},
|
||||
removePluginDirectory: path => {
|
||||
if (!removedPaths.includes(path)) {
|
||||
removedPaths.push(path);
|
||||
}
|
||||
},
|
||||
removeAndDeletePluginDirectory: path => {
|
||||
if (!removedPaths.includes(path)) {
|
||||
removedPaths.push(path);
|
||||
}
|
||||
},
|
||||
};
|
||||
GMPScope.gmpService = MockGMPService;
|
||||
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), true);
|
||||
|
||||
// Test that plugin registration fails if the plugin dynamic library and
|
||||
// info files are not present.
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
clearPaths();
|
||||
|
@ -351,7 +330,7 @@ add_task(async function test_pluginRegistration() {
|
|||
createMockPluginFilesIfNeeded(file, addon.id);
|
||||
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
clearPaths();
|
||||
|
@ -362,7 +341,7 @@ add_task(async function test_pluginRegistration() {
|
|||
// Setting the ABI to something invalid should cause plugin to be removed at startup.
|
||||
clearPaths();
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ABI, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_ABI, addon.id),
|
||||
"invalid-ABI"
|
||||
);
|
||||
await promiseRestartManager();
|
||||
|
@ -372,11 +351,11 @@ add_task(async function test_pluginRegistration() {
|
|||
// Setting the ABI to expected ABI should cause registration at startup.
|
||||
clearPaths();
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ABI, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_ABI, addon.id),
|
||||
UpdateUtils.ABI
|
||||
);
|
||||
await promiseRestartManager();
|
||||
|
@ -385,9 +364,7 @@ add_task(async function test_pluginRegistration() {
|
|||
|
||||
// Check that clearing the version doesn't trigger registration.
|
||||
clearPaths();
|
||||
gPrefs.clearUserPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id));
|
||||
Assert.deepEqual(addedPaths, []);
|
||||
Assert.deepEqual(removedPaths, [file.path]);
|
||||
|
||||
|
@ -399,7 +376,7 @@ add_task(async function test_pluginRegistration() {
|
|||
|
||||
// Changing the pref mid-session should cause unregistration and registration.
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
clearPaths();
|
||||
|
@ -408,7 +385,7 @@ add_task(async function test_pluginRegistration() {
|
|||
file2.append(addon.id);
|
||||
file2.append(TEST_VERSION_2);
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION_2
|
||||
);
|
||||
Assert.deepEqual(addedPaths, [file2.path]);
|
||||
|
@ -416,14 +393,11 @@ add_task(async function test_pluginRegistration() {
|
|||
|
||||
// Disabling the plugin should cause unregistration.
|
||||
gPrefs.setCharPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
gGetKey(GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
|
||||
TEST_VERSION
|
||||
);
|
||||
clearPaths();
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
false
|
||||
);
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), false);
|
||||
Assert.deepEqual(addedPaths, []);
|
||||
Assert.deepEqual(removedPaths, [file.path]);
|
||||
|
||||
|
@ -435,37 +409,26 @@ add_task(async function test_pluginRegistration() {
|
|||
|
||||
// Re-enabling the plugin should cause registration.
|
||||
clearPaths();
|
||||
gPrefs.setBoolPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id),
|
||||
true
|
||||
);
|
||||
gPrefs.setBoolPref(gGetKey(GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), true);
|
||||
Assert.deepEqual(addedPaths, [file.path]);
|
||||
Assert.deepEqual(removedPaths, []);
|
||||
GMPScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/GMPProvider.jsm",
|
||||
null
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_periodicUpdate() {
|
||||
Object.defineProperty(GMPScope, "GMPInstallManager", {
|
||||
value: MockGMPInstallManager,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
// The GMPInstallManager constructor has an empty body,
|
||||
// so replacing the prototype is safe.
|
||||
let originalInstallManager = GMPInstallManager.prototype;
|
||||
GMPInstallManager.prototype = MockGMPInstallManagerPrototype;
|
||||
|
||||
let addons = await promiseAddonsByIDs([...gMockAddons.keys()]);
|
||||
Assert.equal(addons.length, gMockAddons.size);
|
||||
|
||||
for (let addon of addons) {
|
||||
gPrefs.clearUserPref(
|
||||
gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id)
|
||||
);
|
||||
gPrefs.clearUserPref(gGetKey(GMPPrefs.KEY_PLUGIN_AUTOUPDATE, addon.id));
|
||||
|
||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
|
||||
gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
|
||||
gPrefs.setIntPref(GMPPrefs.KEY_UPDATE_LAST_CHECK, 0);
|
||||
let result = await addon.findUpdates(
|
||||
{},
|
||||
AddonManager.UPDATE_WHEN_PERIODIC_UPDATE
|
||||
|
@ -473,19 +436,17 @@ add_task(async function test_periodicUpdate() {
|
|||
Assert.strictEqual(result, false);
|
||||
|
||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
|
||||
gPrefs.setIntPref(
|
||||
GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK,
|
||||
Date.now() / 1000 - 60
|
||||
);
|
||||
gPrefs.setIntPref(GMPPrefs.KEY_UPDATE_LAST_CHECK, Date.now() / 1000 - 60);
|
||||
result = await addon.findUpdates(
|
||||
{},
|
||||
AddonManager.UPDATE_WHEN_PERIODIC_UPDATE
|
||||
);
|
||||
Assert.strictEqual(result, false);
|
||||
|
||||
const SEC_IN_A_DAY = 24 * 60 * 60;
|
||||
gPrefs.setIntPref(
|
||||
GMPScope.GMPPrefs.KEY_UPDATE_LAST_CHECK,
|
||||
Date.now() / 1000 - 2 * GMPScope.SEC_IN_A_DAY
|
||||
GMPPrefs.KEY_UPDATE_LAST_CHECK,
|
||||
Date.now() / 1000 - 2 * SEC_IN_A_DAY
|
||||
);
|
||||
gInstalledAddonId = "";
|
||||
result = await addon.findUpdates(
|
||||
|
@ -496,8 +457,5 @@ add_task(async function test_periodicUpdate() {
|
|||
Assert.equal(gInstalledAddonId, addon.id);
|
||||
}
|
||||
|
||||
GMPScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/GMPProvider.jsm",
|
||||
null
|
||||
);
|
||||
GMPInstallManager.prototype = originalInstallManager;
|
||||
});
|
||||
|
|
|
@ -6,11 +6,9 @@
|
|||
// bug 944006
|
||||
|
||||
// Load XPI Provider to get schema version ID
|
||||
var XPIScope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
);
|
||||
const { DB_SCHEMA } = XPIScope.XPIInternal;
|
||||
const {
|
||||
XPIInternal: { DB_SCHEMA },
|
||||
} = ChromeUtils.import("resource://gre/modules/addons/XPIProvider.jsm");
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
|
||||
const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
|
||||
|
||||
const { PermissionsTestUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/PermissionsUtils.jsm"
|
||||
);
|
||||
|
||||
function newPrincipal(uri) {
|
||||
return Services.scriptSecurityManager.createContentPrincipal(
|
||||
NetUtil.newURI(uri),
|
||||
|
@ -26,14 +30,6 @@ function do_check_permission_prefs(preferences) {
|
|||
}
|
||||
}
|
||||
|
||||
function clear_imported_preferences_cache() {
|
||||
let scope = ChromeUtils.import(
|
||||
"resource://gre/modules/PermissionsUtils.jsm",
|
||||
null
|
||||
);
|
||||
scope.gImportedPrefBranches.clear();
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
||||
|
||||
|
@ -72,7 +68,7 @@ add_task(async function setup() {
|
|||
// of code, such as a permissions management UI.
|
||||
|
||||
// First, request to flush all permissions
|
||||
clear_imported_preferences_cache();
|
||||
PermissionsTestUtils.clearImportedPrefBranches();
|
||||
Services.prefs.setCharPref(
|
||||
"xpinstall.whitelist.add.TEST2",
|
||||
"https://whitelist2.example.com"
|
||||
|
@ -81,7 +77,7 @@ add_task(async function setup() {
|
|||
do_check_permission_prefs(preferences);
|
||||
|
||||
// Then, request to flush just install permissions
|
||||
clear_imported_preferences_cache();
|
||||
PermissionsTestUtils.clearImportedPrefBranches();
|
||||
Services.prefs.setCharPref(
|
||||
"xpinstall.whitelist.add.TEST3",
|
||||
"https://whitelist3.example.com"
|
||||
|
@ -90,7 +86,7 @@ add_task(async function setup() {
|
|||
do_check_permission_prefs(preferences);
|
||||
|
||||
// And a request to flush some other permissions sholdn't flush install permissions
|
||||
clear_imported_preferences_cache();
|
||||
PermissionsTestUtils.clearImportedPrefBranches();
|
||||
Services.prefs.setCharPref(
|
||||
"xpinstall.whitelist.add.TEST4",
|
||||
"https://whitelist4.example.com"
|
||||
|
|
|
@ -51,12 +51,9 @@ function findInStatus(aStatus, aName) {
|
|||
* Make sure we report correctly when an add-on provider or AddonRepository block shutdown
|
||||
*/
|
||||
add_task(async function blockRepoShutdown() {
|
||||
// Reach into the AddonManager scope and inject our mock AddonRepository
|
||||
// the mock provider behaves enough like AddonRepository for the purpose of this test
|
||||
let mockRepo = mockAddonProvider("Mock repo");
|
||||
// Trigger the lazy getter so that we can assign a new value to it:
|
||||
void AMscope.AddonRepository;
|
||||
AMscope.AddonRepository = mockRepo;
|
||||
AddonManagerPrivate.overrideAddonRepository(mockRepo);
|
||||
|
||||
let mockProvider = mockAddonProvider("Mock provider");
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@ const IGNORE_PRIVATE = [
|
|||
"recordTiming",
|
||||
"BOOTSTRAP_REASONS",
|
||||
"notifyAddonChanged",
|
||||
"overrideAddonRepository",
|
||||
"overrideAsyncShutdown",
|
||||
];
|
||||
|
||||
async function test_functions() {
|
||||
|
|
|
@ -35,11 +35,10 @@ function verifySignatures() {
|
|||
Services.obs.addObserver(observer, "xpi-signature-changed");
|
||||
|
||||
info("Verifying signatures");
|
||||
let XPIscope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIDatabase } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIDatabase.jsm"
|
||||
);
|
||||
XPIscope.XPIDatabase.verifySignatures();
|
||||
XPIDatabase.verifySignatures();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -75,7 +74,7 @@ add_task(async function() {
|
|||
Assert.equal(addon.signedState, AddonManager.SIGNEDSTATE_MISSING);
|
||||
|
||||
// Update checks shouldn't affect the add-on
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
addon = await promiseAddonByID(ID);
|
||||
Assert.notEqual(addon, null);
|
||||
Assert.ok(!addon.appDisabled);
|
||||
|
|
|
@ -16,11 +16,10 @@ function verifySignatures() {
|
|||
Services.obs.addObserver(observer, "xpi-signature-changed");
|
||||
|
||||
info("Verifying signatures");
|
||||
let XPIscope = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIProvider.jsm",
|
||||
null
|
||||
const { XPIDatabase } = ChromeUtils.import(
|
||||
"resource://gre/modules/addons/XPIDatabase.jsm"
|
||||
);
|
||||
XPIscope.XPIDatabase.verifySignatures();
|
||||
XPIDatabase.verifySignatures();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ add_task(async function test_background_update() {
|
|||
],
|
||||
},
|
||||
() => {
|
||||
AddonManagerInternal.backgroundUpdateCheck();
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -768,7 +768,7 @@ add_task(async function test_no_auto_update() {
|
|||
},
|
||||
};
|
||||
AddonManager.addInstallListener(listener);
|
||||
AddonManagerInternal.backgroundUpdateCheck();
|
||||
AddonManagerPrivate.backgroundUpdateCheck();
|
||||
});
|
||||
AddonManager.removeInstallListener(listener);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ add_task(async function test_systems_update_uninstall_check() {
|
|||
"http://example.com/update.json?id=%ITEM_ID%"
|
||||
);
|
||||
|
||||
await AddonManagerInternal.backgroundUpdateCheck();
|
||||
await AddonManagerPrivate.backgroundUpdateCheck();
|
||||
|
||||
await promiseShutdownManager();
|
||||
});
|
||||
|
|
|
@ -3,8 +3,7 @@ createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
|
|||
add_task(async function() {
|
||||
let triggered = {};
|
||||
const { Management } = ChromeUtils.import(
|
||||
"resource://gre/modules/Extension.jsm",
|
||||
null
|
||||
"resource://gre/modules/Extension.jsm"
|
||||
);
|
||||
for (let event of ["install", "uninstall", "update"]) {
|
||||
triggered[event] = false;
|
||||
|
|
Загрузка…
Ссылка в новой задаче