Bug 1338911 - Ensure page is loaded before proceeding in test_refresh_firefox.py. r=Gijs
authorJessica Jong <jjong@mozilla.com>
Sun, 19 Feb 2017 19:18:00 -0500
changeset 486876 87d88eed04b26d799285a287a06fac287e2a88e6
parent 486875 dbba2087799852f1b83ef118f0aebb939b2b625e
child 486877 e7a05ab2dc0d6893efb7dd9b4d7891a0c70a0e51
child 487055 87908aced1112d2fe469d2042ce8ce22e72a7f34
push id46082
push userm_kato@ga2.so-net.ne.jp
push dateMon, 20 Feb 2017 05:29:00 +0000
reviewersGijs
bugs1338911
milestone54.0a1
Bug 1338911 - Ensure page is loaded before proceeding in test_refresh_firefox.py. r=Gijs
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"
 
@@ -264,28 +265,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, self._expectedURLs)
 
     def checkProfile(self, hasMigrated=False):
         self.checkPassword()
         self.checkBookmark()
         self.checkHistory()