Bug 1476844 - Clear selected tabs whenever 'TabSelect' event is fired except when switching tab from 'switchToNextMultiSelectedTab' function in /browser/base/content/tabbrowser.js. r=jaws
authorAbdoulaye O. Ly <ablayelyfondou@gmail.com>
Sat, 21 Jul 2018 02:32:19 +0000
changeset 428900 697a32f394b28d1dd908f7d7b97c4c0f1819057f
parent 428899 3f6664786e8531bc621d0113328d73cf3556193f
child 428901 f0e52163b195725794a12f8895ce61b57d17982f
push id34351
push userapavel@mozilla.com
push dateMon, 30 Jul 2018 09:51:16 +0000
treeherdermozilla-central@d01677a667bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1476844
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 1476844 - Clear selected tabs whenever 'TabSelect' event is fired except when switching tab from 'switchToNextMultiSelectedTab' function in /browser/base/content/tabbrowser.js. r=jaws MozReview-Commit-ID: J2DyAbQJITo
browser/base/content/tabbrowser.js
browser/base/content/tabbrowser.xml
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_multiselect_tabs_clear_selection_when_tab_switch.js
browser/base/content/test/tabs/browser_multiselect_tabs_close.js
browser/base/content/test/tabs/browser_multiselect_tabs_using_Ctrl.js
browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift_and_Ctrl.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -142,16 +142,18 @@ window._gBrowser = {
   ],
 
   _removingTabs: [],
 
   _multiSelectedTabsSet: new WeakSet(),
 
   _lastMultiSelectedTabRef: null,
 
+  _clearMultiSelectionLocked: false,
+
   /**
    * Tab close requests are ignored if the window is closing anyway,
    * e.g. when holding Ctrl+W.
    */
   _windowIsClosing: false,
 
   /**
    * This defines a proxy which allows us to access browsers by
@@ -3686,17 +3688,26 @@ window._gBrowser = {
       return;
     }
     aTab.removeAttribute("multiselected");
     this.tabContainer._setPositionalAttributes();
     this._multiSelectedTabsSet.delete(aTab);
   },
 
   clearMultiSelectedTabs(updatePositionalAttributes) {
-    for (let tab of this.selectedTabs) {
+    if (this._clearMultiSelectionLocked) {
+      return;
+    }
+
+    let selectedTabs = this.selectedTabs;
+    if (selectedTabs.length < 2) {
+      return;
+    }
+
+    for (let tab of selectedTabs) {
       tab.removeAttribute("multiselected");
     }
     this._multiSelectedTabsSet = new WeakSet();
     this._lastMultiSelectedTabRef = null;
     if (updatePositionalAttributes) {
       this.tabContainer._setPositionalAttributes();
     }
   },
@@ -3706,25 +3717,31 @@ window._gBrowser = {
    */
   updateActiveTabMultiSelectState() {
     if (this.selectedTabs.length == 1) {
       this.clearMultiSelectedTabs();
     }
   },
 
   switchToNextMultiSelectedTab() {
-    let lastMultiSelectedTab = gBrowser.lastMultiSelectedTab;
-    if (lastMultiSelectedTab != gBrowser.selectedTab) {
-      gBrowser.selectedTab = lastMultiSelectedTab;
-      return;
-    }
-    let selectedTabs = ChromeUtils.nondeterministicGetWeakSetKeys(this._multiSelectedTabsSet)
-                                  .filter(tab => tab.isConnected && !tab.closing);
-    let length = selectedTabs.length;
-    gBrowser.selectedTab = selectedTabs[length - 1];
+    this._clearMultiSelectionLocked = true;
+    try {
+      let lastMultiSelectedTab = gBrowser.lastMultiSelectedTab;
+      if (lastMultiSelectedTab != gBrowser.selectedTab) {
+        gBrowser.selectedTab = lastMultiSelectedTab;
+      } else {
+        let selectedTabs = ChromeUtils.nondeterministicGetWeakSetKeys(this._multiSelectedTabsSet)
+          .filter(tab => tab.isConnected && !tab.closing);
+        let length = selectedTabs.length;
+        gBrowser.selectedTab = selectedTabs[length - 1];
+      }
+    } catch (e) {
+      Cu.reportError(e);
+    }
+    this._clearMultiSelectionLocked = false;
   },
 
   set selectedTabs(tabs) {
     this.clearMultiSelectedTabs(false);
     this.selectedTab = tabs[0];
     if (tabs.length > 1) {
       for (let tab of tabs) {
         this.addToMultiSelectedTabs(tab, true);
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -947,17 +947,20 @@
               this.removeAttribute("hiddensoundplaying");
             }
           }
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
-      <handler event="TabSelect" action="this._handleTabSelect();"/>
+      <handler event="TabSelect"><![CDATA[
+        this._handleTabSelect();
+        gBrowser.clearMultiSelectedTabs(true);
+      ]]></handler>
 
       <handler event="TabClose"><![CDATA[
         this._hiddenSoundPlayingStatusChanged(event.target, {closed: true});
       ]]></handler>
 
       <handler event="TabAttrModified"><![CDATA[
         if (event.detail.changed.includes("soundplaying") && event.target.hidden) {
           this._hiddenSoundPlayingStatusChanged(event.target);
@@ -2002,20 +2005,22 @@
 
       <handler event="click" button="0"><![CDATA[
         if (Services.prefs.getBoolPref("browser.tabs.multiselect")) {
           let shiftKey = event.shiftKey;
           let accelKey = event.getModifierState("Accel");
           if (shiftKey) {
             const lastSelectedTab = gBrowser.lastMultiSelectedTab;
             if (!accelKey) {
-              gBrowser.clearMultiSelectedTabs(true);
+              gBrowser.selectedTab = lastSelectedTab;
+
+              // Make sure selection is cleared when tab-switch doesn't happen.
+              gBrowser.clearMultiSelectedTabs(false);
             }
             gBrowser.addRangeToMultiSelectedTabs(lastSelectedTab, this);
-            gBrowser.selectedTab = lastSelectedTab;
             return;
           }
           if (accelKey) {
             // Ctrl (Cmd for mac) key is pressed
             if (this.multiselected) {
               gBrowser.removeFromMultiSelectedTabs(this);
               if (this == gBrowser.selectedTab) {
                 gBrowser.switchToNextMultiSelectedTab();
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -16,27 +16,29 @@ tags = audiochannel
 [browser_close_tab_by_dblclick.js]
 [browser_contextmenu_openlink_after_tabnavigated.js]
 skip-if = (verify && debug && (os == 'linux'))
 support-files =
   test_bug1358314.html
 [browser_isLocalAboutURI.js]
 [browser_multiselect_tabs_active_tab_selected_by_default.js]
 [browser_multiselect_tabs_bookmark.js]
+[browser_multiselect_tabs_clear_selection_when_tab_switch.js]
 [browser_multiselect_tabs_close_other_tabs.js]
 [browser_multiselect_tabs_close_using_shortcuts.js]
 [browser_multiselect_tabs_close.js]
 [browser_multiselect_tabs_move_to_new_window_contextmenu.js]
 [browser_multiselect_tabs_mute_unmute.js]
 [browser_multiselect_tabs_pin_unpin.js]
 [browser_multiselect_tabs_positional_attrs.js]
 [browser_multiselect_tabs_reload.js]
 [browser_multiselect_tabs_using_Ctrl.js]
+[browser_multiselect_tabs_using_selectedTabs.js]
+[browser_multiselect_tabs_using_Shift_and_Ctrl.js]
 [browser_multiselect_tabs_using_Shift.js]
-[browser_multiselect_tabs_using_selectedTabs.js]
 [browser_navigatePinnedTab.js]
 [browser_new_file_whitelisted_http_tab.js]
 skip-if = !e10s # Test only relevant for e10s.
 [browser_new_tab_insert_position.js]
 skip-if = (debug && os == 'linux' && bits == 32) #Bug 1455882, disabled on Linux32 for almost permafailing
 support-files = file_new_tab_page.html
 [browser_new_tab_in_privileged_process_pref.js]
 skip-if = !e10s # Pref and test only relevant for e10s.
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_clear_selection_when_tab_switch.js
@@ -0,0 +1,38 @@
+const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";
+
+add_task(async function setPref() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_MULTISELECT_TABS, true]]
+  });
+});
+
+add_task(async function test() {
+  let initialTab = gBrowser.selectedTab;
+  let tab1 = await addTab();
+  let tab2 = await addTab();
+  let tab3 = await addTab();
+
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
+
+  for (let tab of [tab1, tab2, tab3]) {
+    await triggerClickOn(tab, { ctrlKey: true });
+  }
+
+  is(gBrowser.multiSelectedTabsCount, 4, "Four multiselected tabs");
+  is(gBrowser.selectedTab, initialTab, "InitialTab is the active tab");
+
+  info("Un-select the active tab");
+  await BrowserTestUtils.switchTab(gBrowser, triggerClickOn(initialTab, { ctrlKey: true }));
+
+  is(gBrowser.multiSelectedTabsCount, 3, "Three multiselected tabs");
+  is(gBrowser.selectedTab, tab3, "Tab3 is the active tab");
+
+  await BrowserTestUtils.switchTab(gBrowser, tab1);
+
+  is(gBrowser.multiSelectedTabsCount, 0, "Selection cleared after tab-switch");
+  is(gBrowser.selectedTab, tab1, "Tab1 is the active tab");
+
+  for (let tab of [tab1, tab2, tab3]) {
+    BrowserTestUtils.removeTab(tab);
+  }
+});
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
@@ -1,106 +1,111 @@
 const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";
 const PREF_WARN_ON_CLOSE = "browser.tabs.warnOnCloseOtherTabs";
 
 add_task(async function setPref() {
-    await SpecialPowers.pushPrefEnv({
-        set: [
-            [PREF_MULTISELECT_TABS, true],
-            [PREF_WARN_ON_CLOSE, false]
-        ]
-    });
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      [PREF_MULTISELECT_TABS, true],
+      [PREF_WARN_ON_CLOSE, false]
+    ]
+  });
 });
 
 add_task(async function usingTabCloseButton() {
-    let tab1 = await addTab();
-    let tab2 = await addTab();
-    let tab3 = await addTab();
-    let tab4 = await addTab();
+  let tab1 = await addTab();
+  let tab2 = await addTab();
+  let tab3 = await addTab();
+  let tab4 = await addTab();
 
-    is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    await BrowserTestUtils.switchTab(gBrowser, tab1);
-    await triggerClickOn(tab2, { ctrlKey: true });
+  await BrowserTestUtils.switchTab(gBrowser, tab1);
+  await triggerClickOn(tab2, { ctrlKey: true });
 
-    ok(tab1.multiselected, "Tab1 is multiselected");
-    ok(tab2.multiselected, "Tab2 is multiselected");
-    ok(!tab3.multiselected, "Tab3 is not multiselected");
-    ok(!tab4.multiselected, "Tab4 is not multiselected");
-    is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
+  ok(tab1.multiselected, "Tab1 is multiselected");
+  ok(tab2.multiselected, "Tab2 is multiselected");
+  ok(!tab3.multiselected, "Tab3 is not multiselected");
+  ok(!tab4.multiselected, "Tab4 is not multiselected");
+  is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
+  is(gBrowser.selectedTab, tab1, "Tab1 is active");
 
-    // Closing a tab which is not multiselected
-    let tab4CloseBtn = document.getAnonymousElementByAttribute(tab4, "anonid", "close-button");
-    let tab4Closing = BrowserTestUtils.waitForTabClosing(tab4);
-    tab4CloseBtn.click();
-    await tab4Closing;
+  // Closing a tab which is not multiselected
+  let tab4CloseBtn = document.getAnonymousElementByAttribute(tab4, "anonid", "close-button");
+  let tab4Closing = BrowserTestUtils.waitForTabClosing(tab4);
 
-    ok(tab1.multiselected, "Tab1 is multiselected");
-    ok(!tab1.closing, "Tab1 is not closing");
-    ok(tab2.multiselected, "Tab2 is multiselected");
-    ok(!tab2.closing, "Tab2 is not closing");
-    ok(!tab3.multiselected, "Tab3 is not multiselected");
-    ok(!tab3.closing, "Tab3 is not closing");
-    ok(tab4.closing, "Tab4 is closing");
-    is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
+  tab4.mOverCloseButton = true;
+  ok(tab4.mOverCloseButton, "Mouse over tab4 close button");
+  tab4CloseBtn.click();
+  await tab4Closing;
+
+  is(gBrowser.selectedTab, tab1, "Tab1 is active");
+  ok(tab1.multiselected, "Tab1 is multiselected");
+  ok(!tab1.closing, "Tab1 is not closing");
+  ok(tab2.multiselected, "Tab2 is multiselected");
+  ok(!tab2.closing, "Tab2 is not closing");
+  ok(!tab3.multiselected, "Tab3 is not multiselected");
+  ok(!tab3.closing, "Tab3 is not closing");
+  ok(tab4.closing, "Tab4 is closing");
+  is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
 
-    // Closing a selected tab
-    let tab2CloseBtn = document.getAnonymousElementByAttribute(tab1, "anonid", "close-button");
-    let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
-    let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
-    tab2CloseBtn.click();
-    await tab1Closing;
-    await tab2Closing;
+  // Closing a selected tab
+  let tab2CloseBtn = document.getAnonymousElementByAttribute(tab1, "anonid", "close-button");
+  let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
+  let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
+  tab2CloseBtn.click();
+  await tab1Closing;
+  await tab2Closing;
 
-    ok(tab1.closing, "Tab1 is closing");
-    ok(tab2.closing, "Tab2 is closing");
-    ok(!tab3.closing, "Tab3 is not closing");
-    is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
+  ok(tab1.closing, "Tab1 is closing");
+  ok(tab2.closing, "Tab2 is closing");
+  ok(!tab3.closing, "Tab3 is not closing");
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    BrowserTestUtils.removeTab(tab3);
+  BrowserTestUtils.removeTab(tab3);
 });
 
 add_task(async function usingTabContextMenu() {
-    let tab1 = await addTab();
-    let tab2 = await addTab();
-    let tab3 = await addTab();
-    let tab4 = await addTab();
+  let tab1 = await addTab();
+  let tab2 = await addTab();
+  let tab3 = await addTab();
+  let tab4 = await addTab();
 
-    let menuItemCloseTab = document.getElementById("context_closeTab");
-    let menuItemCloseSelectedTabs = document.getElementById("context_closeSelectedTabs");
+  let menuItemCloseTab = document.getElementById("context_closeTab");
+  let menuItemCloseSelectedTabs = document.getElementById("context_closeSelectedTabs");
 
-    is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    await BrowserTestUtils.switchTab(gBrowser, tab1);
-    await triggerClickOn(tab2, { ctrlKey: true });
+  await BrowserTestUtils.switchTab(gBrowser, tab1);
+  await triggerClickOn(tab2, { ctrlKey: true });
 
-    ok(tab1.multiselected, "Tab1 is multiselected");
-    ok(tab2.multiselected, "Tab2 is multiselected");
-    ok(!tab3.multiselected, "Tab3 is not multiselected");
-    ok(!tab4.multiselected, "Tab4 is not multiselected");
-    is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
+  ok(tab1.multiselected, "Tab1 is multiselected");
+  ok(tab2.multiselected, "Tab2 is multiselected");
+  ok(!tab3.multiselected, "Tab3 is not multiselected");
+  ok(!tab4.multiselected, "Tab4 is not multiselected");
+  is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
 
-    // Check the context menu with a non-multiselected tab
-    updateTabContextMenu(tab4);
-    is(menuItemCloseTab.hidden, false, "Close Tab is visible");
-    is(menuItemCloseSelectedTabs.hidden, true, "Close Selected Tabs is hidden");
+  // Check the context menu with a non-multiselected tab
+  updateTabContextMenu(tab4);
+  is(menuItemCloseTab.hidden, false, "Close Tab is visible");
+  is(menuItemCloseSelectedTabs.hidden, true, "Close Selected Tabs is hidden");
 
-    // Check the context menu with a multiselected tab
-    updateTabContextMenu(tab2);
-    is(menuItemCloseTab.hidden, true, "Close Tab is hidden");
-    is(menuItemCloseSelectedTabs.hidden, false, "Close Selected Tabs is visible");
+  // Check the context menu with a multiselected tab
+  updateTabContextMenu(tab2);
+  is(menuItemCloseTab.hidden, true, "Close Tab is hidden");
+  is(menuItemCloseSelectedTabs.hidden, false, "Close Selected Tabs is visible");
 
-    let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
-    let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
-    menuItemCloseSelectedTabs.click();
-    await tab1Closing;
-    await tab2Closing;
+  let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
+  let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
+  menuItemCloseSelectedTabs.click();
+  await tab1Closing;
+  await tab2Closing;
 
-    ok(tab1.closing, "Tab1 is closing");
-    ok(tab2.closing, "Tab2 is closing");
-    ok(!tab3.closing, "Tab3 is not closing");
-    ok(!tab4.closing, "Tab4 is not closing");
-    is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
+  ok(tab1.closing, "Tab1 is closing");
+  ok(tab2.closing, "Tab2 is closing");
+  ok(!tab3.closing, "Tab3 is not closing");
+  ok(!tab4.closing, "Tab4 is not closing");
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    BrowserTestUtils.removeTab(tab3);
-    BrowserTestUtils.removeTab(tab4);
+  BrowserTestUtils.removeTab(tab3);
+  BrowserTestUtils.removeTab(tab4);
 });
 
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_using_Ctrl.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_using_Ctrl.js
@@ -32,28 +32,29 @@ add_task(async function setPref() {
   });
 });
 
 add_task(async function clickWithPrefSet() {
   await SpecialPowers.pushPrefEnv({
     set: [[PREF_MULTISELECT_TABS, true]]
   });
 
-  let mSelectedTabs = gBrowser._multiSelectedTabsSet;
   const initialFocusedTab = await addTab();
   await BrowserTestUtils.switchTab(gBrowser, initialFocusedTab);
   const tab = await addTab();
 
   await triggerClickOn(tab, { ctrlKey: true });
-  ok(tab.multiselected && mSelectedTabs.has(tab), "Tab should be (multi) selected after click");
+  ok(tab.multiselected && gBrowser._multiSelectedTabsSet.has(tab),
+    "Tab should be (multi) selected after click");
   isnot(gBrowser.selectedTab, tab, "Multi-selected tab is not focused");
   is(gBrowser.selectedTab, initialFocusedTab, "Focused tab doesn't change");
 
   await triggerClickOn(tab, { ctrlKey: true });
-  ok(!tab.multiselected && !mSelectedTabs.has(tab), "Tab is not (multi) selected anymore");
+  ok(!tab.multiselected && !gBrowser._multiSelectedTabsSet.has(tab),
+    "Tab is not (multi) selected anymore");
   is(gBrowser.selectedTab, initialFocusedTab, "Focused tab still doesn't change");
 
   BrowserTestUtils.removeTab(initialFocusedTab);
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function clearSelection() {
   const tab1 = await addTab();
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
@@ -4,31 +4,29 @@ add_task(async function prefNotSet() {
     await SpecialPowers.pushPrefEnv({
         set: [[PREF_MULTISELECT_TABS, false]]
     });
 
     let tab1 = await addTab();
     let tab2 = await addTab();
     let tab3 = await addTab();
 
-    let mSelectedTabs = gBrowser._multiSelectedTabsSet;
-
     await BrowserTestUtils.switchTab(gBrowser, tab1);
 
     is(gBrowser.selectedTab, tab1, "Tab1 has focus now");
     is(gBrowser.multiSelectedTabsCount, 0, "No tab is mutli-selected");
 
     info("Click on tab3 while holding shift key");
     await BrowserTestUtils.switchTab(gBrowser, () => {
         triggerClickOn(tab3, { shiftKey: true });
     });
 
-    ok(!tab1.multiselected && !mSelectedTabs.has(tab1), "Tab1 is not multi-selected");
-    ok(!tab2.multiselected && !mSelectedTabs.has(tab2), "Tab2 is not multi-selected");
-    ok(!tab3.multiselected && !mSelectedTabs.has(tab3), "Tab3 is not multi-selected");
+    ok(!tab1.multiselected && !gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is not multi-selected");
+    ok(!tab2.multiselected && !gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is not multi-selected");
+    ok(!tab3.multiselected && !gBrowser._multiSelectedTabsSet.has(tab3), "Tab3 is not multi-selected");
     is(gBrowser.multiSelectedTabsCount, 0, "There is still no multi-selected tab");
     is(gBrowser.selectedTab, tab3, "Tab3 has focus now");
 
     BrowserTestUtils.removeTab(tab1);
     BrowserTestUtils.removeTab(tab2);
     BrowserTestUtils.removeTab(tab3);
 });
 
@@ -39,35 +37,33 @@ add_task(async function setPref() {
 });
 
 add_task(async function noItemsInTheCollectionBeforeShiftClicking() {
     let tab1 = await addTab();
     let tab2 = await addTab();
     let tab3 = await addTab();
     let tab4 = await addTab();
     let tab5 = await addTab();
-    let mSelectedTabs = gBrowser._multiSelectedTabsSet;
 
     await BrowserTestUtils.switchTab(gBrowser, tab1);
 
     is(gBrowser.selectedTab, tab1, "Tab1 has focus now");
     is(gBrowser.multiSelectedTabsCount, 0, "No tab is multi-selected");
 
     gBrowser.hideTab(tab3);
     ok(tab3.hidden, "Tab3 is hidden");
 
     info("Click on tab4 while holding shift key");
     await triggerClickOn(tab4, { shiftKey: true });
-    mSelectedTabs = gBrowser._multiSelectedTabsSet;
 
-    ok(tab1.multiselected && mSelectedTabs.has(tab1), "Tab1 is multi-selected");
-    ok(tab2.multiselected && mSelectedTabs.has(tab2), "Tab2 is multi-selected");
-    ok(!tab3.multiselected && !mSelectedTabs.has(tab3), "Hidden tab3 is not multi-selected");
-    ok(tab4.multiselected && mSelectedTabs.has(tab4), "Tab4 is multi-selected");
-    ok(!tab5.multiselected && !mSelectedTabs.has(tab5), "Tab5 is not multi-selected");
+    ok(tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is multi-selected");
+    ok(tab2.multiselected && gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is multi-selected");
+    ok(!tab3.multiselected && !gBrowser._multiSelectedTabsSet.has(tab3), "Hidden tab3 is not multi-selected");
+    ok(tab4.multiselected && gBrowser._multiSelectedTabsSet.has(tab4), "Tab4 is multi-selected");
+    ok(!tab5.multiselected && !gBrowser._multiSelectedTabsSet.has(tab5), "Tab5 is not multi-selected");
     is(gBrowser.multiSelectedTabsCount, 3, "three multi-selected tabs");
     is(gBrowser.selectedTab, tab1, "Tab1 still has focus");
 
     BrowserTestUtils.removeTab(tab1);
     BrowserTestUtils.removeTab(tab2);
     BrowserTestUtils.removeTab(tab3);
     BrowserTestUtils.removeTab(tab4);
     BrowserTestUtils.removeTab(tab5);
@@ -75,51 +71,47 @@ add_task(async function noItemsInTheColl
 
 add_task(async function itemsInTheCollectionBeforeShiftClicking() {
     let tab1 = await addTab();
     let tab2 = await addTab();
     let tab3 = await addTab();
     let tab4 = await addTab();
     let tab5 = await addTab();
 
-    let mSelectedTabs = gBrowser._multiSelectedTabsSet;
-
     await BrowserTestUtils.switchTab(gBrowser, () => triggerClickOn(tab1, {}));
 
     is(gBrowser.selectedTab, tab1, "Tab1 has focus now");
     is(gBrowser.multiSelectedTabsCount, 0, "No tab is multi-selected");
 
     await triggerClickOn(tab3, { ctrlKey: true });
     is(gBrowser.selectedTab, tab1, "Tab1 still has focus");
     is(gBrowser.multiSelectedTabsCount, 2, "Two tabs are multi-selected");
-    ok(tab1.multiselected && mSelectedTabs.has(tab1), "Tab1 is multi-selected");
-    ok(tab3.multiselected && mSelectedTabs.has(tab3), "Tab3 is multi-selected");
+    ok(tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is multi-selected");
+    ok(tab3.multiselected && gBrowser._multiSelectedTabsSet.has(tab3), "Tab3 is multi-selected");
 
     info("Click on tab5 while holding Shift key");
-    await triggerClickOn(tab5, { shiftKey: true });
-    mSelectedTabs = gBrowser._multiSelectedTabsSet;
+    await BrowserTestUtils.switchTab(gBrowser, triggerClickOn(tab5, { shiftKey: true }));
 
     is(gBrowser.selectedTab, tab3, "Tab3 has focus");
-    ok(!tab1.multiselected && !mSelectedTabs.has(tab1), "Tab1 is not multi-selected");
-    ok(!tab2.multiselected && !mSelectedTabs.has(tab2), "Tab2 is not multi-selected ");
-    ok(tab3.multiselected && mSelectedTabs.has(tab3), "Tab3 is multi-selected");
-    ok(tab4.multiselected && mSelectedTabs.has(tab4), "Tab4 is multi-selected");
-    ok(tab5.multiselected && mSelectedTabs.has(tab5), "Tab5 is multi-selected");
+    ok(!tab1.multiselected && !gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is not multi-selected");
+    ok(!tab2.multiselected && !gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is not multi-selected ");
+    ok(tab3.multiselected && gBrowser._multiSelectedTabsSet.has(tab3), "Tab3 is multi-selected");
+    ok(tab4.multiselected && gBrowser._multiSelectedTabsSet.has(tab4), "Tab4 is multi-selected");
+    ok(tab5.multiselected && gBrowser._multiSelectedTabsSet.has(tab5), "Tab5 is multi-selected");
     is(gBrowser.multiSelectedTabsCount, 3, "Three tabs are multi-selected");
 
     info("Click on tab1 while holding Shift key");
     await triggerClickOn(tab1, { shiftKey: true });
-    mSelectedTabs = gBrowser._multiSelectedTabsSet;
 
     is(gBrowser.selectedTab, tab3, "Tab3 has focus");
-    ok(tab1.multiselected && mSelectedTabs.has(tab1), "Tab1 is multi-selected");
-    ok(tab2.multiselected && mSelectedTabs.has(tab2), "Tab2 is multi-selected ");
-    ok(tab3.multiselected && mSelectedTabs.has(tab3), "Tab3 is multi-selected");
-    ok(!tab4.multiselected && !mSelectedTabs.has(tab4), "Tab4 is not multi-selected");
-    ok(!tab5.multiselected && !mSelectedTabs.has(tab5), "Tab5 is not multi-selected");
+    ok(tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is multi-selected");
+    ok(tab2.multiselected && gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is multi-selected ");
+    ok(tab3.multiselected && gBrowser._multiSelectedTabsSet.has(tab3), "Tab3 is multi-selected");
+    ok(!tab4.multiselected && !gBrowser._multiSelectedTabsSet.has(tab4), "Tab4 is not multi-selected");
+    ok(!tab5.multiselected && !gBrowser._multiSelectedTabsSet.has(tab5), "Tab5 is not multi-selected");
     is(gBrowser.multiSelectedTabsCount, 3, "Three tabs are multi-selected");
 
     BrowserTestUtils.removeTab(tab1);
     BrowserTestUtils.removeTab(tab2);
     BrowserTestUtils.removeTab(tab3);
     BrowserTestUtils.removeTab(tab4);
     BrowserTestUtils.removeTab(tab5);
 });
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift_and_Ctrl.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift_and_Ctrl.js
@@ -52,17 +52,17 @@ add_task(async function selectionWithCtr
   const tab4 = await addTab();
   const tab5 = await addTab();
 
   await BrowserTestUtils.switchTab(gBrowser, tab1);
 
   is(gBrowser.multiSelectedTabsCount, 0, "No tab is multi-selected");
 
   info("Click on tab3 with Ctrl key down");
-  await triggerClickOn(tab5, { ctrlKey: true });
+  await triggerClickOn(tab3, { ctrlKey: true });
 
   is(gBrowser.selectedTab, tab1, "Tab1 has focus");
   ok(tab1.multiselected, "Tab1 is multi-selected");
   ok(!tab2.multiselected, "Tab2 is not multi-selected ");
   ok(tab3.multiselected, "Tab3 is multi-selected");
   ok(!tab4.multiselected, "Tab4 is not multi-selected");
   ok(!tab5.multiselected, "Tab5 is not multi-selected");
   is(gBrowser.multiSelectedTabsCount, 2, "Two tabs are multi-selected");