Bug 1538378 - Back out bug 1529411. r=mixedpuppy a=pascalc
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Tue, 26 Mar 2019 02:40:18 +0000
changeset 525723 338dcd382a65dae76061e5b0809edc8d9928a806
parent 525722 dab7eaf9899235d813e50b299508be269b167a19
child 525724 2f5aedeffed90029e870c65b7ad1c797c380186e
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, pascalc
bugs1538378, 1529411
milestone67.0
Bug 1538378 - Back out bug 1529411. r=mixedpuppy a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D24818
browser/components/extensions/parent/ext-browser.js
browser/components/extensions/test/browser/browser_ext_tabs_events.js
--- a/browser/components/extensions/parent/ext-browser.js
+++ b/browser/components/extensions/parent/ext-browser.js
@@ -455,27 +455,36 @@ class TabTracker extends TabTrackerBase 
           // Handle the adoption.
           this.adopt(nativeTab, adoptedTab);
           if (adoptedTab.linkedPanel) {
             adoptedTab.linkedBrowser.messageManager.sendAsyncMessage("Extension:SetFrameData", {
               windowId: windowTracker.getId(nativeTab.ownerGlobal),
             });
           }
         } else {
-          if (!event.originalTarget.parentNode) {
-            // If the tab is already be destroyed, do nothing.
-            return;
-          }
+          // Save the size of the current tab, since the newly-created tab will
+          // likely be active by the time the promise below resolves and the
+          // event is dispatched.
           const currentTab = nativeTab.ownerGlobal.gBrowser.selectedTab;
           const {frameLoader} = currentTab.linkedBrowser;
           const currentTabSize = {
             width: frameLoader.lazyWidth,
             height: frameLoader.lazyHeight,
           };
-          this.emitCreated(event.originalTarget, currentTabSize);
+
+          // We need to delay sending this event until the next tick, since the
+          // tab could have been created with a lazy browser but still not have
+          // been assigned a SessionStore tab state with the URL and title.
+          Promise.resolve().then(() => {
+            if (!event.originalTarget.parentNode) {
+              // If the tab is already be destroyed, do nothing.
+              return;
+            }
+            this.emitCreated(event.originalTarget, currentTabSize);
+          });
         }
         break;
 
       case "TabClose":
         let {adoptedBy} = event.detail;
         if (adoptedBy) {
           // This tab is being closed because it was adopted by a new window.
           // Handle the adoption in case it was created as the first tab of a
@@ -483,31 +492,31 @@ class TabTracker extends TabTrackerBase 
           // opened.
           this.adopt(adoptedBy, nativeTab);
         } else {
           this.emitRemoved(nativeTab, false);
         }
         break;
 
       case "TabSelect":
-        // We need to delay sending this event because it shouldn't fire before
-        // onRemoved when the active tab is removed.
+        // Because we are delaying calling emitCreated above, we also need to
+        // delay sending this event because it shouldn't fire before onCreated.
         Promise.resolve().then(() => {
           if (!nativeTab.parentNode) {
             // If the tab is already be destroyed, do nothing.
             return;
           }
           this.emitActivated(nativeTab, event.detail.previousTab);
         });
         break;
 
       case "TabMultiSelect":
         if (this.has("tabs-highlighted")) {
-          // Because we are delaying calling emitActivated above, we also need to
-          // delay sending this event because it shouldn't fire before onActivated.
+          // Because we are delaying calling emitCreated above, we also need to
+          // delay sending this event because it shouldn't fire before onCreated.
           Promise.resolve().then(() => {
             this.emitHighlighted(event.target.ownerGlobal);
           });
         }
         break;
     }
   }
 
--- a/browser/components/extensions/test/browser/browser_ext_tabs_events.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_events.js
@@ -396,23 +396,22 @@ add_task(async function testLastTabRemov
   const CLOSE_WINDOW_PREF = "browser.tabs.closeWindowWithLastTab";
   await SpecialPowers.pushPrefEnv({set: [
     [CLOSE_WINDOW_PREF, false],
   ]});
 
   async function background() {
     let windowId;
     browser.tabs.onCreated.addListener(tab => {
-      windowId = tab.windowId;
+      browser.test.assertEq(windowId, tab.windowId,
+                            "expecting onCreated after onRemoved on the same window");
       browser.test.sendMessage("tabCreated", `${tab.width}x${tab.height}`);
     });
     browser.tabs.onRemoved.addListener((tabId, info) => {
-      browser.test.assertEq(windowId, info.windowId,
-                            "expecting onRemoved after onCreated on the same window");
-      browser.test.sendMessage("tabRemoved");
+      windowId = info.windowId;
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "permissions": ["tabs"],
     },
     background,
@@ -422,17 +421,16 @@ add_task(async function testLastTabRemov
   await extension.startup();
 
   const oldBrowser = newWin.gBrowser.selectedBrowser;
   const expectedDims = `${oldBrowser.clientWidth}x${oldBrowser.clientHeight}`;
   BrowserTestUtils.removeTab(newWin.gBrowser.selectedTab);
 
   const actualDims = await extension.awaitMessage("tabCreated");
   is(actualDims, expectedDims, "created tab reports a size same to the removed last tab");
-  await extension.awaitMessage("tabRemoved");
 
   await extension.unload();
   await BrowserTestUtils.closeWindow(newWin);
   SpecialPowers.clearUserPref(CLOSE_WINDOW_PREF);
 });
 
 add_task(async function testTabActivationEvent() {
   async function background() {