Bug 515409 - closing a tab should go back to opening tab [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 18 Jun 2010 00:31:24 -0400
changeset 66298 8fb61693f57eae6cdb91ef725f441fff270b9e23
parent 66297 577021b2c59dc6678b203a362a7af33ea4dd5bd6
child 66299 e78a4ef0d3f7686490df469fdfdc23a3c4ad25f7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs515409
Bug 515409 - closing a tab should go back to opening tab [r=mfinkle]
mobile/chrome/content/browser.js
mobile/chrome/tests/browser_tabs.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -778,16 +778,18 @@ var Browser = {
   closeTab: function(tab) {
     if (tab instanceof XULElement)
       tab = this.getTabFromChrome(tab);
 
     if (!tab)
       return;
 
     let tabIndex = this._tabs.indexOf(tab);
+    if (tabIndex == -1)
+      return;
 
     let nextTab = this._selectedTab;
     if (nextTab == tab) {
       nextTab = tab.owner || this.getTabAtIndex(tabIndex + 1) || this.getTabAtIndex(tabIndex - 1);
       if (!nextTab)
         return;
     }
 
--- a/mobile/chrome/tests/browser_tabs.js
+++ b/mobile/chrome/tests/browser_tabs.js
@@ -1,13 +1,15 @@
 let testURL_01 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
 let testURL_02 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_02.html";
+let testURL_03 = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html#tab3";
 
 let new_tab_01;
 let new_tab_02;
+let new_tab_03;
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
   
   //Add new tab
@@ -47,15 +49,32 @@ function tab_switch_01() {
 
 function tab_switch_02() {
   BrowserUI.selectTab(new_tab_02);
   is(Browser.selectedTab.browser.currentURI.spec, testURL_02, "Tab Switch 02 URL Matches");
 
   BrowserUI.selectTab(new_tab_01);
   is(Browser.selectedTab.browser.currentURI.spec, testURL_01, "Tab Switch 01 URL Matches"); 
 
+  //Add new tab
+  new_tab_03 =  Browser.addTab(testURL_03, true, new_tab_01);
+  new_tab_03.browser.addEventListener("load", tab_switch_03, true);
+}
+
+function tab_switch_03() {
+  is(Browser.selectedTab.browser.currentURI.spec, testURL_03, "Tab Switch 03 URL Matches"); 
+  is(new_tab_03.owner, new_tab_01, "Tab 03 owned by tab 01"); 
+
+  Browser.closeTab(new_tab_03);
+  is(Browser.selectedTab, new_tab_01, "Closing tab 03 returns to owner"); 
+
+  done();
+}
+
+function done() {
   //Close new tab 
   Browser.closeTab(new_tab_01);
   Browser.closeTab(new_tab_02);
+  Browser.closeTab(new_tab_03);
   
   // We must finialize the tests
   finish();
 }