Bug 722596 - Get stack trace from errors in content frames, r=jgriffin
☠☠ backed out by fd10dfc5f834 ☠ ☠
authorMalini Das <mdas@mozilla.com>
Mon, 17 Dec 2012 16:02:58 -0500
changeset 125419 f5aaf21d0a2b3c9ec6366413d71bf2240be6e96d
parent 125418 167cface3edc21ac607bbf1930fb3226009796d3
child 125420 e75c8b88e65ef138fea48b66520e7e1c40fe8f9a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs722596
milestone20.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 722596 - Get stack trace from errors in content frames, r=jgriffin
testing/marionette/client/marionette/tests/unit/test_switch_frame.py
testing/marionette/marionette-listener.js
--- a/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
+++ b/testing/marionette/client/marionette/tests/unit/test_switch_frame.py
@@ -1,42 +1,46 @@
 # 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/.
 
 import os
 from marionette_test import MarionetteTestCase
+from errors import JavascriptException
+
+# boiler plate for the initial navigation and frame switch
+def switch_to_window_verify(test, start_url, frame, verify_title, verify_url):
+    test.assertTrue(test.marionette.execute_script("window.location.href = 'about:blank'; return true;"))
+    test.assertEqual("about:blank", test.marionette.execute_script("return window.location.href;"))
+    test_html = test.marionette.absolute_url(start_url)
+    test.marionette.navigate(test_html)
+    test.assertNotEqual("about:blank", test.marionette.execute_script("return window.location.href;"))
+    test.assertEqual(verify_title, test.marionette.title)
+    test.marionette.switch_to_frame(frame)
+    test.assertTrue(verify_url in test.marionette.get_url())
 
 class TestSwitchFrame(MarionetteTestCase):
     def test_switch_simple(self):
-        self.assertTrue(self.marionette.execute_script("window.location.href = 'about:blank'; return true;"))
-        self.assertEqual("about:blank", self.marionette.execute_script("return window.location.href;"))
-        test_html = self.marionette.absolute_url("test_iframe.html")
-        self.marionette.navigate(test_html)
-        self.assertNotEqual("about:blank", self.marionette.execute_script("return window.location.href;"))
-        self.assertEqual("Marionette IFrame Test", self.marionette.title)
-        self.marionette.switch_to_frame("test_iframe")
-        self.assertTrue("test.html" in self.marionette.get_url())
+        switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html")
 
     def test_switch_nested(self):
-        self.assertTrue(self.marionette.execute_script("window.location.href = 'about:blank'; return true;"))
-        self.assertEqual("about:blank", self.marionette.execute_script("return window.location.href;"))
-        test_html = self.marionette.absolute_url("test_nested_iframe.html")
-        self.marionette.navigate(test_html)
-        self.assertNotEqual("about:blank", self.marionette.execute_script("return window.location.href;"))
-        self.assertEqual("Marionette IFrame Test", self.marionette.title)
-        self.marionette.switch_to_frame("test_iframe")
-        self.assertTrue("test_inner_iframe.html" in self.marionette.get_url())
+        switch_to_window_verify(self, "test_nested_iframe.html", "test_iframe", "Marionette IFrame Test", "test_inner_iframe.html")
         self.marionette.switch_to_frame("inner_frame")
         self.assertTrue("test.html" in self.marionette.get_url())
         self.marionette.switch_to_frame() # go back to main frame
         self.assertTrue("test_nested_iframe.html" in self.marionette.get_url())
         #test that we're using the right window object server-side
         self.assertTrue("test_nested_iframe.html" in self.marionette.execute_script("return window.location.href;"))
 
+    def test_stack_trace(self):
+        switch_to_window_verify(self, "test_iframe.html", "test_iframe", "Marionette IFrame Test", "test.html")
+        with self.assertRaises(JavascriptException) as cm:
+            self.marionette.execute_async_script("foo();")
+        self.assertTrue("foo" in cm.exception.msg)
+
 class TestSwitchFrameChrome(MarionetteTestCase):
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.marionette.set_context("chrome")
         self.win = self.marionette.current_window_handle
         self.marionette.execute_script("window.open('chrome://marionette/content/test.xul', 'foo', 'chrome,centerscreen');")
         self.marionette.switch_to_window('foo')
         self.assertNotEqual(self.win, self.marionette.current_window_handle)
@@ -57,11 +61,14 @@ class TestSwitchFrameChrome(MarionetteTe
         self.assertTrue("test2.xul" in self.marionette.get_url())
         self.marionette.switch_to_frame()
         self.assertTrue("test.xul" in self.marionette.get_url())
         self.marionette.switch_to_frame("iframename")
         self.assertTrue("test2.xul" in self.marionette.get_url())
         self.marionette.switch_to_frame()
         self.assertTrue("test.xul" in self.marionette.get_url())
         
-    #I can't seem to access a xul iframe within a xul iframe
-    def test_switch_nested(self):
-        pass
+    def test_stack_trace(self):
+        self.assertTrue("test.xul" in self.marionette.get_url())
+        self.marionette.switch_to_frame(0)
+        with self.assertRaises(JavascriptException) as cm:
+            self.marionette.execute_async_script("foo();")
+        self.assertTrue("foo" in cm.exception.msg)
--- a/testing/marionette/marionette-listener.js
+++ b/testing/marionette/marionette-listener.js
@@ -45,16 +45,17 @@ let importedScripts = null;
 // The sandbox we execute test scripts in. Gets lazily created in
 // createExecuteContentSandbox().
 let sandbox;
 
 // Flag to indicate whether an async script is currently running or not.
 let asyncTestRunning = false;
 let asyncTestCommandId;
 let asyncTestTimeoutId;
+let originalOnError;
 //timer for doc changes
 let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
 
 /**
  * Called when listener is first started up. 
  * The listener sends its unique window ID and its current URI to the actor.
  * If the actor returns an ID, we start the listeners. Otherwise, nothing happens.
  */
@@ -476,21 +477,21 @@ function executeWithCallback(msg, useFin
   // see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/execute_async.
   // However Selenium code returns 28, see
   // http://code.google.com/p/selenium/source/browse/trunk/javascript/firefox-driver/js/evaluate.js.
   // We'll stay compatible with the Selenium code.
   asyncTestTimeoutId = curWindow.setTimeout(function() {
     sandbox.asyncComplete('timed out', 28);
   }, msg.json.timeout);
 
-  curWindow.addEventListener('error', function win__onerror(evt) {
-    curWindow.removeEventListener('error', win__onerror, true);
-    sandbox.asyncComplete(evt, 17);
-    return true;
-  }, true);
+  originalOnError = curWindow.onerror;
+  curWindow.onerror = function errHandler(errMsg, url, line) {
+    sandbox.asyncComplete(errMsg, 17);
+    curWindow.onerror = originalOnError;
+  };
 
   let scriptSrc;
   if (useFinish) {
     if (msg.json.timeout == null || msg.json.timeout == 0) {
       sendError("Please set a timeout", 21, null, asyncTestCommandId);
     }
     scriptSrc = script;
   }