Backed out 7 changesets (bug 1353074) for crashes in test_accessiblecaret_selection_mode.py
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 06 Apr 2017 22:11:45 -0700
changeset 558325 7c7029cf53f5cdb061d7e0abc087852de663c76a
parent 558324 b691dd46057bd1b939f85afa0ea07b05b2888910
child 558326 07435005e74ae597b15f393e15a77e0bc132c07f
push id52860
push userbmo:walkingice0204@gmail.com
push dateFri, 07 Apr 2017 13:29:26 +0000
bugs1353074
milestone55.0a1
backs out0c075043bc43c7d312d7d7147ff4ea4f9aa71b2b
001f220710a211db655f98aa08b40d7b5911e4fc
9c1ca76fba9b8011a0349bbaff8ee09682734819
8dcd190a0a593331f0754cd00111e5c5a44cb6c2
23409efe536f0e06b74dd4fd69c3a3a620d33e57
8112153e07938722d989d6079d0e98ca3cedbac4
2670eec1ed8ab10cb44c7010d996fa28af565442
Backed out 7 changesets (bug 1353074) for crashes in test_accessiblecaret_selection_mode.py Backed out changeset 0c075043bc43 (bug 1353074) Backed out changeset 001f220710a2 (bug 1353074) Backed out changeset 9c1ca76fba9b (bug 1353074) Backed out changeset 8dcd190a0a59 (bug 1353074) Backed out changeset 23409efe536f (bug 1353074) Backed out changeset 8112153e0793 (bug 1353074) Backed out changeset 2670eec1ed8a (bug 1353074)
testing/marionette/evaluate.js
testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
--- a/testing/marionette/evaluate.js
+++ b/testing/marionette/evaluate.js
@@ -100,19 +100,18 @@ this.evaluate = {};
  */
 evaluate.sandbox = function (sb, script, args = [], opts = {}) {
   let scriptTimeoutID, timeoutHandler, unloadHandler;
 
   let promise = new Promise((resolve, reject) => {
     let src = "";
     sb[COMPLETE] = resolve;
     timeoutHandler = () => reject(new ScriptTimeoutError("Timed out"));
-    unloadHandler = sandbox.cloneInto(
-        () => reject(new JavaScriptError("Document was unloaded during execution")),
-        sb);
+    unloadHandler = () => reject(
+        new JavaScriptError("Document was unloaded during execution"));
 
     // wrap in function
     if (!opts.directInject) {
       if (opts.async) {
         sb[CALLBACK] = sb[COMPLETE];
       }
       sb[ARGUMENTS] = sandbox.cloneInto(args, sb);
 
@@ -141,17 +140,17 @@ evaluate.sandbox = function (sb, script,
       sb.window.onerror = (msg, url, line) => {
         let err = new JavaScriptError(`${msg} at ${url}:${line}`);
         reject(err);
       };
     }
 
     // timeout and unload handlers
     scriptTimeoutID = setTimeout(timeoutHandler, opts.timeout || DEFAULT_TIMEOUT);
-    sb.window.addEventListener("unload", unloadHandler);
+    sb.window.onunload = sandbox.cloneInto(unloadHandler, sb);
 
     let res;
     try {
       res = Cu.evalInSandbox(src, sb, "1.8", opts.filename || "dummy file", 0);
     } catch (e) {
       let err = new JavaScriptError(
           e,
           "execute_script",
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_execute_script.py
@@ -87,92 +87,70 @@ class TestExecuteContent(MarionetteTestC
         self.assertEqual(
             {"foo": {"bar": [1, 2]}},
             self.marionette.execute_script("return {foo: {bar: [1, 2]}}"))
 
     def test_no_return_value(self):
         self.assertIsNone(self.marionette.execute_script("true"))
 
     def test_argument_null(self):
-        self.assertIsNone(self.marionette.execute_script(
-            "return arguments[0]",
-            script_args=(None,),
-            sandbox="default"))
-        self.assertIsNone(self.marionette.execute_script(
-            "return arguments[0]",
-            script_args=(None,),
-            sandbox="system"))
-        self.assertIsNone(self.marionette.execute_script(
-            "return arguments[0]",
-            script_args=(None,),
-            sandbox=None))
+        self.assertIsNone(self.marionette.execute_script("return arguments[0]", [None]))
 
     def test_argument_number(self):
         self.assertEqual(
-            1, self.marionette.execute_script("return arguments[0]", (1,)))
+            1, self.marionette.execute_script("return arguments[0]", [1]))
         self.assertEqual(
-            1.5, self.marionette.execute_script("return arguments[0]", (1.5,)))
+            1.5, self.marionette.execute_script("return arguments[0]", [1.5]))
 
     def test_argument_boolean(self):
-        self.assertTrue(self.marionette.execute_script("return arguments[0]", (True,)))
+        self.assertTrue(self.marionette.execute_script("return arguments[0]", [True]))
 
     def test_argument_string(self):
         self.assertEqual(
-            "foo", self.marionette.execute_script("return arguments[0]", ("foo",)))
+            "foo", self.marionette.execute_script("return arguments[0]", ["foo"]))
 
     def test_argument_array(self):
         self.assertEqual(
-            [1, 2], self.marionette.execute_script("return arguments[0]", ([1, 2],)))
+            [1, 2], self.marionette.execute_script("return arguments[0]", [[1, 2]]))
 
     def test_argument_object(self):
         self.assertEqual({"foo": 1}, self.marionette.execute_script(
-            "return arguments[0]", ({"foo": 1},)))
+            "return arguments[0]", [{"foo": 1}]))
 
-    def test_default_sandbox_globals(self):
+    def test_globals(self):
         for property in globals:
-            self.assert_is_defined(property, sandbox="default")
-
+            self.assert_is_defined(property)
         self.assert_is_defined("Components")
         self.assert_is_defined("window.wrappedJSObject")
 
     def test_system_globals(self):
         for property in globals:
             self.assert_is_defined(property, sandbox="system")
-
         self.assert_is_defined("Components", sandbox="system")
-        self.assert_is_defined("window.wrappedJSObject", sandbox="system")
-
-    def test_mutable_sandbox_globals(self):
-        for property in globals:
-            self.assert_is_defined(property, sandbox=None)
-
-        # Components is there, but will be removed soon
-        self.assert_is_defined("Components", sandbox=None)
-        # wrappedJSObject is always there in sandboxes
-        self.assert_is_defined("window.wrappedJSObject", sandbox=None)
+        self.assert_is_defined("window.wrappedJSObject")
 
     def test_exception(self):
         self.assertRaises(errors.JavascriptException,
                           self.marionette.execute_script, "return foo")
 
     def test_stacktrace(self):
         with self.assertRaises(errors.JavascriptException) as cm:
             self.marionette.execute_script("return b")
 
         # by default execute_script pass the name of the python file
         self.assertIn(os.path.basename(__file__.replace(".pyc", ".py")),
                       cm.exception.stacktrace)
         self.assertIn("b is not defined", cm.exception.message)
         self.assertIn("return b", cm.exception.stacktrace)
 
     def test_permission(self):
-        for sandbox in ["default", None]:
-            with self.assertRaises(errors.JavascriptException):
-               self.marionette.execute_script(
-                    "Components.classes['@mozilla.org/preferences-service;1']")
+        with self.assertRaises(errors.JavascriptException):
+            self.marionette.execute_script("""
+                var c = Components.classes["@mozilla.org/preferences-service;1"];
+            """)
 
     def test_return_web_element(self):
         self.marionette.navigate(elements)
         expected = self.marionette.find_element(By.TAG_NAME, "p")
         actual = self.marionette.execute_script(
             "return document.querySelector('p')")
         self.assertEqual(expected, actual)
 
@@ -205,44 +183,31 @@ class TestExecuteContent(MarionetteTestC
             "return global.barfoo;", new_sandbox=False), [42, 23])
 
     def test_sandbox_refresh_arguments(self):
         self.marionette.execute_script(
             "this.foobar = [arguments[0], arguments[1]]", [23, 42])
         self.assertEqual(self.marionette.execute_script(
             "return this.foobar", new_sandbox=False), [23, 42])
 
-    def test_mutable_sandbox_wrappedjsobject(self):
-        self.assert_is_defined("window.wrappedJSObject")
-        with self.assertRaises(errors.JavascriptException):
-            self.marionette.execute_script("window.wrappedJSObject.foo = 1", sandbox=None)
-
-    def test_default_sandbox_wrappedjsobject(self):
-        self.assert_is_defined("window.wrappedJSObject", sandbox="default")
-
+    def test_wrappedjsobject(self):
         try:
-            self.marionette.execute_script(
-                "window.wrappedJSObject.foo = 4", sandbox="default")
-            self.assertEqual(self.marionette.execute_script(
-                "return window.wrappedJSObject.foo", sandbox="default"), 4)
+            self.marionette.execute_script("window.wrappedJSObject.foo = 3")
+            self.assertEqual(
+                self.marionette.execute_script("return window.wrappedJSObject.foo"), 3)
         finally:
-            self.marionette.execute_script(
-                "delete window.wrappedJSObject.foo", sandbox="default")
+            self.marionette.execute_script("delete window.wrappedJSObject.foo")
 
     def test_system_sandbox_wrappedjsobject(self):
-        self.assert_is_defined("window.wrappedJSObject", sandbox="system")
-
         self.marionette.execute_script(
             "window.wrappedJSObject.foo = 4", sandbox="system")
         self.assertEqual(self.marionette.execute_script(
             "return window.wrappedJSObject.foo", sandbox="system"), 4)
 
     def test_system_dead_object(self):
-        self.assert_is_defined("window.wrappedJSObject", sandbox="system")
-
         self.marionette.execute_script(
             "window.wrappedJSObject.foo = function() { return 'yo' }",
             sandbox="system")
         self.marionette.execute_script(
             "dump(window.wrappedJSObject.foo)", sandbox="system")
 
         self.marionette.execute_script(
             "window.wrappedJSObject.foo = function() { return 'yolo' }",
@@ -293,63 +258,41 @@ class TestExecuteContent(MarionetteTestC
             "return window.n", sandbox=None),
             "setTimeout already fired")
 
         # if event was cancelled, this will time out
         Wait(self.marionette, timeout=8).until(
             content_timeout_triggered,
             message="Scheduled setTimeout event was cancelled by call to execute_script")
 
-    def test_access_chrome_objects_in_event_listeners(self):
-        # sandbox.window.addEventListener/removeEventListener
-        # is used by Marionette for installing the unloadHandler which
-        # is used to return an error when a document is unloaded during
-        # script execution.
-        #
-        # Certain web frameworks, notably Angular, override
-        # window.addEventListener/removeEventListener and introspects
-        # objects passed to them.  If these objects originates from chrome
-        # without having been cloned, a permission denied error is thrown
-        # as part of the security precautions put in place by the sandbox.
-
-        # addEventListener is called when script is injected
+    def test_privileged_code_inspection(self):
+        # test permission denied on toString of unload event handler
         self.marionette.navigate(inline("""
             <script>
-            window.addEventListener = (event, listener) => listener.toString();
-            </script>
-            """))
+            window.addEventListener = (type, handler) => handler.toString();
+            </script>"""))
         self.marionette.execute_script("", sandbox=None)
 
-        # removeEventListener is called when sandbox is unloaded
-        self.marionette.navigate(inline("""
-            <script>
-            window.removeEventListener = (event, listener) => listener.toString();
-            </script>
-            """))
-        self.marionette.execute_script("", sandbox=None)
-
-    def test_access_global_objects_from_chrome(self):
         # test inspection of arguments
         self.marionette.execute_script("__webDriverArguments.toString()")
 
 
-
 class TestExecuteChrome(WindowManagerMixin, TestExecuteContent):
 
     def setUp(self):
         super(TestExecuteChrome, self).setUp()
 
         self.marionette.set_context("chrome")
 
     def tearDown(self):
         super(TestExecuteChrome, self).tearDown()
 
     def test_permission(self):
-        self.marionette.execute_script(
-            "Components.classes['@mozilla.org/preferences-service;1']")
+        self.assertEqual(1, self.marionette.execute_script("""
+            var c = Components.classes["@mozilla.org/preferences-service;1"]; return 1;"""))
 
     @skip_if_mobile("New windows not supported in Fennec")
     def test_unmarshal_element_collection(self):
 
         def open_window_with_js():
             self.marionette.execute_script(
                 "window.open('chrome://marionette/content/test.xul', 'xul', 'chrome');")
 
@@ -382,26 +325,17 @@ class TestExecuteChrome(WindowManagerMix
         pass
 
     def test_return_web_element_nodelist(self):
         pass
 
     def test_window_set_timeout_is_not_cancelled(self):
         pass
 
-    def test_mutable_sandbox_wrappedjsobject(self):
-        pass
-
-    def test_default_sandbox_wrappedjsobject(self):
-        pass
-
-    def test_system_sandbox_wrappedjsobject(self):
-        pass
-
-    def test_access_chrome_objects_in_event_listeners(self):
+    def test_privileged_code_inspection(self):
         pass
 
 
 class TestElementCollections(MarionetteTestCase):
 
     def assertSequenceIsInstance(self, seq, typ):
         for item in seq:
             self.assertIsInstance(item, typ)