Bug 1488981 - Fix browser_ext_getViews.js popup count failure when getViews is called before inner-window-destroyed. r=robwu
authorLuca Greco <lgreco@mozilla.com>
Mon, 25 Feb 2019 11:45:29 +0000
changeset 460888 ce6cff27290efa10e6e4fe63fe9889633a965fbb
parent 460877 80e4f0ce3dd4d428993e557f0a879b6da5b2f77c
child 460889 902743b5cc59aa0835b9e20e5df51e9f1fc529a6
push id35613
push usernerli@mozilla.com
push dateTue, 26 Feb 2019 03:52:35 +0000
treeherdermozilla-central@faec87a80ed1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu
bugs1488981
milestone67.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 1488981 - Fix browser_ext_getViews.js popup count failure when getViews is called before inner-window-destroyed. r=robwu This test was failing intermittently in opt and pgo builds because there was a slightly chance that the test extension may be calling browser.extension.getViews while the popup context was unloading but it wasn't still destroyed and so it wasn't yet removed from the set of the extension views. This patch fixes this intermittency by changing the promiseBrowserContentUnloaded test helper to ensure that the unloadPromise is resolved when the "inner-window-destroyed" message for the extension window is being notified to the "observer service" listeners, as it is what the ExtensionPageChild is listening to decide when the ExtensionPageContextChild should be unloaded and removed from the set of the extension views. Differential Revision: https://phabricator.services.mozilla.com/D20658
browser/components/extensions/test/browser/browser_ext_getViews.js
--- a/browser/components/extensions/test/browser/browser_ext_getViews.js
+++ b/browser/components/extensions/test/browser/browser_ext_getViews.js
@@ -71,21 +71,30 @@ async function promiseBrowserContentUnlo
   let unloadPromise = new Promise(resolve => {
     Services.ppmm.addMessageListener(MSG_WINDOW_DESTROYED, function listener() {
       Services.ppmm.removeMessageListener(MSG_WINDOW_DESTROYED, listener);
       resolve();
     });
   });
 
   await ContentTask.spawn(browser, MSG_WINDOW_DESTROYED, (MSG_WINDOW_DESTROYED) => {
-    this.content.addEventListener("unload", () => {
-      // Use process message manager to ensure that the message is delivered
-      // even after the <browser>'s message manager is disconnected.
-      Services.cpmm.sendAsyncMessage(MSG_WINDOW_DESTROYED);
-    }, {once: true});
+    let innerWindowId = this.content.windowUtils.currentInnerWindowID;
+    let observer = (subject) => {
+      if (innerWindowId === subject.QueryInterface(Ci.nsISupportsPRUint64).data) {
+        Services.obs.removeObserver(observer, "inner-window-destroyed");
+
+        // Use process message manager to ensure that the message is delivered
+        // even after the <browser>'s message manager is disconnected.
+        Services.cpmm.sendAsyncMessage(MSG_WINDOW_DESTROYED);
+      }
+    };
+    // Observe inner-window-destroyed, like ExtensionPageChild, to ensure that
+    // the ExtensionPageContextChild instance has been unloaded when we resolve
+    // the unloadPromise.
+    Services.obs.addObserver(observer, "inner-window-destroyed");
   });
 
   // Return an object so that callers can use "await".
   return {unloadPromise};
 }
 
 add_task(async function() {
   let win1 = await BrowserTestUtils.openNewBrowserWindow();
@@ -98,26 +107,30 @@ add_task(async function() {
       "browser_action": {
         "default_popup": "popup.html",
       },
     },
 
     files: {
       "tab.html": `
       <!DOCTYPE html>
-      <html><body>
+      <html>
+      <head><meta charset="utf-8"></head>
+      <body>
       <script src="tab.js"></script>
       </body></html>
       `,
 
       "tab.js": genericChecker,
 
       "popup.html": `
       <!DOCTYPE html>
-      <html><body>
+      <html>
+      <head><meta charset="utf-8"></head>
+      <body>
       <script src="popup.js"></script>
       </body></html>
       `,
 
       "popup.js": genericChecker,
     },
 
     background: genericChecker,