Bug 1040048 - Register the OpenH264 plugin from the OpenH264Provider on startup. r=bsmedberg
--- a/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
+++ b/toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
@@ -156,16 +156,21 @@ let OpenH264Wrapper = Object.freeze({
},
});
let OpenH264Provider = {
startup: function() {
Services.obs.addObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED, false);
prefs.observe(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this);
prefs.observe(OPENH264_PREF_PATH, this.onPrefPathChanged, this);
+
+ this.gmpPath = prefs.get(OPENH264_PREF_PATH, null);
+ if (this.gmpPath) {
+ gmpService.addPluginDirectory(this.gmpPath);
+ }
},
shutdown: function() {
Services.obs.removeObserver(this, AddonManager.OPTIONS_NOTIFICATION_DISPLAYED);
prefs.ignore(OPENH264_PREF_ENABLED, this.onPrefEnabledChanged, this);
prefs.ignore(OPENH264_PREF_PATH, this.onPrefPathChanged, this);
},
--- a/toolkit/mozapps/extensions/test/xpcshell/test_openh264.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_openh264.js
@@ -1,14 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-const Ci = Components.interfaces;
+const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
const OPENH264_PLUGIN_ID = "openh264-plugin@cisco.com";
const OPENH264_PREF_BRANCH = "media.openh264.";
const OPENH264_PREF_ENABLED = OPENH264_PREF_BRANCH + "enabled";
const OPENH264_PREF_PATH = OPENH264_PREF_BRANCH + "path";
const OPENH264_PREF_VERSION = OPENH264_PREF_BRANCH + "version";
const OPENH264_PREF_LASTUPDATE = OPENH264_PREF_BRANCH + "lastUpdate";
const OPENH264_PREF_AUTOUPDATE = OPENH264_PREF_BRANCH + "autoupdate";
@@ -141,8 +141,54 @@ add_task(function* test_autoUpdatePrefPe
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_ENABLE);
Assert.ok(prefs.getBoolPref(OPENH264_PREF_AUTOUPDATE));
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
Assert.ok(!prefs.prefHasUserValue(OPENH264_PREF_AUTOUPDATE));
});
+
+add_task(function* test_pluginRegistration() {
+ let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
+ file.append("openh264");
+ file.append("testDir");
+
+ let addedPath = null
+ let removedPath = null;
+ let clearPaths = () => addedPath = removedPath = null;
+
+ let MockGMPService = {
+ addPluginDirectory: path => addedPath = path,
+ removePluginDirectory: path => removedPath = path,
+ };
+
+ let OpenH264Scope = Cu.import("resource://gre/modules/addons/OpenH264Provider.jsm");
+ OpenH264Scope.gmpService = MockGMPService;
+
+ // Check that the OpenH264 plugin gets registered after startup.
+ Services.prefs.setCharPref(OPENH264_PREF_PATH, file.path);
+ clearPaths();
+ yield promiseRestartManager();
+ Assert.equal(addedPath, file.path);
+ Assert.equal(removedPath, null);
+
+ // Check that clearing the path doesn't trigger registration.
+ clearPaths();
+ Services.prefs.clearUserPref(OPENH264_PREF_PATH);
+ Assert.equal(addedPath, null);
+ Assert.equal(removedPath, file.path);
+
+ // Restarting with no path set should not trigger registration.
+ clearPaths();
+ yield promiseRestartManager();
+ Assert.equal(addedPath, null);
+ Assert.equal(removedPath, null);
+
+ // Changing the pref mid-session should cause unregistration and registration.
+ Services.prefs.setCharPref(OPENH264_PREF_PATH, file.path);
+ clearPaths();
+ let file2 = file.clone();
+ file2.append("foo");
+ Services.prefs.setCharPref(OPENH264_PREF_PATH, file2.path);
+ Assert.equal(addedPath, file2.path);
+ Assert.equal(removedPath, file.path);
+});