Bug 1468443 - Consider the 'active tab'(gBrowser.selectedTab) as part of the multi-selection by default. r=jaws
authorAbdoulaye O. Ly <ablayelyfondou@gmail.com>
Wed, 20 Jun 2018 19:53:51 +0000
changeset 480090 d0f2ca34fbfb76f3bf3c3e684b1242ed527c207b
parent 480089 f6f3c67e4d33c0842fb716f65f27a178ed882768
child 480091 90e54fb8d5a8fe2d0cd80ecbb3b3aa2813eaf6c7
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1468443
milestone62.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 1468443 - Consider the 'active tab'(gBrowser.selectedTab) as part of the multi-selection by default. r=jaws MozReview-Commit-ID: DZAhZ7iQqFl
browser/base/content/tabbrowser.xml
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_multiselect_tabs_active_tab_selected_by_default.js
browser/base/content/test/tabs/browser_multiselect_tabs_close.js
browser/base/content/test/tabs/browser_multiselect_tabs_close_using_shortcuts.js
browser/base/content/test/tabs/browser_multiselect_tabs_using_Ctrl.js
browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2002,18 +2002,23 @@
             gBrowser.addRangeToMultiSelectedTabs(lastSelectedTab, this);
             gBrowser.lastMultiSelectedTab = this;
             return;
           }
           if (event.getModifierState("Accel")) {
             // Ctrl (Cmd for mac) key is pressed
             if (this.multiselected) {
               gBrowser.removeFromMultiSelectedTabs(this);
-            } else {
-              gBrowser.addToMultiSelectedTabs(this);
+              if (this == gBrowser.selectedTab) {
+                gBrowser.selectedTab = gBrowser.lastMultiSelectedTab;
+              }
+            } else if (this != gBrowser.selectedTab) {
+              for (let tab of [this, gBrowser.selectedTab]) {
+                gBrowser.addToMultiSelectedTabs(tab);
+              }
               gBrowser.lastMultiSelectedTab = this;
             }
             return;
           }
 
           const overCloseButton = event.originalTarget.getAttribute("anonid") == "close-button";
           if (gBrowser.multiSelectedTabsCount > 0 && !overCloseButton && !this._overPlayingIcon) {
             // Tabs were previously multi-selected and user clicks on a tab
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -49,8 +49,9 @@ skip-if = (debug && os == 'mac') || (deb
 [browser_multiselect_tabs_using_Shift.js]
 [browser_multiselect_tabs_close.js]
 [browser_multiselect_tabs_positional_attrs.js]
 [browser_multiselect_tabs_close_using_shortcuts.js]
 [browser_multiselect_tabs_mute_unmute.js]
 support-files =
   ../general/audio.ogg
   ../general/file_mediaPlayback.html
+[browser_multiselect_tabs_active_tab_selected_by_default.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_active_tab_selected_by_default.js
@@ -0,0 +1,49 @@
+const PREF_MULTISELECT_TABS = "browser.tabs.multiselect";
+
+add_task(async function multiselectActiveTabByDefault() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_MULTISELECT_TABS, true]]
+  });
+
+  const tab1 = await addTab();
+  const tab2 = await addTab();
+  const tab3 = await addTab();
+
+  await BrowserTestUtils.switchTab(gBrowser, tab1);
+
+  info("Try multiselecting Tab1 (active) with click+CtrlKey");
+  await triggerClickOn(tab1, { ctrlKey: true });
+
+  is(gBrowser.selectedTab, tab1, "Tab1 is active");
+  ok(!tab1.multiselected,
+    "Tab1 is not multi-selected because we are not in multi-select context yet");
+  ok(!tab2.multiselected, "Tab2 is not multi-selected");
+  ok(!tab3.multiselected, "Tab3 is not multi-selected");
+  is(gBrowser.multiSelectedTabsCount, 0, "Zero tabs multi-selected");
+
+  info("We multi-select tab1 and tab2 with ctrl key down");
+  await triggerClickOn(tab2, { ctrlKey: true });
+  await triggerClickOn(tab3, { ctrlKey: true });
+
+  is(gBrowser.selectedTab, tab1, "Tab1 is active");
+  ok(tab1.multiselected, "Tab1 is multi-selected");
+  ok(tab2.multiselected, "Tab2 is multi-selected");
+  ok(tab3.multiselected, "Tab3 is multi-selected");
+  is(gBrowser.multiSelectedTabsCount, 3, "Three tabs multi-selected");
+  is(gBrowser.lastMultiSelectedTab, tab3, "Tab3 is the last multi-selected tab");
+
+  info("Unselect tab1 from multi-selection using ctrlKey");
+
+  await BrowserTestUtils.switchTab(gBrowser, triggerClickOn(tab1, { ctrlKey: true }));
+
+  isnot(gBrowser.selectedTab, tab1, "Tab1 is not active anymore");
+  is(gBrowser.selectedTab, tab3, "Tab3 is active");
+  ok(!tab1.multiselected, "Tab1 is not multi-selected");
+  ok(tab2.multiselected, "Tab2 is multi-selected");
+  ok(tab3.multiselected, "Tab3 is multi-selected");
+  is(gBrowser.multiSelectedTabsCount, 2, "Two tabs multi-selected");
+
+  BrowserTestUtils.removeTab(tab1);
+  BrowserTestUtils.removeTab(tab2);
+  BrowserTestUtils.removeTab(tab3);
+});
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close.js
@@ -13,17 +13,17 @@ add_task(async function setPref() {
 add_task(async function usingTabCloseButton() {
     let tab1 = await addTab();
     let tab2 = await addTab();
     let tab3 = await addTab();
     let tab4 = await addTab();
 
     is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    await triggerClickOn(tab1, { 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");
 
@@ -64,17 +64,17 @@ add_task(async function usingTabContextM
     let tab3 = await addTab();
     let tab4 = await addTab();
 
     let menuItemCloseTab = document.getElementById("context_closeTab");
     let menuItemCloseSelectedTabs = document.getElementById("context_closeSelectedTabs");
 
     is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    await triggerClickOn(tab1, { 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");
 
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_close_using_shortcuts.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_close_using_shortcuts.js
@@ -19,49 +19,50 @@ add_task(async function using_Ctrl_W() {
 
     await BrowserTestUtils.switchTab(gBrowser, triggerClickOn(tab1, {}));
 
     is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
     await triggerClickOn(tab2, { ctrlKey: true });
     await triggerClickOn(tab3, { ctrlKey: true });
 
-    is(gBrowser.selectedTab, tab1, "Tab1 is focused");
-    ok(!tab1.multiselected, "Tab1 is not multiselected");
+    ok(tab1.multiselected, "Tab1 is multiselected");
     ok(tab2.multiselected, "Tab2 is multiselected");
     ok(tab3.multiselected, "Tab3 is multiselected");
     ok(!tab4.multiselected, "Tab4 is not multiselected");
-    is(gBrowser.multiSelectedTabsCount, 2, "Two multiselected tabs");
+    is(gBrowser.multiSelectedTabsCount, 3, "Three multiselected tabs");
 
+    let tab1Closing = BrowserTestUtils.waitForTabClosing(tab1);
     let tab2Closing = BrowserTestUtils.waitForTabClosing(tab2);
     let tab3Closing = BrowserTestUtils.waitForTabClosing(tab3);
 
     EventUtils.synthesizeKey(key, { accelKey: true });
 
     // On OSX, Cmd+F4 should not close tabs.
     const shouldBeClosing = key == "w" || AppConstants.platform != "macosx";
 
     if (shouldBeClosing) {
+      await tab1Closing;
       await tab2Closing;
       await tab3Closing;
     }
 
-    is(gBrowser.selectedTab, tab1, "Tab1 is still focused");
-    ok(!tab1.closing, "Tab1 is not closing");
     ok(!tab4.closing, "Tab4 is not closing");
 
     if (shouldBeClosing) {
+      ok(tab1.closing, "Tab1 is closing");
       ok(tab2.closing, "Tab2 is closing");
       ok(tab3.closing, "Tab3 is closing");
       is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
     } else {
+      ok(!tab1.closing, "Tab1 is not closing");
       ok(!tab2.closing, "Tab2 is not closing");
       ok(!tab3.closing, "Tab3 is not closing");
-      is(gBrowser.multiSelectedTabsCount, 2, "Still Two multiselected tabs");
+      is(gBrowser.multiSelectedTabsCount, 3, "Still Three multiselected tabs");
 
+      BrowserTestUtils.removeTab(tab1);
       BrowserTestUtils.removeTab(tab2);
       BrowserTestUtils.removeTab(tab3);
     }
 
-    BrowserTestUtils.removeTab(tab1);
     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
@@ -25,44 +25,46 @@ add_task(async function clickWithoutPref
 add_task(async function clickWithPrefSet() {
   await SpecialPowers.pushPrefEnv({
     set: [
       [PREF_MULTISELECT_TABS, true]
     ]
   });
 
   let mSelectedTabs = gBrowser._multiSelectedTabsSet;
-  const initialFocusedTab = gBrowser.selectedTab;
+  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");
   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");
   is(gBrowser.selectedTab, initialFocusedTab, "Focused tab still doesn't change");
 
+  BrowserTestUtils.removeTab(initialFocusedTab);
   BrowserTestUtils.removeTab(tab);
 });
 
 add_task(async function clearSelection() {
   await SpecialPowers.pushPrefEnv({
     set: [
       [PREF_MULTISELECT_TABS, true]
     ]
   });
 
   const tab1 = await addTab();
   const tab2 = await addTab();
   const tab3 = await addTab();
 
-  info("We multi-select tab1 and tab2 with ctrl key down");
-  await triggerClickOn(tab1, { ctrlKey: true });
+  await BrowserTestUtils.switchTab(gBrowser, tab1);
+  info("We multi-select tab2 with ctrl key down");
   await triggerClickOn(tab2, { ctrlKey: true });
 
   ok(tab1.multiselected && gBrowser._multiSelectedTabsSet.has(tab1), "Tab1 is (multi) selected");
   ok(tab2.multiselected && gBrowser._multiSelectedTabsSet.has(tab2), "Tab2 is (multi) selected");
   is(gBrowser.multiSelectedTabsCount, 2, "Two tabs (multi) selected");
   isnot(tab3, gBrowser.selectedTab, "Tab3 doesn't have focus");
 
   info("We select tab3 with Ctrl key up");
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_using_Shift.js
@@ -81,29 +81,30 @@ add_task(async function itemsInTheCollec
 
     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, 1, "One tab is multi-selected");
+    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");
 
     info("Click on tab5 while holding Shift key");
     await triggerClickOn(tab5, { shiftKey: true });
 
     is(gBrowser.selectedTab, tab1, "Tab1 still has focus");
-    ok(!tab1.multiselected && !mSelectedTabs.has(tab1), "Tab1 is not multi-selected");
+    ok(tab1.multiselected && mSelectedTabs.has(tab1), "Tab1 is 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");
-    is(gBrowser.multiSelectedTabsCount, 3, "Three tabs are multi-selected");
+    is(gBrowser.multiSelectedTabsCount, 4, "Four tabs are multi-selected");
 
     BrowserTestUtils.removeTab(tab1);
     BrowserTestUtils.removeTab(tab2);
     BrowserTestUtils.removeTab(tab3);
     BrowserTestUtils.removeTab(tab4);
     BrowserTestUtils.removeTab(tab5);
 });