Bug 1428740 - Improve Marionette unit tests for parent and content crashes. draft
authorHenrik Skupin <mail@hskupin.info>
Mon, 08 Jan 2018 11:37:41 +0100
changeset 717965 91d5e4ee8d376d6f063357837bed1d111d0ac97d
parent 717028 739484451a6399c7f156a0d960335606aa6c1221
child 745393 1d3902021b467b813e38a24b13a0f7a6b39aec92
push id94826
push userbmo:hskupin@gmail.com
push dateTue, 09 Jan 2018 21:03:48 +0000
bugs1428740
milestone59.0a1
Bug 1428740 - Improve Marionette unit tests for parent and content crashes. For parent process crashes a Wait().until() condition was added, which is not necessary because if the parent (chrome) process dies, the browser window will be gone immediately, and the IOError is thrown directly. Further the tests should check that the correct type of crash is shown in the IOError exceptions. MozReview-Commit-ID: JC90CObZQ3r
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
@@ -1,13 +1,14 @@
 # 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 glob
+import os
 import shutil
 
 from marionette_driver import Wait
 from marionette_driver.errors import (
     MarionetteException,
     NoSuchWindowException,
     TimeoutException
 )
@@ -37,17 +38,18 @@ class MockMozCrash(object):
             # minidump_files = glob.glob('{}/*.dmp'.format(dump_directory))
             try:
                 minidump_files = Wait(None, timeout=5).until(
                     lambda _: glob.glob('{}/*.dmp'.format(dump_directory))
                 )
             except TimeoutException:
                 minidump_files = []
 
-            shutil.rmtree(dump_directory)
+            if os.path.isdir(dump_directory):
+                shutil.rmtree(dump_directory)
 
             return len(minidump_files)
         else:
             return len(minidump_files) == 0
 
     def log_crashes(self, logger, dump_directory, *args, **kwargs):
         return self.check_for_crashes(dump_directory, *args, **kwargs)
 
@@ -100,45 +102,39 @@ class BaseCrashTestCase(MarionetteTestCa
             """, sandbox=sandbox)
         finally:
             self.marionette.client.socket_timeout = socket_timeout
 
 
 class TestCrash(BaseCrashTestCase):
 
     def test_crash_chrome_process(self):
-        with self.assertRaises(IOError):
-            self.crash(chrome=True)
-            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."
-            )
+        self.assertRaisesRegexp(IOError, "Process crashed",
+                                self.crash, chrome=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)
 
         self.marionette.start_session()
         self.assertNotEqual(self.marionette.process_id, self.pid)
 
         self.marionette.get_url()
 
     @run_if_e10s("Content crashes only exist in e10s mode")
     def test_crash_content_process(self):
-        # With MOZ_CRASHREPORTER_SHUTDOWN each window of the browser will be
-        # closed in case of a content crash. So the "unload" handler fires for
-        # the current window, which causes the command to return early.
-        # To check for an IOError, further commands have to be executed until
-        # Firefox has been shutdown.
-        with self.assertRaises(IOError):
+        # 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)
             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
@@ -159,46 +155,36 @@ class TestCrash(BaseCrashTestCase):
         self.crash(chrome=True)
 
 
 class TestCrashInSetUp(BaseCrashTestCase):
 
     def setUp(self):
         super(TestCrashInSetUp, self).setUp()
 
-        with self.assertRaises(IOError):
-            self.crash(chrome=True)
-            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."
-            )
+        self.assertRaisesRegexp(IOError, "Process crashed",
+                                self.crash, chrome=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):
         self.marionette.start_session()
         self.assertNotEqual(self.marionette.process_id, self.pid)
 
 
 class TestCrashInTearDown(BaseCrashTestCase):
 
     def tearDown(self):
         try:
-            with self.assertRaises(IOError):
-                self.crash(chrome=True)
-                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."
-                )
+            self.assertRaisesRegexp(IOError, "Process crashed",
+                                    self.crash, chrome=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: