diff --git a/mobile/chrome/content/browser-ui.js b/mobile/chrome/content/browser-ui.js index 33afb53eb13..bbed46116d5 100644 --- a/mobile/chrome/content/browser-ui.js +++ b/mobile/chrome/content/browser-ui.js @@ -880,6 +880,8 @@ var BrowserUI = { if (browser.canGoBack) { browser.goBack(); } else if (tab.owner) { + // When going back, always return to the owner (not a sibling). + Browser.selectedTab = tab.owner; this.closeTab(tab); } #ifdef ANDROID diff --git a/mobile/chrome/content/browser.js b/mobile/chrome/content/browser.js index bf24e418955..f7d6fe4b89f 100644 --- a/mobile/chrome/content/browser.js +++ b/mobile/chrome/content/browser.js @@ -717,7 +717,12 @@ var Browser = { let nextTab = this._selectedTab; if (nextTab == aTab) { - nextTab = aTab.owner || this.getTabAtIndex(tabIndex + 1) || this.getTabAtIndex(tabIndex - 1); + nextTab = this.getTabAtIndex(tabIndex + 1) || this.getTabAtIndex(tabIndex - 1); + + // If the next tab is not a sibling, switch back to the parent. + if (aTab.owner && nextTab.owner != aTab.owner) + nextTab = aTab.owner; + if (!nextTab) return null; } diff --git a/mobile/chrome/tests/browser_tabs.js b/mobile/chrome/tests/browser_tabs.js index 21fa73660eb..e08fb5e7854 100644 --- a/mobile/chrome/tests/browser_tabs.js +++ b/mobile/chrome/tests/browser_tabs.js @@ -83,6 +83,8 @@ function tab_switch_02() { //Add new tab new_tab_03 = Browser.addTab(testURL_03, true, new_tab_01); + new_tab_04 = Browser.addTab(testURL_03, false, new_tab_01); + checkExpectedSize(); new_tab_03.browser.addEventListener("load", tab_switch_03, true); } @@ -93,7 +95,11 @@ function tab_switch_03() { is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser"); Browser.closeTab(new_tab_03, { forceClose: true }); - is(Browser.selectedTab, new_tab_01, "Closing tab 03 returns to owner"); + is(Browser.selectedTab, new_tab_04, "Closing tab 03 goes to sibling"); + is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser"); + + Browser.closeTab(new_tab_04, { forceClose: true }); + is(Browser.selectedTab, new_tab_01, "Closing tab 04 returns to owner"); is(Browser.selectedTab.notification, Elements.browsers.selectedPanel, "Deck has correct browser"); new_tab_03 = Browser.addTab(testURL_03, true, new_tab_01);