Bug 1167508 - Fix BrowserTestUtils.browserLoaded() and use it in sessionstore/head.js r=billm
authorTim Taubert <ttaubert@mozilla.com>
Tue, 09 Jun 2015 22:11:43 +0200
changeset 248079 ad065623983ef6a0a6ea02dc412cf05948ace88a
parent 248078 d3de3ab56658c3571acf02bf500c7afa3090cbdb
child 248080 aead6e4865f9e7a3d514ac795526bacf3e6585a4
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}