Bug 1398272 - Prevent onUpdated from breaking tab IDs for adopted tabs. r=kmag, a=jcristau
authorTomislav Jovanovic <tomica@gmail.com>
Tue, 15 May 2018 22:36:18 +0200
changeset 802197 f2165acbf563b92e790843ef3005cfbddad00cfc
parent 802196 b63a4acbf1f84cf76e1e821f40f2149bd8bc7a9f
child 802198 62bc8ca444f93c09e9e87c4910a7910596f8010e
push id111850
push userbmo:tom@mozilla.com
push dateThu, 31 May 2018 16:41:37 +0000
reviewerskmag, jcristau
bugs1398272
milestone60.0.2
Bug 1398272 - Prevent onUpdated from breaking tab IDs for adopted tabs. r=kmag, a=jcristau
browser/components/extensions/ext-tabs.js
browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -294,18 +294,22 @@ this.tabs = class extends ExtensionAPI {
               }
               if (changed.includes("sharing")) {
                 needed.push("sharingState");
               }
             } else if (event.type == "TabPinned") {
               needed.push("pinned");
             } else if (event.type == "TabUnpinned") {
               needed.push("pinned");
-            } else if (event.type == "TabBrowserInserted" &&
-                       !event.detail.insertedOnTabCreation) {
+            } else if (event.type == "TabBrowserInserted") {
+              // This may be an adopted tab. Bail early to avoid asking tabManager
+              // about the tab before we run the adoption logic in ext-browser.js.
+              if (event.detail.insertedOnTabCreation) {
+                return;
+              }    
               needed.push("discarded");
             } else if (event.type == "TabBrowserDiscarded") {
               needed.push("discarded");
             } else if (event.type == "TabShow") {
               needed.push("hidden");
             } else if (event.type == "TabHide") {
               needed.push("hidden");
             }
--- a/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
@@ -12,27 +12,33 @@ add_task(async function() {
       "permissions": ["tabs"],
     },
 
     async background() {
       let tabs = await browser.tabs.query({url: "<all_urls>"});
       let destination = tabs[0];
       let source = tabs[1]; // skip over about:blank in window1
 
+      browser.tabs.onUpdated.addListener(() => {
+        // Bug 1398272: Adding onUpdated listener broke tab IDs across windows.
+      });
+
       // Assuming that this windowId does not exist.
       await browser.test.assertRejects(
         browser.tabs.move(source.id, {windowId: 123144576, index: 0}),
         /Invalid window/,
         "Should receive invalid window error");
 
       browser.tabs.move(source.id, {windowId: destination.windowId, index: 0});
 
       tabs = await browser.tabs.query({url: "<all_urls>"});
       browser.test.assertEq(tabs[0].url, "http://example.com/");
       browser.test.assertEq(tabs[0].windowId, destination.windowId);
+      browser.test.assertEq(tabs[0].id, source.id);
+
       browser.test.notifyPass("tabs.move.window");
     },
   });
 
   await extension.startup();
   await extension.awaitFinish("tabs.move.window");
   await extension.unload();