Bug 641685 - [e10s] Make setTestPluginEnabledState work in content processes (r=bsmedberg)

This commit is contained in:
Bill McCloskey 2014-10-29 08:04:51 -07:00
parent 6c6c1250f3
commit a56e2dcc60
4 changed files with 42 additions and 3 deletions

View File

@ -35,11 +35,19 @@ function getTestPlugin(pluginName) {
// 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);
});
}

View File

@ -85,6 +85,7 @@ SpecialPowersObserver.prototype = new SpecialPowersObserverAPI();
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);

View File

@ -67,6 +67,20 @@ function parseKeyValuePairsFromFile(file) {
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) {
@ -321,6 +335,16 @@ SpecialPowersObserverAPI.prototype = {
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);

View File

@ -846,6 +846,12 @@ SpecialPowersAPI.prototype = {
},
setTestPluginEnabledState: function(newEnabledState, pluginName) {
return this._sendSyncMessage("SPSetTestPluginEnabledState",
{ newEnabledState: newEnabledState, pluginName: pluginName })[0];
},
_permissionObserver: {
_self: null,
_lastPermission: {},