Bug 1478094 - [marionette] Update crash unit tests to make use of about:crashparent and about:crashcontent draft
authorVenkatesh Pitta <venkateshpitta@gmail.com>
Sat, 04 Aug 2018 00:45:53 +1000
changeset 826314 c5a04d8c1ab3f5421bc3c83ec521501e4bf62569
parent 822828 7ba07ef0e4532b644b812942aa38af4510dbc74f
push id118289
push userbmo:venkateshpitta@gmail.com
push dateFri, 03 Aug 2018 14:47:17 +0000
bugs1478094
milestone63.0a1
Bug 1478094 - [marionette] Update crash unit tests to make use of about:crashparent and about:crashcontent MozReview-Commit-ID: H9LBBD7t9vL
testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_crash.py
@@ -79,43 +79,32 @@ class BaseCrashTestCase(MarionetteTestCa
     def tearDown(self):
         # Replace mockup with original mozcrash instance
         runner.mozcrash = self.mozcrash
 
         self.marionette.crashed = self.crash_count
 
         super(BaseCrashTestCase, self).tearDown()
 
-    def crash(self, chrome=True):
-        context = 'chrome' if chrome else 'content'
-        sandbox = None if chrome else 'system'
-
+    def crash(self, parent=True):
         socket_timeout = self.marionette.client.socket_timeout
         self.marionette.client.socket_timeout = self.socket_timeout
 
-        self.marionette.set_context(context)
+        self.marionette.set_context("content")
         try:
-            self.marionette.execute_script("""
-              // Copied from crash me simple
-              Components.utils.import("resource://gre/modules/ctypes.jsm");
-
-              // ctypes checks for NULL pointer derefs, so just go near-NULL.
-              var zero = new ctypes.intptr_t(8);
-              var badptr = ctypes.cast(zero, ctypes.PointerType(ctypes.int32_t));
-              var crash = badptr.contents;
-            """, sandbox=sandbox)
+            self.marionette.navigate("about:crash{}".format("parent" if parent else "content"))
         finally:
             self.marionette.client.socket_timeout = socket_timeout
 
 
 class TestCrash(BaseCrashTestCase):
 
     def test_crash_chrome_process(self):
         self.assertRaisesRegexp(IOError, "Process crashed",
-                                self.crash, chrome=True)
+                                self.crash, parent=True)
 
         # A crash results in a non zero exit code
         self.assertNotIn(self.marionette.instance.runner.returncode, (None, 0))
 
         self.assertEqual(self.marionette.crashed, 1)
         self.assertIsNone(self.marionette.session)
         self.assertRaisesRegexp(MarionetteException, 'Please start a session',
                                 self.marionette.get_url)
@@ -127,17 +116,17 @@ class TestCrash(BaseCrashTestCase):
 
     @run_if_e10s("Content crashes only exist in e10s mode")
     def test_crash_content_process(self):
         # For a content process crash and MOZ_CRASHREPORTER_SHUTDOWN set the top
         # browsing context will be gone first. As such the raised NoSuchWindowException
         # has to be ignored. To check for the IOError, further commands have to
         # be executed until the process is gone.
         with self.assertRaisesRegexp(IOError, "Content process crashed"):
-            self.crash(chrome=False)
+            self.crash(parent=False)
             Wait(self.marionette, timeout=self.socket_timeout,
                  ignored_exceptions=NoSuchWindowException).until(
                 lambda _: self.marionette.get_url(),
                 message="Expected IOError exception for content crash not raised."
             )
 
         # In the case of a content crash Firefox will be closed and its
         # returncode will report 0 (this will change with 1370520).
@@ -149,26 +138,26 @@ class TestCrash(BaseCrashTestCase):
                                 self.marionette.get_url)
 
         self.marionette.start_session()
         self.assertNotEqual(self.marionette.process_id, self.pid)
         self.marionette.get_url()
 
     @expectedFailure
     def test_unexpected_crash(self):
-        self.crash(chrome=True)
+        self.crash(parent=True)
 
 
 class TestCrashInSetUp(BaseCrashTestCase):
 
     def setUp(self):
         super(TestCrashInSetUp, self).setUp()
 
         self.assertRaisesRegexp(IOError, "Process crashed",
-                                self.crash, chrome=True)
+                                self.crash, parent=True)
 
         # A crash results in a non zero exit code
         self.assertNotIn(self.marionette.instance.runner.returncode, (None, 0))
 
         self.assertEqual(self.marionette.crashed, 1)
         self.assertIsNone(self.marionette.session)
 
     def test_crash_in_setup(self):
@@ -176,17 +165,17 @@ class TestCrashInSetUp(BaseCrashTestCase
         self.assertNotEqual(self.marionette.process_id, self.pid)
 
 
 class TestCrashInTearDown(BaseCrashTestCase):
 
     def tearDown(self):
         try:
             self.assertRaisesRegexp(IOError, "Process crashed",
-                                    self.crash, chrome=True)
+                                    self.crash, parent=True)
 
             # A crash results in a non zero exit code
             self.assertNotIn(self.marionette.instance.runner.returncode, (None, 0))
 
             self.assertEqual(self.marionette.crashed, 1)
             self.assertIsNone(self.marionette.session)
 
         finally: