summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js122
1 files changed, 19 insertions, 103 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
index 545d7d666..8de3ab4a2 100644
--- a/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js
@@ -3,19 +3,14 @@
"use strict";
-var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-var GMPScope = Cu.import("resource://gre/modules/addons/GMPProvider.jsm");
-Cu.import("resource://gre/modules/AppConstants.jsm");
-Cu.import("resource://gre/modules/UpdateUtils.jsm");
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
+let GMPScope = Cu.import("resource://gre/modules/addons/GMPProvider.jsm");
XPCOMUtils.defineLazyGetter(this, "pluginsBundle",
() => Services.strings.createBundle("chrome://global/locale/plugins.properties"));
-XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
- "resource://gre/modules/FileUtils.jsm");
-
-var gMockAddons = new Map();
-var gMockEmeAddons = new Map();
+let gMockAddons = new Map();
+let gMockEmeAddons = new Map();
for (let plugin of GMPScope.GMP_PLUGINS) {
let mockAddon = Object.freeze({
@@ -24,28 +19,22 @@ for (let plugin of GMPScope.GMP_PLUGINS) {
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) {
+ if (mockAddon.id.indexOf("gmp-eme-") == 0) {
gMockEmeAddons.set(mockAddon.id, mockAddon);
}
}
-var gInstalledAddonId = "";
-var gPrefs = Services.prefs;
-var gGetKey = GMPScope.GMPPrefs.getPrefKey;
+let gInstalledAddonId = "";
+let gPrefs = Services.prefs;
+let gGetKey = GMPScope.GMPPrefs.getPrefKey;
function MockGMPInstallManager() {
}
MockGMPInstallManager.prototype = {
- checkForAddons: () => Promise.resolve({
- usedFallback: true,
- gmpAddons: [...gMockAddons.values()]
- }),
+ checkForAddons: () => Promise.resolve([...gMockAddons.values()]),
installAddon: addon => {
gInstalledAddonId = addon.id;
@@ -62,9 +51,7 @@ function run_test() {
gPrefs.setIntPref(GMPScope.GMPPrefs.KEY_LOGGING_LEVEL, 0);
gPrefs.setBoolPref(GMPScope.GMPPrefs.KEY_EME_ENABLED, true);
for (let addon of gMockAddons.values()) {
- gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VISIBLE, addon.id),
- true);
- gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCE_SUPPORTED, addon.id),
+ gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_FORCEVISIBLE, addon.id),
true);
}
GMPScope.GMPProvider.shutdown();
@@ -229,42 +216,11 @@ add_task(function* test_autoUpdatePrefPersistance() {
}
});
-function createMockPluginFilesIfNeeded(aFile, aPluginId) {
- function createFile(aFileName) {
- let f = aFile.clone();
- f.append(aFileName);
- if (!f.exists()) {
- f.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
- }
- }
-
- let id = aPluginId.substring(4);
- let libName = AppConstants.DLL_PREFIX + id + AppConstants.DLL_SUFFIX;
-
- createFile(libName);
- if (aPluginId == "gmp-widevinecdm") {
- 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).indexOf(element) != -1;
- }
-}
-
add_task(function* test_pluginRegistration() {
const TEST_VERSION = "1.2.3.4";
- let profD = do_get_profile();
for (let addon of gMockAddons.values()) {
- let file = profD.clone();
+ let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
file.append(addon.id);
file.append(TEST_VERSION);
@@ -273,58 +229,18 @@ add_task(function* test_pluginRegistration() {
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);
- }
- },
+ addPluginDirectory: path => addedPaths.push(path),
+ removePluginDirectory: path => removedPaths.push(path),
+ removeAndDeletePluginDirectory: path => removedPaths.push(path),
};
- GMPScope.gmpService = MockGMPService;
+ GMPScope.gmpService = MockGMPService;
gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), true);
- // Test that plugin registration fails if the plugin dynamic library and
- // info files are not present.
+ // Check that the plugin gets registered after startup.
gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
- TEST_VERSION);
- clearPaths();
- yield promiseRestartManager();
- Assert.equal(addedPaths.indexOf(file.path), -1);
- Assert.deepEqual(removedPaths, [file.path]);
-
- // Create dummy GMP library/info files, and test that plugin registration
- // succeeds during startup, now that we've added GMP info/lib files.
- createMockPluginFilesIfNeeded(file, addon.id);
-
- gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
- TEST_VERSION);
- clearPaths();
- yield promiseRestartManager();
- Assert.notEqual(addedPaths.indexOf(file.path), -1);
- Assert.deepEqual(removedPaths, []);
-
- // 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), "invalid-ABI");
- yield promiseRestartManager();
- Assert.equal(addedPaths.indexOf(file.path), -1);
- Assert.deepEqual(removedPaths, [file.path]);
-
- // Setting the ABI to expected ABI should cause registration at startup.
+ TEST_VERSION);
clearPaths();
- gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
- TEST_VERSION);
- gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ABI, addon.id), UpdateUtils.ABI);
yield promiseRestartManager();
Assert.notEqual(addedPaths.indexOf(file.path), -1);
Assert.deepEqual(removedPaths, []);
@@ -343,7 +259,7 @@ add_task(function* test_pluginRegistration() {
// Changing the pref mid-session should cause unregistration and registration.
gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
- TEST_VERSION);
+ TEST_VERSION);
clearPaths();
const TEST_VERSION_2 = "5.6.7.8";
let file2 = Services.dirsvc.get("ProfD", Ci.nsIFile);
@@ -356,7 +272,7 @@ add_task(function* test_pluginRegistration() {
// Disabling the plugin should cause unregistration.
gPrefs.setCharPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_VERSION, addon.id),
- TEST_VERSION);
+ TEST_VERSION);
clearPaths();
gPrefs.setBoolPref(gGetKey(GMPScope.GMPPrefs.KEY_PLUGIN_ENABLED, addon.id), false);
Assert.deepEqual(addedPaths, []);