Bug 1125342 - Fix intermittent browser_responsiveui.js by making the test to wait for document to load before starting the test. r=ochameau, a=test-only
authorSami Jaktholm <sjakthol@outlook.com>
Fri, 06 Mar 2015 14:09:50 +0200
changeset 262334 690fb52f675629b213eadf12f42d3078f0c03a42
parent 262333 9bb2ecb59c70b66e728ce2db698da0cd3f6fbc7d
child 262335 caac2d955f54a091bc7258a2785d4dd403b3f239
push id1963
push userpaolo.mozmail@amadzone.org
push dateSun, 10 May 2015 10:26:20 +0000
reviewersochameau, test-only
bugs1125342
milestone38.0a2
Bug 1125342 - Fix intermittent browser_responsiveui.js by making the test to wait for document to load before starting the test. r=ochameau, a=test-only
browser/devtools/responsivedesign/test/browser_responsiveui.js
browser/devtools/responsivedesign/test/head.js
--- a/browser/devtools/responsivedesign/test/browser_responsiveui.js
+++ b/browser/devtools/responsivedesign/test/browser_responsiveui.js
@@ -37,17 +37,21 @@ function test() {
 
     // Menus are correctly updated?
     is(document.getElementById("Tools:ResponsiveUI").getAttribute("checked"), "true", "menus checked");
 
     let instance = mgr.getResponsiveUIForTab(gBrowser.selectedTab);
     ok(instance, "instance of the module is attached to the tab.");
 
     let originalWidth = content.innerWidth;
+
+    let documentLoaded = waitForDocLoadComplete();
     content.location = "data:text/html;charset=utf-8,mop<div style%3D'height%3A5000px'><%2Fdiv>";
+    yield documentLoaded;
+
     let newWidth = content.innerWidth;
     is(originalWidth, newWidth, "Floating scrollbars are presents");
 
     yield instance._test_notifyOnResize();
 
     yield nextTick();
 
     instance.transitionsEnabled = false;
--- a/browser/devtools/responsivedesign/test/head.js
+++ b/browser/devtools/responsivedesign/test/head.js
@@ -207,8 +207,37 @@ function synthesizeKeyFromKeyTag(aKeyId)
   EventUtils.synthesizeKey(name, modifiers);
 }
 
 function nextTick() {
   let def = promise.defer();
   executeSoon(() => def.resolve())
   return def.promise;
 }
+
+/**
+ * Waits for the next load to complete in the current browser.
+ *
+ * @return promise
+ */
+function waitForDocLoadComplete(aBrowser=gBrowser) {
+  let deferred = promise.defer();
+  let progressListener = {
+    onStateChange: function (webProgress, req, flags, status) {
+      let docStop = Ci.nsIWebProgressListener.STATE_IS_NETWORK |
+                    Ci.nsIWebProgressListener.STATE_STOP;
+      info("Saw state " + flags.toString(16) + " and status " + status.toString(16));
+
+      // When a load needs to be retargetted to a new process it is cancelled
+      // with NS_BINDING_ABORTED so ignore that case
+      if ((flags & docStop) == docStop && status != Cr.NS_BINDING_ABORTED) {
+        aBrowser.removeProgressListener(progressListener);
+        info("Browser loaded " + aBrowser.contentWindow.location);
+        deferred.resolve();
+      }
+    },
+    QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
+                                           Ci.nsISupportsWeakReference])
+  };
+  aBrowser.addProgressListener(progressListener);
+  info("Waiting for browser load");
+  return deferred.promise;
+}