Bug 1007062 - Fix SpecialPower API doesn't work on Marionette test-container. r=mdas,jmaher

This commit is contained in:
Edgar Chen 2014-09-28 22:43:32 +08:00
parent 5a257b83f9
commit 8268a0954a
6 changed files with 57 additions and 39 deletions

View File

@ -9,6 +9,7 @@ var NotificationTest = (function () {
SimpleTest.waitForExplicitFinish();
// turn on testing pref (used by notification.cpp, and mock the alerts
SpecialPowers.setBoolPref("notification.prompt.testing", true);
SpecialPowers.setAllAppsLaunchable(true);
}
function teardown_testing_env() {

View File

@ -2,7 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from marionette_test import MarionetteTestCase, skip_if_b2g
from marionette_test import MarionetteTestCase
from errors import JavascriptException, MarionetteException
class TestSpecialPowersContent(MarionetteTestCase):
@ -10,8 +10,6 @@ class TestSpecialPowersContent(MarionetteTestCase):
testpref = "testing.marionette.contentcharpref"
testvalue = "blabla"
# fails in b2g's test-container: "Error getting pref", Bug 1060061
@skip_if_b2g
def test_prefs(self):
result = self.marionette.execute_script("""
SpecialPowers.setCharPref("%(pref)s", "%(value)s");

View File

@ -13,6 +13,12 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Log.jsm");
let logger = Log.repository.getLogger("Marionette");
let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader);
let specialpowers = {};
loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
specialpowers);
//list of OOP frames that has the frame script loaded
let remoteFrames = [];
@ -121,6 +127,11 @@ FrameManager.prototype = {
if (frameMessageManager == mm) {
this.currentRemoteFrame = frame;
this.addMessageManagerListeners(mm);
if (!frame.specialPowersObserver) {
frame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
frame.specialPowersObserver.init(mm);
}
mm.sendAsyncMessage("Marionette:restart", {});
return;
}
@ -135,6 +146,9 @@ FrameManager.prototype = {
aFrame.messageManager = Cu.getWeakReference(mm);
remoteFrames.push(aFrame);
this.currentRemoteFrame = aFrame;
aFrame.specialPowersObserver = new specialpowers.SpecialPowersObserver();
aFrame.specialPowersObserver.init(mm);
},
/*
@ -150,6 +164,20 @@ FrameManager.prototype = {
this.handledModal = false;
},
/**
* This function removes any SpecialPowersObservers from OOP frames.
*/
removeSpecialPowers: function FM_removeSpecialPowers() {
for (let i = 0; i < remoteFrames.length; i++) {
let frame = remoteFrames[i];
if (frame.specialPowersObserver) {
frame.specialPowersObserver.uninit();
frame.specialPowersObserver = null;
}
}
},
/**
* Adds message listeners to the server, listening for messages from content frame scripts.
* It also adds a "MarionetteFrame:getInterruptedState" message listener to the FrameManager,

View File

@ -2215,6 +2215,7 @@ MarionetteServerConnection.prototype = {
while (winEnum.hasMoreElements()) {
winEnum.getNext().messageManager.removeDelayedFrameScript(FRAME_SCRIPT);
}
this.curBrowser.frameManager.removeSpecialPowers();
this.curBrowser.frameManager.removeMessageManagerListeners(this.globalMessageManager);
}
this.switchToGlobalMessageManager();

View File

@ -75,21 +75,6 @@ if (outOfProcess) {
let mm = container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
specialPowersObserver.init(mm);
mm.addMessageListener("SPPrefService", specialPowersObserver);
mm.addMessageListener("SPProcessCrashService", specialPowersObserver);
mm.addMessageListener("SPPingService", specialPowersObserver);
mm.addMessageListener("SpecialPowers.Quit", specialPowersObserver);
mm.addMessageListener("SpecialPowers.Focus", specialPowersObserver);
mm.addMessageListener("SPPermissionManager", specialPowersObserver);
mm.addMessageListener("SPObserverService", specialPowersObserver);
mm.addMessageListener("SPLoadChromeScript", specialPowersObserver);
mm.addMessageListener("SPChromeScriptMessage", specialPowersObserver);
mm.addMessageListener("SPQuotaManager", specialPowersObserver);
mm.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
mm.loadFrameScript(CHILD_SCRIPT_API, true);
mm.loadFrameScript(CHILD_SCRIPT, true);
//Workaround for bug 848411, once that bug is fixed, the following line can be removed
function contentScript() {
addEventListener("DOMWindowCreated", function listener(e) {
@ -99,8 +84,6 @@ if (outOfProcess) {
});
}
mm.loadFrameScript("data:,(" + encodeURI(contentScript.toSource()) + ")();", true);
specialPowersObserver._isFrameScriptLoaded = true;
}

View File

@ -50,25 +50,7 @@ SpecialPowersObserver.prototype = new SpecialPowersObserverAPI();
break;
case "chrome-document-global-created":
if (!this._isFrameScriptLoaded) {
// Register for any messages our API needs us to handle
this._messageManager.addMessageListener("SPPrefService", this);
this._messageManager.addMessageListener("SPProcessCrashService", this);
this._messageManager.addMessageListener("SPPingService", this);
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.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
this._messageManager.loadFrameScript(CHILD_SCRIPT_API, true);
this._messageManager.loadFrameScript(CHILD_SCRIPT, true);
this._isFrameScriptLoaded = true;
}
this._loadFrameScript();
break;
case "http-on-modify-request":
@ -88,6 +70,29 @@ SpecialPowersObserver.prototype = new SpecialPowersObserverAPI();
}
};
SpecialPowersObserver.prototype._loadFrameScript = function()
{
if (!this._isFrameScriptLoaded) {
// Register for any messages our API needs us to handle
this._messageManager.addMessageListener("SPPrefService", this);
this._messageManager.addMessageListener("SPProcessCrashService", this);
this._messageManager.addMessageListener("SPPingService", this);
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.loadFrameScript(CHILD_LOGGER_SCRIPT, true);
this._messageManager.loadFrameScript(CHILD_SCRIPT_API, true);
this._messageManager.loadFrameScript(CHILD_SCRIPT, true);
this._isFrameScriptLoaded = true;
}
};
SpecialPowersObserver.prototype._sendAsyncMessage = function(msgname, msg)
{
if (this._mmIsGlobal) {
@ -112,6 +117,8 @@ SpecialPowersObserver.prototype = new SpecialPowersObserverAPI();
if (messageManager) {
this._messageManager = messageManager;
this._mmIsGlobal = false;
this._loadFrameScript();
}
};