summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_restore_uitest.cc
diff options
context:
space:
mode:
authorpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 22:01:03 +0000
committerpam@chromium.org <pam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 22:01:03 +0000
commit77bc673bf31c32bfdcb1bf139c3a58eace23e3ea (patch)
treea737cc649d4f38a2b96ca2de8d1da4fda0e36451 /chrome/browser/tab_restore_uitest.cc
parent8c2ea0e34721a2b0bfd8e003937b0617adfddf96 (diff)
downloadchromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.zip
chromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.tar.gz
chromium_src-77bc673bf31c32bfdcb1bf139c3a58eace23e3ea.tar.bz2
When restoring a closed tab using either ctrl-shift-T or the context menu, put
it back into the window it came from, at the tabstrip index it occupied before, and activate (select) both the window and the tab. Restoring a tab from the New Tab Page replaces the NTP, as before. If the window the tab was in no longer exists, put the tab at the end of the current window's tabstrip. This behavior may change in a later patch. BUG=5278 TEST=Open two windows, with >1 tabs each. Close a tab, not the one at the end, in one of the windows. Switch to the other window and choose "Undo Closed Tab" from the tabstrip context menu, or type ctrl-shift-T. The tab should be restored where it was, and activated (selected and brought to the front). Review URL: http://codereview.chromium.org/69015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_restore_uitest.cc')
-rw-r--r--chrome/browser/tab_restore_uitest.cc127
1 files changed, 125 insertions, 2 deletions
diff --git a/chrome/browser/tab_restore_uitest.cc b/chrome/browser/tab_restore_uitest.cc
index 6a16c9b..109c768 100644
--- a/chrome/browser/tab_restore_uitest.cc
+++ b/chrome/browser/tab_restore_uitest.cc
@@ -12,6 +12,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
@@ -49,6 +50,17 @@ class TabRestoreUITest : public UITest {
action_max_timeout_ms()));
}
+ // Ensure that the given browser occupies the currently active window.
+ void CheckActiveWindow(const BrowserProxy* browser) {
+ // The EXPECT_TRUE may fail during manual debugging, as well as if a user
+ // does other things while running the tests, because Chromium won't be
+ // the foremost application at all.
+ bool is_active = false;
+ scoped_ptr<WindowProxy> window_proxy(browser->GetWindow());
+ ASSERT_TRUE(window_proxy->IsActive(&is_active));
+ EXPECT_TRUE(is_active);
+ }
+
GURL url1_;
GURL url2_;
@@ -56,36 +68,144 @@ class TabRestoreUITest : public UITest {
DISALLOW_EVIL_CONSTRUCTORS(TabRestoreUITest);
};
+// Close the end tab in the current window, then restore it. The tab should be
+// in its original position, and active.
TEST_F(TabRestoreUITest, Basic) {
scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
int tab_count;
ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ int starting_tab_count = tab_count;
// Add a tab
browser_proxy->AppendTab(url1_);
ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1,
action_max_timeout_ms()));
ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
- scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(tab_count - 1));
+ ASSERT_EQ(starting_tab_count + 1, tab_count);
+
+ int closed_tab_index = tab_count - 1;
+ scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
// Make sure we're at url.
new_tab->NavigateToURL(url1_);
// Close the tab.
new_tab->Close(true);
new_tab.reset();
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count, tab_count);
RestoreTab();
- // And make sure the URL matches.
+ // And make sure everything looks right.
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 1, tab_count);
+ ASSERT_EQ(closed_tab_index, GetActiveTabIndex());
ASSERT_EQ(url1_, GetActiveTabURL());
}
+// Close a tab not at the end of the current window, then restore it. The tab
+// should be in its original position, and active.
+TEST_F(TabRestoreUITest, MiddleTab) {
+ scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
+
+ int tab_count;
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ int starting_tab_count = tab_count;
+
+ // Add a couple of tabs
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1,
+ action_max_timeout_ms()));
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 2,
+ action_max_timeout_ms()));
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 3,
+ action_max_timeout_ms()));
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 3, tab_count);
+
+ // Close one in the middle
+ int closed_tab_index = starting_tab_count + 1;
+ scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
+ // Make sure we're at url.
+ new_tab->NavigateToURL(url1_);
+ // Close the tab.
+ new_tab->Close(true);
+ new_tab.reset();
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 2, tab_count);
+
+ RestoreTab();
+
+ // And make sure everything looks right.
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 3, tab_count);
+ ASSERT_EQ(closed_tab_index, GetActiveTabIndex());
+ ASSERT_EQ(url1_, GetActiveTabURL());
+}
+
+// Close a tab, switch windows, then restore the tab. The tab should be in its
+// original window and position, and active.
TEST_F(TabRestoreUITest, RestoreToDifferentWindow) {
+ scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
+
+ CheckActiveWindow(browser_proxy.get());
+
+ int tab_count;
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ int starting_tab_count = tab_count;
+
+ // Add a couple of tabs
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1,
+ action_max_timeout_ms()));
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 2,
+ action_max_timeout_ms()));
+ browser_proxy->AppendTab(url1_);
+ ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 3,
+ action_max_timeout_ms()));
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 3, tab_count);
+
+ // Close one in the middle
+ int closed_tab_index = starting_tab_count + 1;
+ scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
+ // Make sure we're at url.
+ new_tab->NavigateToURL(url1_);
+ // Close the tab.
+ new_tab->Close(true);
+ new_tab.reset();
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ ASSERT_EQ(starting_tab_count + 2, tab_count);
+
+ // Create a new browser.
+ ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
+ ASSERT_TRUE(automation()->WaitForWindowCountToBecome(
+ 2, action_max_timeout_ms()));
+
+ CheckActiveWindow(automation()->GetBrowserWindow(1));
+
+ RestoreTab();
+
+ // And make sure everything looks right.
+ CheckActiveWindow(browser_proxy.get());
+ ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
+ EXPECT_EQ(starting_tab_count + 3, tab_count);
+ ASSERT_EQ(closed_tab_index, GetActiveTabIndex());
+ ASSERT_EQ(url1_, GetActiveTabURL());
+}
+
+// Close a tab, open a new window, close the first window, then restore the
+// tab. It should be at the end of the current (new) window's tabstrip.
+TEST_F(TabRestoreUITest, RestoreFromClosedWindow) {
// This test is disabled on win2k. See bug 1215881.
if (win_util::GetWinVersion() == win_util::WINVERSION_2000)
return;
scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
+ CheckActiveWindow(browser_proxy.get());
int tab_count;
ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
@@ -106,6 +226,7 @@ TEST_F(TabRestoreUITest, RestoreToDifferentWindow) {
ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
ASSERT_TRUE(automation()->WaitForWindowCountToBecome(
2, action_max_timeout_ms()));
+ CheckActiveWindow(automation()->GetBrowserWindow(1));
// Close the first browser.
EXPECT_TRUE(tab_proxy->Close(true));
@@ -118,7 +239,9 @@ TEST_F(TabRestoreUITest, RestoreToDifferentWindow) {
RestoreTab();
+ // Tab should be at the end of the current (only) window.
browser_proxy.reset(automation()->GetBrowserWindow(0));
+ CheckActiveWindow(browser_proxy.get());
tab_proxy.reset(browser_proxy->GetActiveTab());
// And make sure the URLs matches.
ASSERT_EQ(url2_, GetActiveTabURL());