Bug 754178 - Expose SpecialPowers in Marionette content JS. r=jgriffin
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Fri, 18 May 2012 13:30:13 -0700
changeset 94359 921706236f86b85e1df48757963ddc87a98d0cb9
parent 94358 cc0b4c5c3ac2609ba7926ef13ede6585ef263d4e
child 94360 9dab33fa5ff4aecbc36dfd6c09027fee897cf05e
push idunknown
push userunknown
push dateunknown
reviewersjgriffin
bugs754178
milestone15.0a1
Bug 754178 - Expose SpecialPowers in Marionette content JS. r=jgriffin
testing/marionette/client/marionette/tests/unit/test_specialpowers.py
testing/marionette/jar.mn
testing/marionette/marionette-actors.js
testing/marionette/marionette-listener.js
--- a/testing/marionette/client/marionette/tests/unit/test_specialpowers.py
+++ b/testing/marionette/client/marionette/tests/unit/test_specialpowers.py
@@ -1,16 +1,35 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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
 from errors import JavascriptException, MarionetteException
 
-class TestSpecialPowers(MarionetteTestCase):
+class TestSpecialPowersContent(MarionetteTestCase):
+
+    testpref = "testing.marionette.contentcharpref"
+    testvalue = "blabla"
 
     def test_prefs(self):
+        result = self.marionette.execute_script("""
+        SpecialPowers.setCharPref("%(pref)s", "%(value)s");
+        return SpecialPowers.getCharPref("%(pref)s")
+        """ % {'pref': self.testpref, 'value': self.testvalue});
+        self.assertEqual(result, self.testvalue)
+
+    def test_prefs_after_navigate(self):
+        test_html = self.marionette.absolute_url("test.html")
+        self.marionette.navigate(test_html)
+        self.test_prefs()
+
+class TestSpecialPowersChrome(TestSpecialPowersContent):
+
+    testpref = "testing.marionette.chromecharpref"
+    testvalue = "blabla"
+
+    def setUp(self):
+        super(TestSpecialPowersChrome, self).setUp()
         self.marionette.set_context("chrome")
-        result = self.marionette.execute_script("""
-        SpecialPowers.setCharPref("testing.marionette.charpref", "blabla");
-        return SpecialPowers.getCharPref("testing.marionette.charpref")
-        """);
-        self.assertEqual(result, "blabla")
+
+    def test_prefs_after_navigate(self):
+        pass
--- a/testing/marionette/jar.mn
+++ b/testing/marionette/jar.mn
@@ -5,14 +5,16 @@ marionette.jar:
   content/marionette-elements.js    (marionette-elements.js)
   content/marionette-log-obj.js     (marionette-log-obj.js)
   content/marionette-simpletest.js  (marionette-simpletest.js)
   content/EventUtils.js  (EventUtils.js)
   content/ChromeUtils.js  (ChromeUtils.js)
 
 % content specialpowers %content/
   content/specialpowers.js (../mochitest/specialpowers/content/specialpowers.js)
+  content/SpecialPowersObserver.js (../mochitest/specialpowers/components/SpecialPowersObserver.js)
   content/specialpowersAPI.js (../mochitest/tests/SimpleTest/specialpowersAPI.js)
   content/SpecialPowersObserverAPI.js (../mochitest/tests/SimpleTest/SpecialPowersObserverAPI.js)
   content/ChromePowers.js (../mochitest/tests/SimpleTest/ChromePowers.js)
+  content/MozillaLogger.js (../mochitest/tests/SimpleTest/MozillaLogger.js)
 
 % resource mochikit %modules/
   modules/MockFilePicker.jsm (../mochitest/MockFilePicker.jsm)
--- a/testing/marionette/marionette-actors.js
+++ b/testing/marionette/marionette-actors.js
@@ -15,16 +15,22 @@ let loader = Cc["@mozilla.org/moz/jssubs
 loader.loadSubScript("chrome://marionette/content/marionette-simpletest.js");
 loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js");
 Cu.import("chrome://marionette/content/marionette-elements.js");
 let utils = {};
 loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
 loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
 loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
 
+let specialpowers = {};
+loader.loadSubScript("chrome://specialpowers/content/SpecialPowersObserver.js",
+                     specialpowers);
+specialpowers.specialPowersObserver = new specialpowers.SpecialPowersObserver();
+specialpowers.specialPowersObserver.init();
+
 Cu.import("resource://gre/modules/Services.jsm");
 
 Services.prefs.setBoolPref("marionette.contentListener", false);
 let appName = Services.appinfo.name;
 
 // import logger
 Cu.import("resource://gre/modules/services-common/log4moz.js");
 let logger = Log4Moz.repository.getLogger("Marionette");
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -15,16 +15,20 @@ loader.loadSubScript("chrome://marionett
 loader.loadSubScript("chrome://marionette/content/marionette-log-obj.js");
 Cu.import("chrome://marionette/content/marionette-elements.js");
 let utils = {};
 utils.window = content;
 // Load Event/ChromeUtils for use with JS scripts:
 loader.loadSubScript("chrome://marionette/content/EventUtils.js", utils);
 loader.loadSubScript("chrome://marionette/content/ChromeUtils.js", utils);
 loader.loadSubScript("chrome://marionette/content/atoms.js", utils);
+
+loader.loadSubScript("chrome://specialpowers/content/specialpowersAPI.js");
+loader.loadSubScript("chrome://specialpowers/content/specialpowers.js");
+
 let marionetteLogObj = new MarionetteLogObj();
 
 let isB2G = false;
 
 let marionetteTimeout = null;
 let winUtil = content.QueryInterface(Ci.nsIInterfaceRequestor)
                      .getInterface(Ci.nsIDOMWindowUtils);
 let listenerId = null; //unique ID of this listener
@@ -234,16 +238,18 @@ function createExecuteContentSandbox(aWi
   sandbox.testUtils = utils;
 
   let marionette = new Marionette(false, aWindow, "content", marionetteLogObj);
   sandbox.marionette = marionette;
   marionette.exports.forEach(function(fn) {
     sandbox[fn] = marionette[fn].bind(marionette);
   });
 
+  sandbox.SpecialPowers = new SpecialPowers(aWindow);
+
   sandbox.asyncComplete = function sandbox_asyncComplete(value, status) {
     curWindow.removeEventListener("unload", errUnload, false);
 
     /* clear all timeouts potentially generated by the script*/
     for (let i = 0; i <= asyncTestTimeoutId; i++) {
       curWindow.clearTimeout(i);
     }