Bug 1495975 - Maintain visual order when unpinning multiple tabs. r=Felipe
authorJared Wein <jwein@mozilla.com>
Wed, 03 Oct 2018 20:05:01 +0000
changeset 495203 0dbaf8bd2ef7a627d53bd359473d2871133508c9
parent 495202 ab9ffb1f10de16b60fba405774c91688337efe66
child 495204 b907c5ebc96daca674c0baefad7afa07a81714f2
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1495975
milestone64.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 1495975 - Maintain visual order when unpinning multiple tabs. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D7572
browser/base/content/tabbrowser.js
browser/base/content/test/tabs/browser_multiselect_tabs_pin_unpin.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -4016,18 +4016,23 @@ window._gBrowser = {
 
   pinMultiSelectedTabs() {
     for (let tab of this.selectedTabs) {
         this.pinTab(tab);
     }
   },
 
   unpinMultiSelectedTabs() {
-    for (let tab of this.selectedTabs) {
-        this.unpinTab(tab);
+    // The selectedTabs getter returns the tabs
+    // in visual order. We need to unpin in reverse
+    // order to maintain visual order.
+    let selectedTabs = this.selectedTabs;
+    for (let i = selectedTabs.length - 1; i >= 0; i--) {
+      let tab = selectedTabs[i];
+      this.unpinTab(tab);
     }
   },
 
   activateBrowserForPrintPreview(aBrowser) {
     this._printPreviewBrowsers.add(aBrowser);
     if (this._switcher) {
       this._switcher.activateBrowserForPrintPreview(aBrowser);
     }
--- a/browser/base/content/test/tabs/browser_multiselect_tabs_pin_unpin.js
+++ b/browser/base/content/test/tabs/browser_multiselect_tabs_pin_unpin.js
@@ -2,28 +2,27 @@ const PREF_MULTISELECT_TABS = "browser.t
 
 add_task(async function setPref() {
     await SpecialPowers.pushPrefEnv({
         set: [[PREF_MULTISELECT_TABS, true]],
     });
 });
 
 add_task(async function test() {
-    let tab1 = await addTab();
+    let tab1 = gBrowser.selectedTab;
     let tab2 = await addTab();
     let tab3 = await addTab();
 
     let menuItemPinTab = document.getElementById("context_pinTab");
     let menuItemUnpinTab = document.getElementById("context_unpinTab");
     let menuItemPinSelectedTabs = document.getElementById("context_pinSelectedTabs");
     let menuItemUnpinSelectedTabs = document.getElementById("context_unpinSelectedTabs");
 
     is(gBrowser.multiSelectedTabsCount, 0, "Zero multiselected tabs");
 
-    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");
 
     // Check the context menu with a non-multiselected tab
     updateTabContextMenu(tab3);
@@ -45,16 +44,19 @@ add_task(async function test() {
     let tab2Pinned = BrowserTestUtils.waitForEvent(tab2, "TabPinned");
     menuItemPinSelectedTabs.click();
     await tab1Pinned;
     await tab2Pinned;
 
     ok(tab1.pinned, "Tab1 is pinned");
     ok(tab2.pinned, "Tab2 is pinned");
     ok(!tab3.pinned, "Tab3 is unpinned");
+    is(tab1._tPos, 0, "Tab1 should still be first after pinning");
+    is(tab2._tPos, 1, "Tab2 should still be second after pinning");
+    is(tab3._tPos, 2, "Tab3 should still be third after pinning");
 
     // Check the context menu with a multiselected and pinned tab
     updateTabContextMenu(tab2);
     ok(tab2.pinned, "Tab2 is pinned");
     is(menuItemPinTab.hidden, true, "Pin Tab is hidden");
     is(menuItemUnpinTab.hidden, true, "Unpin Tab is hidden");
     is(menuItemPinSelectedTabs.hidden, true, "Pin Selected Tabs is hidden");
     is(menuItemUnpinSelectedTabs.hidden, false, "Unpin Selected Tabs is visible");
@@ -63,13 +65,15 @@ add_task(async function test() {
     let tab2Unpinned = BrowserTestUtils.waitForEvent(tab2, "TabUnpinned");
     menuItemUnpinSelectedTabs.click();
     await tab1Unpinned;
     await tab2Unpinned;
 
     ok(!tab1.pinned, "Tab1 is unpinned");
     ok(!tab2.pinned, "Tab2 is unpinned");
     ok(!tab3.pinned, "Tab3 is unpinned");
+    is(tab1._tPos, 0, "Tab1 should still be first after unpinning");
+    is(tab2._tPos, 1, "Tab2 should still be second after unpinning");
+    is(tab3._tPos, 2, "Tab3 should still be third after unpinning");
 
-    BrowserTestUtils.removeTab(tab1);
     BrowserTestUtils.removeTab(tab2);
     BrowserTestUtils.removeTab(tab3);
 });