зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1042161 - Handle OpenH264 updates for long-running sessions. r=unfocused
This commit is contained in:
Родитель
8892b984f2
Коммит
b4478212a5
|
@ -18,13 +18,14 @@ Cu.import("resource://gre/modules/osfile.jsm");
|
|||
Cu.import("resource://gre/modules/Log.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
|
||||
//Cu.import("resource://gre/modules/GMPInstallManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "GMPInstallManager",
|
||||
"resource://gre/modules/GMPInstallManager.jsm");
|
||||
|
||||
const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties";
|
||||
const STRING_TYPE_NAME = "type.%ID%.name";
|
||||
|
||||
const SEC_IN_A_DAY = 24 * 60 * 60;
|
||||
|
||||
const OPENH264_PLUGIN_ID = "gmp-gmpopenh264";
|
||||
const OPENH264_PREF_BRANCH = "media." + OPENH264_PLUGIN_ID + ".";
|
||||
const OPENH264_PREF_ENABLED = "enabled";
|
||||
|
@ -39,6 +40,8 @@ const OPENH264_PREF_LOGGING_DUMP = OPENH264_PREF_LOGGING + ".dump"; // media.gmp
|
|||
const OPENH264_HOMEPAGE_URL = "http://www.openh264.org/";
|
||||
const OPENH264_OPTIONS_URL = "chrome://mozapps/content/extensions/openH264Prefs.xul";
|
||||
|
||||
const GMP_PREF_LASTCHECK = "media.gmp-manager.lastCheck";
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "pluginsBundle",
|
||||
() => Services.strings.createBundle("chrome://global/locale/plugins.properties"));
|
||||
XPCOMUtils.defineLazyGetter(this, "prefs",
|
||||
|
@ -172,9 +175,24 @@ let OpenH264Wrapper = {
|
|||
|
||||
AddonManagerPrivate.callNoUpdateListeners(this, aListener);
|
||||
|
||||
if (aReason !== AddonManager.UPDATE_WHEN_USER_REQUESTED ||
|
||||
this._updateTask !== null) {
|
||||
return;
|
||||
if (this._updateTask !== null) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (aReason === AddonManager.UPDATE_WHEN_PERIODIC_UPDATE) {
|
||||
if (!AddonManager.shouldAutoUpdate(this)) {
|
||||
this._log.trace("findUpdates() - no autoupdate");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
let secSinceLastCheck = Date.now() / 1000 - Preferences.get(GMP_PREF_LASTCHECK, 0);
|
||||
if (secSinceLastCheck <= SEC_IN_A_DAY) {
|
||||
this._log.trace("findUpdates() - last check was less then a day ago");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
} else if (aReason !== AddonManager.UPDATE_WHEN_USER_REQUESTED) {
|
||||
this._log.trace("findUpdates() - unsupported reason");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
this._updateTask = Task.spawn(function* OpenH264Provider_updateTask() {
|
||||
|
@ -192,8 +210,11 @@ let OpenH264Wrapper = {
|
|||
throw e;
|
||||
} finally {
|
||||
this._updateTask = null;
|
||||
return true;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
return this._updateTask;
|
||||
},
|
||||
|
||||
get pluginMimeTypes() { return []; },
|
||||
|
|
|
@ -15,11 +15,32 @@ const OPENH264_PREF_AUTOUPDATE = OPENH264_PREF_BRANCH + "autoupdate";
|
|||
const PREF_LOGGING = OPENH264_PREF_BRANCH + "provider.logging";
|
||||
const PREF_LOGGING_LEVEL = PREF_LOGGING + ".level";
|
||||
const PREF_LOGGING_DUMP = PREF_LOGGING + ".dump";
|
||||
const GMP_PREF_LASTCHECK = "media.gmp-manager.lastCheck";
|
||||
const SEC_IN_A_DAY = 24 * 60 * 60;
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "pluginsBundle",
|
||||
() => Services.strings.createBundle("chrome://global/locale/plugins.properties"));
|
||||
|
||||
let gProfileDir = null;
|
||||
let MockGMPAddon = Object.freeze({
|
||||
id: OPENH264_PLUGIN_ID,
|
||||
isOpenH264: true,
|
||||
isInstalled: false,
|
||||
});
|
||||
|
||||
let gInstalledAddonId = "";
|
||||
|
||||
function MockGMPInstallManager() {
|
||||
}
|
||||
|
||||
MockGMPInstallManager.prototype = {
|
||||
checkForAddons: () => Promise.resolve([MockGMPAddon]),
|
||||
|
||||
installAddon: addon => {
|
||||
gInstalledAddonId = addon.id;
|
||||
return Promise.resolve();
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
function run_test() {
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
|
@ -218,3 +239,35 @@ add_task(function* test_pluginRegistration() {
|
|||
Assert.equal(addedPath, file.path);
|
||||
Assert.equal(removedPath, null);
|
||||
});
|
||||
|
||||
add_task(function* test_periodicUpdate() {
|
||||
let OpenH264Scope = Cu.import("resource://gre/modules/addons/OpenH264Provider.jsm");
|
||||
Object.defineProperty(OpenH264Scope, "GMPInstallManager", {
|
||||
value: MockGMPInstallManager,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Services.prefs.clearUserPref(OPENH264_PREF_AUTOUPDATE);
|
||||
let addons = yield promiseAddonsByIDs([OPENH264_PLUGIN_ID]);
|
||||
let prefs = Services.prefs;
|
||||
Assert.equal(addons.length, 1);
|
||||
let addon = addons[0];
|
||||
|
||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
|
||||
Services.prefs.setIntPref(GMP_PREF_LASTCHECK, 0);
|
||||
let result = yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
Assert.strictEqual(result, false);
|
||||
|
||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
|
||||
Services.prefs.setIntPref(GMP_PREF_LASTCHECK, Date.now() / 1000 - 60);
|
||||
result = yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
Assert.strictEqual(result, false);
|
||||
|
||||
Services.prefs.setIntPref(GMP_PREF_LASTCHECK, Date.now() / 1000 - 2 * SEC_IN_A_DAY);
|
||||
gInstalledAddonId = "";
|
||||
result = yield addon.findUpdates({}, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE);
|
||||
Assert.strictEqual(result, true);
|
||||
Assert.equal(gInstalledAddonId, OPENH264_PLUGIN_ID);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче