Bug 1040048 - Register the OpenH264 plugin from the OpenH264Provider on startup. r=bsmedberg
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Thu, 17 Jul 2014 17:46:18 +0200
changeset 194622 ad53b74f0bf2bf83e7b0eb7ee2ce9e36f87509ae
parent 194621 dc73c687701debc63f38130b110330435c2bf921
child 194623 91e7ba697b14b450935c0161b23c07aeb93e8f2a
push id7783
push usergeorg.fritzsche@googlemail.com
push dateThu, 17 Jul 2014 15:47:08 +0000
treeherderfx-team@ad53b74f0bf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1040048
milestone33.0a1
Bug 1040048 - Register the OpenH264 plugin from the OpenH264Provider on startup. r=bsmedberg
toolkit/mozapps/extensions/internal/OpenH264Provider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_openh264.js
--- 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);
+});