diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js index 94b62b6f06d2..813cbcf65277 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -5865,7 +5865,7 @@ nextTab.group.after(selectedTab); } else { // Enter first position of tab group. - nextTab.group.prepend(selectedTab); + nextTab.group.insertBefore(selectedTab, nextTab); } } else if (selectedTab.group != nextTab.group) { // Standalone tab after tab group. @@ -5874,6 +5874,10 @@ nextTab.after(selectedTab); } }); + } else if (selectedTab.group) { + // selectedTab is the last tab and is grouped. + // remove it from its group. + selectedTab.group.after(selectedTab); } } @@ -5902,6 +5906,10 @@ previousTab.before(selectedTab); } }); + } else if (selectedTab.group) { + // selectedTab is the first tab and is grouped. + // remove it from its group. + selectedTab.group.before(selectedTab); } } diff --git a/browser/components/tabbrowser/test/browser/tabs/browser_tab_move_active_tab.js b/browser/components/tabbrowser/test/browser/tabs/browser_tab_move_active_tab.js index eeff3c2225cc..f93ac098a95e 100644 --- a/browser/components/tabbrowser/test/browser/tabs/browser_tab_move_active_tab.js +++ b/browser/components/tabbrowser/test/browser/tabs/browser_tab_move_active_tab.js @@ -144,8 +144,6 @@ add_task(async function test_moveTabForwardTabGroups() { let tab2 = BrowserTestUtils.addTab(gBrowser, "about:blank"); let tab3 = BrowserTestUtils.addTab(gBrowser, "about:blank"); let tab4 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab5 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab6 = BrowserTestUtils.addTab(gBrowser, "about:blank"); let group1 = gBrowser.addTabGroup([tab3], { insertBefore: tab3 }); let group2 = gBrowser.addTabGroup([tab4], { insertBefore: tab4 }); gBrowser.selectedTab = tab1; @@ -156,8 +154,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 2], [tab3, 3], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.ok(!tab1.group, "tab1 should not be in a tab group"); @@ -168,8 +164,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 3], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.ok(!tab1.group, "tab1 should not be in a tab group"); @@ -180,10 +174,13 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 3], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.equal(tab1.group, group1, "tab1 should be in group1"); + Assert.equal( + tab1.group.firstChild.className, + "tab-group-label-container", + "Group label appears before the first group tab" + ); gBrowser.moveTabForward(); info("selected tab should move to the end of group1"); @@ -192,8 +189,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 2], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.equal(tab1.group, group1, "tab1 should still be in group1"); @@ -204,8 +199,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 2], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.ok(!tab1.group, "tab1 should no longer be in a group"); @@ -216,8 +209,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 2], [tab4, 4], - [tab5, 5], - [tab6, 6], ]); Assert.equal(tab1.group, group2, "tab1 should now be in group2"); @@ -228,8 +219,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 2], [tab4, 3], - [tab5, 5], - [tab6, 6], ]); Assert.equal(tab1.group, group2, "tab1 should still be in group2"); @@ -240,8 +229,6 @@ add_task(async function test_moveTabForwardTabGroups() { [tab2, 1], [tab3, 2], [tab4, 3], - [tab5, 5], - [tab6, 6], ]); Assert.ok(!tab1.group, "tab1 should no longer be in a group"); @@ -249,8 +236,6 @@ add_task(async function test_moveTabForwardTabGroups() { await removeTabGroup(group2); BrowserTestUtils.removeTab(tab1); BrowserTestUtils.removeTab(tab2); - BrowserTestUtils.removeTab(tab5); - BrowserTestUtils.removeTab(tab6); }); /* TODO Bug 1927844 for moving the active tab around collapsed tab groups */ @@ -400,117 +385,93 @@ add_task(async function test_moveTabBackwardPinnedTabs() { }); add_task(async function test_moveTabBackwardTabGroups() { - let tab1 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab2 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab3 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab4 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab5 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let tab6 = BrowserTestUtils.addTab(gBrowser, "about:blank"); - let group1 = gBrowser.addTabGroup([tab3], { insertBefore: tab3 }); - let group2 = gBrowser.addTabGroup([tab4], { insertBefore: tab4 }); - gBrowser.selectedTab = tab6; + let win = await BrowserTestUtils.openNewBrowserWindow(); + let tab1 = win.gBrowser.tabs[0]; + let tab2 = BrowserTestUtils.addTab(win.gBrowser, "about:blank"); + let tab3 = BrowserTestUtils.addTab(win.gBrowser, "about:blank"); + let tab4 = BrowserTestUtils.addTab(win.gBrowser, "about:blank"); + let group1 = win.gBrowser.addTabGroup([tab1], { insertBefore: tab1 }); + let group2 = win.gBrowser.addTabGroup([tab3], { insertBefore: tab3 }); + win.gBrowser.selectedTab = tab4; info("validate the starting order of the tabs"); assertTabIndexesMatch([ - [tab1, 1], - [tab2, 2], - [tab3, 3], - [tab4, 4], - [tab5, 5], - [tab6, 6], + [tab1, 0], + [tab2, 1], + [tab3, 2], + [tab4, 3], ]); - Assert.ok(!tab6.group, "tab6 should not be in a tab group"); + Assert.ok(!tab4.group, "tab4 should not be in a tab group"); - gBrowser.moveTabBackward(); - info("last two tabs should switch places"); - assertTabIndexesMatch([ - [tab1, 1], - [tab2, 2], - [tab3, 3], - [tab4, 4], - [tab5, 6], - [tab6, 5], - ]); - Assert.ok(!tab6.group, "tab6 should not be in a tab group"); - - gBrowser.moveTabBackward(); + win.gBrowser.moveTabBackward(); info("selected tab should move into the end of group2"); assertTabIndexesMatch([ - [tab1, 1], - [tab2, 2], - [tab3, 3], - [tab4, 4], - [tab5, 6], - [tab6, 5], + [tab1, 0], + [tab2, 1], + [tab3, 2], + [tab4, 3], ]); - Assert.equal(tab6.group, group2, "tab6 should be in group2"); + Assert.equal(tab4.group, group2, "tab4 should be in group2"); - gBrowser.moveTabBackward(); + win.gBrowser.moveTabBackward(); info("selected tab should move to the start of group2"); assertTabIndexesMatch([ - [tab1, 1], - [tab2, 2], + [tab1, 0], + [tab2, 1], [tab3, 3], - [tab4, 5], - [tab5, 6], - [tab6, 4], + [tab4, 2], ]); - Assert.equal(tab6.group, group2, "tab6 should still be in group2"); + Assert.equal(tab4.group, group2, "tab4 should still be in group2"); - gBrowser.moveTabBackward(); + win.gBrowser.moveTabBackward(); info("selected tab should become a standalone tab between group1 and group2"); assertTabIndexesMatch([ - [tab1, 1], - [tab2, 2], + [tab1, 0], + [tab2, 1], [tab3, 3], - [tab4, 5], - [tab5, 6], - [tab6, 4], + [tab4, 2], ]); - Assert.ok(!tab6.group, "tab6 should no longer be in a group"); + Assert.ok(!tab4.group, "tab4 should no longer be in a group"); + + win.gBrowser.moveTabBackward(); + info("tab should be in between groups. next move should group it."); + win.gBrowser.moveTabBackward(); - gBrowser.moveTabBackward(); info("selected tab should move into the end of group1"); assertTabIndexesMatch([ - [tab1, 1], + [tab1, 0], [tab2, 2], [tab3, 3], - [tab4, 5], - [tab5, 6], - [tab6, 4], + [tab4, 1], ]); - Assert.equal(tab6.group, group1, "tab6 should now be in group1"); - gBrowser.moveTabBackward(); + Assert.equal(tab4.group, group1, "tab4 should now be in group1"); + win.gBrowser.moveTabBackward(); + info("selected tab should move to the start of group1"); assertTabIndexesMatch([ [tab1, 1], [tab2, 2], - [tab3, 4], - [tab4, 5], - [tab5, 6], - [tab6, 3], + [tab3, 3], + [tab4, 0], ]); - Assert.equal(tab6.group, group1, "tab6 should still be in group2"); + Assert.equal(tab4.group, group1, "tab4 should still be in group1"); - gBrowser.moveTabBackward(); + win.gBrowser.moveTabBackward(); info("selected tab should become a standalone tab before group1"); assertTabIndexesMatch([ [tab1, 1], [tab2, 2], - [tab3, 4], - [tab4, 5], - [tab5, 6], - [tab6, 3], + [tab3, 3], + [tab4, 0], ]); - Assert.ok(!tab6.group, "tab6 should no longer be in a group"); + Assert.ok(!tab4.group, "tab4 should no longer be in a group"); await removeTabGroup(group1); await removeTabGroup(group2); - BrowserTestUtils.removeTab(tab1); BrowserTestUtils.removeTab(tab2); - BrowserTestUtils.removeTab(tab5); - BrowserTestUtils.removeTab(tab6); + BrowserTestUtils.removeTab(tab4); + await BrowserTestUtils.closeWindow(win); }); /* TODO Bug 1927844 for moving the active tab around collapsed tab groups */