Bug 1338911 - Ensure page is loaded before proceeding in test_refresh_firefox.py. r=Gijs a=test-only
authorJessica Jong <jjong@mozilla.com>
Wed, 15 Feb 2017 22:45:00 +0100
changeset 376300 35ef506e005a3bc7f42637debfada1d3e09d7e5a
parent 376299 a6d3ee554e58f1439e0111da53753d37433c7ccc
child 376301 af5bdcf60bf4a23079dd93d419de40840880bbd4
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, test-only
bugs1338911
milestone53.0a2
Bug 1338911 - Ensure page is loaded before proceeding in test_refresh_firefox.py. r=Gijs a=test-only
browser/components/migration/tests/marionette/test_refresh_firefox.py
--- a/browser/components/migration/tests/marionette/test_refresh_firefox.py
+++ b/browser/components/migration/tests/marionette/test_refresh_firefox.py
@@ -1,13 +1,14 @@
 import os
 import shutil
 import time
 
 from marionette_harness import MarionetteTestCase
+from marionette_driver.errors import NoAlertPresentException
 
 
 class TestFirefoxRefresh(MarionetteTestCase):
     _username = "marionette-test-login"
     _password = "marionette-test-password"
     _bookmarkURL = "about:mozilla"
     _bookmarkText = "Some bookmark from Marionette"
 
@@ -256,28 +257,45 @@ class TestFirefoxRefresh(MarionetteTestC
         self.assertEqual(cookieInfo['name'], self._cookieName)
 
     def checkSession(self):
         tabURIs = self.runCode("""
           return [... gBrowser.browsers].map(b => b.currentURI && b.currentURI.spec)
         """)
         self.assertSequenceEqual(tabURIs, ["about:welcomeback"])
 
+        # Dismiss modal dialog if any. This is mainly to dismiss the check for
+        # default browser dialog if it shows up.
+        try:
+          alert = self.marionette.switch_to_alert()
+          alert.dismiss()
+        except NoAlertPresentException:
+          pass
+
         tabURIs = self.runAsyncCode("""
           let mm = gBrowser.selectedBrowser.messageManager;
-          let fs = function() {
-            content.document.getElementById("errorTryAgain").click();
-          };
+
           let {TabStateFlusher} = Cu.import("resource:///modules/sessionstore/TabStateFlusher.jsm", {});
           window.addEventListener("SSWindowStateReady", function testSSPostReset() {
             window.removeEventListener("SSWindowStateReady", testSSPostReset, false);
             Promise.all(gBrowser.browsers.map(b => TabStateFlusher.flush(b))).then(function() {
               marionetteScriptFinished([... gBrowser.browsers].map(b => b.currentURI && b.currentURI.spec));
             });
           }, false);
+
+          let fs = function() {
+            if (content.document.readyState === "complete") {
+              content.document.getElementById("errorTryAgain").click();
+            } else {
+              content.window.addEventListener("load", function(event) {
+                content.document.getElementById("errorTryAgain").click();
+              }, { once: true });
+            }
+          };
+
           mm.loadFrameScript("data:application/javascript,(" + fs.toString() + ")()", true);
         """)
         self.assertSequenceEqual(tabURIs, ["about:blank"] + self._expectedURLs)
         pass
 
     def checkProfile(self, hasMigrated=False):
         self.checkPassword()
         self.checkBookmark()