Bug 803253 - Only wait for system-message-listener-ready on emulator startup, r=mdas, DONTBUILD, a=NPOTB
authorJonathan Griffin <jgriffin@mozilla.com>
Thu, 18 Oct 2012 13:19:21 -0700
changeset 116617 f9166576f834df7fe2ab822b070a1b14611cc3aa
parent 116616 fa9d3e13e47399cd49a49c4e21ee596e32bbd29c
child 116618 d45c28a32e26383d70bbdfbdeef1f78930cb0fcd
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmdas, DONTBUILD, NPOTB
bugs803253
milestone18.0a2
Bug 803253 - Only wait for system-message-listener-ready on emulator startup, r=mdas, DONTBUILD, a=NPOTB
testing/marionette/client/marionette/marionette.py
testing/marionette/client/marionette/marionette_test.py
--- a/testing/marionette/client/marionette/marionette.py
+++ b/testing/marionette/client/marionette/marionette.py
@@ -137,16 +137,42 @@ class Marionette(object):
                                      logcat_dir=self.logcat_dir,
                                      gecko_path=self.gecko_path)
             self.emulator.connect()
             self.port = self.emulator.setup_port_forwarding(self.port)
             assert(self.emulator.wait_for_port())
 
         self.client = MarionetteClient(self.host, self.port)
 
+        if emulator:
+            # When launching an emulator, telephony API's are not
+            # available immediately.  They start working after the
+            # system-message-listener-ready event is observed.  See
+            # bug 792647.  This code causes us to wait for this event
+            # after launching an emulator, before allowing any tests
+            # to run.
+            self.start_session()
+            self.set_context(self.CONTEXT_CHROME)
+            self.set_script_timeout(30000)
+            try:
+                self.execute_async_script("""
+    waitFor(
+        function() { marionetteScriptFinished(true); },
+        function() { return isSystemMessageListenerReady(); }
+    );
+                """)
+            except ScriptTimeoutException:
+                # We silently ignore the timeout if it occurs, since
+                # isSystemMessageListenerReady() isn't available on
+                # older emulators.  30s *should* be enough of a delay
+                # to allow telephony API's to work.
+                pass
+            self.set_context(self.CONTEXT_CONTENT)
+            self.delete_session()
+
     def __del__(self):
         if self.emulator:
             self.emulator.close()
         if self.instance:
             self.instance.close()
         for qemu in self.extra_emulators:
             qemu.emulator.close()
 
--- a/testing/marionette/client/marionette/marionette_test.py
+++ b/testing/marionette/client/marionette/marionette_test.py
@@ -156,26 +156,16 @@ class MarionetteJSTestCase(CommonTestCas
     def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette, testvars):
         suite.addTest(cls(weakref.ref(marionette), jsFile=filepath))
 
     def runTest(self):
         if self.marionette.session is None:
             self.marionette.start_session()
         self.marionette.execute_script("log('TEST-START: %s');" % self.jsFile.replace('\\', '\\\\'))
 
-        self.marionette.set_context(self.marionette.CONTEXT_CHROME)
-        self.marionette.set_script_timeout(30000)
-        self.marionette.execute_async_script("""
-waitFor(
-    function() { marionetteScriptFinished(true); },
-    function() { return isSystemMessageListenerReady(); }
-);
-            """)
-        self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
-
         f = open(self.jsFile, 'r')
         js = f.read()
         args = []
 
         # if this is a browser_ test, prepend head.js to it
         if os.path.basename(self.jsFile).startswith('browser_'):
             local_head = open(os.path.join(os.path.dirname(__file__), 'tests', 'head.js'), 'r')
             js = local_head.read() + js