Bug 1167508 - Fix BrowserTestUtils.browserLoaded() and use it in sessionstore/head.js r=billm
☠☠ backed out by 986f641d87e4 ☠ ☠
authorTim Taubert <ttaubert@mozilla.com>
Sat, 23 May 2015 15:47:28 +0200
changeset 248032 00eb943a27b21e92204c525a656c59ec17e3c50e
parent 248031 c1a16fd640aed3c0fbfacde14bd3bcbfda7adf3d
child 248033 97b5372b89506a986eb23f13e91e2ded2ac4e87d
push id60888
push userkwierso@gmail.com
push dateThu, 11 Jun 2015 01:38:38 +0000
treeherdermozilla-inbound@39e638ed06bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1167508
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1167508 - Fix BrowserTestUtils.browserLoaded() and use it in sessionstore/head.js r=billm
browser/components/sessionstore/test/head.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -277,24 +277,17 @@ let promiseForEachSessionRestoreFile = T
 	     && ex.becauseNoSuchFile) {
       // Ignore missing files
     }
     cb(data, key);
   }
 });
 
 function promiseBrowserLoaded(aBrowser, ignoreSubFrames = true) {
-  return new Promise(resolve => {
-    aBrowser.messageManager.addMessageListener("ss-test:loadEvent", function onLoad(msg) {
-      if (!ignoreSubFrames || !msg.data.subframe) {
-        aBrowser.messageManager.removeMessageListener("ss-test:loadEvent", onLoad);
-        resolve();
-      }
-    });
-  });
+  return BrowserTestUtils.browserLoaded(aBrowser, !ignoreSubFrames);
 }
 
 function whenWindowLoaded(aWindow, aCallback = next) {
   aWindow.addEventListener("load", function windowLoadListener() {
     aWindow.removeEventListener("load", windowLoadListener, false);
     executeSoon(function executeWhenWindowLoaded() {
       aCallback(aWindow);
     });
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -135,21 +135,20 @@ this.BrowserTestUtils = {
    * @param {Boolean} includeSubFrames
    *        A boolean indicating if loads from subframes should be included.
    *
    * @return {Promise}
    * @resolves When a load event is triggered for the browser.
    */
   browserLoaded(browser, includeSubFrames=false) {
     return new Promise(resolve => {
-      browser.messageManager.addMessageListener("browser-test-utils:loadEvent",
-                                                 function onLoad(msg) {
-        if (!msg.data.subframe || includeSubFrames) {
-          browser.messageManager.removeMessageListener(
-            "browser-test-utils:loadEvent", onLoad);
+      let mm = browser.ownerDocument.defaultView.messageManager;
+      mm.addMessageListener("browser-test-utils:loadEvent", function onLoad(msg) {
+        if (msg.target == browser && (!msg.data.subframe || includeSubFrames)) {
+          mm.removeMessageListener("browser-test-utils:loadEvent", onLoad);
           resolve();
         }
       });
     });
   },
 
   /**
    * @return {Promise}