Bug 1486050 - Don't change selected tab when browser.tabs.update is called with {highlighted: true, active: false}. r=mixedpuppy
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Mon, 27 Aug 2018 11:53:42 +0000
changeset 491212 84d0017964b62ebb961b16fb5e0a30e11ae04b00
parent 491211 4095afaecf59f6296e72102c4aefc6c54b7305e5
child 491213 d846803d6d6e6a24586232f0291dfc6cdffa1e19
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1486050
milestone63.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 1486050 - Don't change selected tab when browser.tabs.update is called with {highlighted: true, active: false}. r=mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D4272
browser/components/extensions/parent/ext-tabs.js
browser/components/extensions/test/browser/browser_ext_tabs_update_highlighted.js
--- a/browser/components/extensions/parent/ext-tabs.js
+++ b/browser/components/extensions/parent/ext-tabs.js
@@ -707,19 +707,22 @@ this.tabs = class extends ExtensionAPI {
           }
           if (updateProperties.highlighted !== null) {
             if (!gMultiSelectEnabled) {
               throw new ExtensionError(`updateProperties.highlight is currently experimental and must be enabled with the ${MULTISELECT_PREFNAME} preference.`);
             }
             if (updateProperties.highlighted) {
               if (!nativeTab.selected && !nativeTab.multiselected) {
                 tabbrowser.addToMultiSelectedTabs(nativeTab, false);
-                // Select the highlighted tab, this matches Chrome's behavior.
-                tabbrowser.lockClearMultiSelectionOnce();
-                tabbrowser.selectedTab = nativeTab;
+                // Select the highlighted tab unless active:false is provided.
+                // Note that Chrome selects it even in that case.
+                if (updateProperties.active !== false) {
+                  tabbrowser.lockClearMultiSelectionOnce();
+                  tabbrowser.selectedTab = nativeTab;
+                }
               }
             } else {
               tabbrowser.removeFromMultiSelectedTabs(nativeTab, true);
             }
           }
           if (updateProperties.muted !== null) {
             if (nativeTab.muted != updateProperties.muted) {
               nativeTab.toggleMuteAudio(extension.id);
--- a/browser/components/extensions/test/browser/browser_ext_tabs_update_highlighted.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_update_highlighted.js
@@ -110,35 +110,34 @@ add_task(async function test_update_high
         await browser.tabs.update(tab2, {highlighted: false});
         return {active: tab1, highlighted: [tab1], events: [
           ["onHighlighted", {tabIds: [tab1], windowId}],
         ]};
       }, "unhighlighting inactive highlighted tab");
 
       await expectResults(async () => {
         await browser.tabs.update(tab2, {highlighted: true, active: false});
-        return {active: tab2, highlighted: [tab1, tab2], events: [
-          ["onActivated", {tabId: tab2, windowId}],
+        return {active: tab1, highlighted: [tab1, tab2], events: [
           ["onHighlighted", {tabIds: [tab1, tab2], windowId}],
         ]};
-      }, "highlighting and (not really) inactivating non-highlighted tab");
+      }, "highlighting without activating non-highlighted tab");
 
       await expectResults(async () => {
-        await browser.tabs.update(tab1, {highlighted: true, active: true});
-        return {active: tab1, highlighted: [tab1], events: [
-          ["onActivated", {tabId: tab1, windowId}],
-          ["onHighlighted", {tabIds: [tab1], windowId}],
+        await browser.tabs.update(tab2, {highlighted: true, active: true});
+        return {active: tab2, highlighted: [tab2], events: [
+          ["onActivated", {tabId: tab2, windowId}],
+          ["onHighlighted", {tabIds: [tab2], windowId}],
         ]};
       }, "highlighting and activating inactive highlighted tab");
 
       await expectResults(async () => {
-        await browser.tabs.update(tab2, {active: true, highlighted: true});
-        return {active: tab2, highlighted: [tab2], events: [
-          ["onActivated", {tabId: tab2, windowId}],
-          ["onHighlighted", {tabIds: [tab2], windowId}],
+        await browser.tabs.update(tab1, {active: true, highlighted: true});
+        return {active: tab1, highlighted: [tab1], events: [
+          ["onActivated", {tabId: tab1, windowId}],
+          ["onHighlighted", {tabIds: [tab1], windowId}],
         ]};
       }, "highlighting and activating non-highlighted tab");
 
       await browser.tabs.remove([tab1, tab2]);
       browser.test.notifyPass("test-finished");
     },
   });