Bug 533232 - closing tab to the right of its parent should select the parent, not the next tab on the right. r=mano a=dietrich
authorDão Gottwald <dao@mozilla.com>
Mon, 06 Sep 2010 11:39:59 +0200
changeset 52075 67aef7ffb282d501bc62c1342ec601e905e27880
parent 52074 b07b23448a2d28f77ba79461be8b81d2a6fcbc45
child 52076 a8dc1f514e9ba336e132b25672c680b6e758614b
push idunknown
push userunknown
push dateunknown
reviewersmano, dietrich
bugs533232
milestone2.0b6pre
first release with
nightly linux32
67aef7ffb282 / 4.0b6pre / 20100906030528 / files
nightly linux64
67aef7ffb282 / 4.0b6pre / 20100906031217 / files
nightly mac
67aef7ffb282 / 4.0b6pre / 20100906031014 / files
nightly win32
67aef7ffb282 / 4.0b6pre / 20100906041818 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 533232 - closing tab to the right of its parent should select the parent, not the next tab on the right. r=mano a=dietrich
browser/base/content/tabbrowser.xml
browser/base/content/test/Makefile.in
browser/base/content/test/browser_bug533232.js
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -753,17 +753,21 @@
               return;
 
             var oldTab = this.mCurrentTab;
 
             // Preview mode should not reset the owner
             if (!this._previewMode && oldTab != this.selectedTab)
               oldTab.owner = null;
 
-            this._lastRelatedTab = null;
+            if (this._lastRelatedTab) {
+              if (this._lastRelatedTab != this.selectedTab)
+                this._lastRelatedTab.owner = null;
+              this._lastRelatedTab = null;
+            }
 
             var oldBrowser = this.mCurrentBrowser;
             if (oldBrowser) {
               oldBrowser.setAttribute("type", "content-targetable");
               oldBrowser.docShell.isActive = false;
             }
 
             var updatePageReport = false;
@@ -1247,16 +1251,20 @@
             // move it to after the current tab.
             // aReferrerURI is null or undefined if the tab is opened from
             // an external application or bookmark, i.e. somewhere other
             // than the current tab.
             if ((aRelatedToCurrent == null ? aReferrerURI : aRelatedToCurrent) &&
                 Services.prefs.getBoolPref("browser.tabs.insertRelatedAfterCurrent")) {
               let newTabPos = (this._lastRelatedTab ||
                                this.selectedTab)._tPos + 1;
+              if (this._lastRelatedTab)
+                this._lastRelatedTab.owner = null;
+              else
+                t.owner = this.selectedTab;
               this.moveTabTo(t, newTabPos);
               this._lastRelatedTab = t;
             }
 
             return t;
           ]]>
         </body>
       </method>
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -127,16 +127,17 @@ endif
                  browser_bug481560.js \
                  browser_bug484315.js \
                  browser_bug491431.js \
                  browser_bug495058.js \
                  browser_bug517902.js \
                  browser_bug519216.js \
                  browser_bug520538.js \
                  browser_bug521216.js \
+                 browser_bug533232.js \
                  browser_bug537474.js \
                  browser_bug550565.js \
                  browser_bug553455.js \
                  browser_bug555224.js \
                  browser_bug555767.js \
                  browser_bug556061.js \
                  browser_bug559991.js \
                  browser_bug561623.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_bug533232.js
@@ -0,0 +1,36 @@
+function test() {
+  var tab1 = gBrowser.selectedTab;
+  var tab2 = gBrowser.addTab();
+  var childTab1;
+  var childTab2;
+
+  childTab1 = gBrowser.addTab("about:blank", { relatedToCurrent: true });
+  gBrowser.selectedTab = childTab1;
+  gBrowser.removeCurrentTab();
+  is(idx(gBrowser.selectedTab), idx(tab1),
+     "closing a tab next to its parent selects the parent");
+
+  childTab1 = gBrowser.addTab("about:blank", { relatedToCurrent: true });
+  gBrowser.selectedTab = tab2;
+  gBrowser.selectedTab = childTab1;
+  gBrowser.removeCurrentTab();
+  is(idx(gBrowser.selectedTab), idx(tab2),
+     "closing a tab next to its parent doesn't select the parent if another tab had been selected ad interim");
+
+  gBrowser.selectedTab = tab1;
+  childTab1 = gBrowser.addTab("about:blank", { relatedToCurrent: true });
+  childTab2 = gBrowser.addTab("about:blank", { relatedToCurrent: true });
+  gBrowser.selectedTab = childTab1;
+  gBrowser.removeCurrentTab();
+  is(idx(gBrowser.selectedTab), idx(childTab2),
+     "closing a tab next to its parent selects the next tab with the same parent");
+  gBrowser.removeCurrentTab();
+  is(idx(gBrowser.selectedTab), idx(tab2),
+     "closing the last tab in a set of child tabs doesn't go back to the parent");
+
+  gBrowser.removeTab(tab2);
+}
+
+function idx(tab) {
+  return Array.indexOf(gBrowser.tabs, tab);
+}