Bug 641685 - [e10s] Make setTestPluginEnabledState work in content processes (r=bsmedberg)
authorBill McCloskey <wmccloskey@mozilla.com>
Wed, 29 Oct 2014 08:04:51 -0700
changeset 212883 55310850248c649cbfc0c101d998b2c3a0837e7d
parent 212882 5e6215461462eeaed579a3742de2d225306e00f7
child 212884 ee7994387e65177c8bac2c4541f4dd75d81bdcb7
push id51079
push userwmccloskey@mozilla.com
push dateWed, 29 Oct 2014 15:05:53 +0000
treeherdermozilla-inbound@0f7fd7a22708 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs641685
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 641685 - [e10s] Make setTestPluginEnabledState work in content processes (r=bsmedberg)
dom/plugins/test/mochitest/utils.js
testing/specialpowers/components/SpecialPowersObserver.js
testing/specialpowers/content/SpecialPowersObserverAPI.js
testing/specialpowers/content/specialpowersAPI.js
--- a/dom/plugins/test/mochitest/utils.js
+++ b/dom/plugins/test/mochitest/utils.js
@@ -30,21 +30,29 @@ function getTestPlugin(pluginName) {
   ok(false, "Could not find plugin tag with plugin name '" + name + "'");
   return null;
 }
 
 // call this to set the test plugin(s) initially expected enabled state.
 // it will automatically be reset to it's previous value after the test
 // ends
 function setTestPluginEnabledState(newEnabledState, pluginName) {
+  var oldEnabledState = SpecialPowers.setTestPluginEnabledState(newEnabledState, pluginName);
+  if (!oldEnabledState) {
+    ok(false, "Cannot find plugin '" + plugin + "'");
+    return;
+  }
   var plugin = getTestPlugin(pluginName);
-  var oldEnabledState = plugin.enabledState;
-  plugin.enabledState = newEnabledState;
+  while (plugin.enabledState != newEnabledState) {
+    // Run a nested event loop to wait for the preference change to
+    // propagate to the child. Yuck!
+    SpecialPowers.Services.tm.currentThread.processNextEvent(true);
+  }
   SimpleTest.registerCleanupFunction(function() {
-    getTestPlugin(pluginName).enabledState = oldEnabledState;
+    SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
   });
 }
 
 function crashAndGetCrashServiceRecord(crashMethodName, callback) {
   var crashMan =
     SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").
     Services.crashmanager;
 
--- a/testing/specialpowers/components/SpecialPowersObserver.js
+++ b/testing/specialpowers/components/SpecialPowersObserver.js
@@ -80,16 +80,17 @@ SpecialPowersObserver.prototype = new Sp
       this._messageManager.addMessageListener("SpecialPowers.Quit", this);
       this._messageManager.addMessageListener("SpecialPowers.Focus", this);
       this._messageManager.addMessageListener("SPPermissionManager", this);
       this._messageManager.addMessageListener("SPWebAppService", this);
       this._messageManager.addMessageListener("SPObserverService", this);
       this._messageManager.addMessageListener("SPLoadChromeScript", this);
       this._messageManager.addMessageListener("SPChromeScriptMessage", this);
       this._messageManager.addMessageListener("SPQuotaManager", this);
+      this._messageManager.addMessageListener("SPSetTestPluginEnabledState", this);
 
       this._messageManager.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
       this._messageManager.loadFrameScript(CHILD_SCRIPT_API, true);
       this._messageManager.loadFrameScript(CHILD_SCRIPT, true);
       this._isFrameScriptLoaded = true;
     }
   };
 
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -62,16 +62,30 @@ function parseKeyValuePairsFromFile(file
   while (is.readString(4096, str) != 0) {
     contents += str.value;
   }
   is.close();
   fstream.close();
   return parseKeyValuePairs(contents);
 }
 
+function getTestPlugin(pluginName) {
+  var ph = Cc["@mozilla.org/plugin/host;1"]
+    .getService(Ci.nsIPluginHost);
+  var tags = ph.getPluginTags();
+  var name = pluginName || "Test Plug-in";
+  for (var tag of tags) {
+    if (tag.name == name) {
+      return tag;
+    }
+  }
+
+  return null;
+}
+
 SpecialPowersObserverAPI.prototype = {
 
   _observe: function(aSubject, aTopic, aData) {
     function addDumpIDToMessage(propertyName) {
       try {
         var id = aSubject.getPropertyAsAString(propertyName);
       } catch(ex) {
         var id = null;
@@ -316,16 +330,26 @@ SpecialPowersObserverAPI.prototype = {
             break;
           default:
             throw new SpecialPowersException("Invalid operation for " +
                                              "SPPermissionManager");
         }
         return undefined;	// See comment at the beginning of this function.
       }
 
+      case "SPSetTestPluginEnabledState": {
+        var plugin = getTestPlugin(aMessage.data.pluginName);
+        if (!plugin) {
+          return undefined;
+        }
+        var oldEnabledState = plugin.enabledState;
+        plugin.enabledState = aMessage.data.newEnabledState;
+        return oldEnabledState;
+      }
+
       case "SPWebAppService": {
         let Webapps = {};
         Components.utils.import("resource://gre/modules/Webapps.jsm", Webapps);
         switch (aMessage.json.op) {
           case "set-launchable":
             let val = Webapps.DOMApplicationRegistry.allAppsLaunchable;
             Webapps.DOMApplicationRegistry.allAppsLaunchable = aMessage.json.launchable;
             return val;
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -841,16 +841,22 @@ SpecialPowersAPI.prototype = {
   flushPermissions: function(callback) {
     while (this._permissionsUndoStack.length > 1)
       this.popPermissions(null);
 
     this.popPermissions(callback);
   },
 
 
+  setTestPluginEnabledState: function(newEnabledState, pluginName) {
+    return this._sendSyncMessage("SPSetTestPluginEnabledState",
+                                 { newEnabledState: newEnabledState, pluginName: pluginName })[0];
+  },
+
+
   _permissionObserver: {
     _self: null,
     _lastPermission: {},
     _callBack: null,
     _nextCallback: null,
 
     observe: function (aSubject, aTopic, aData)
     {