| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/win_util.h" | 8 #include "base/win_util.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class TabRestoreUITest : public UITest { | 21 class TabRestoreUITest : public UITest { |
| 22 public: | 22 public: |
| 23 TabRestoreUITest() : UITest() { | 23 TabRestoreUITest() : UITest() { |
| 24 FilePath path_prefix(FilePath::FromWStringHack(test_data_directory_)); | 24 FilePath path_prefix(FilePath::FromWStringHack(test_data_directory_)); |
| 25 path_prefix = path_prefix.AppendASCII("session_history"); | 25 path_prefix = path_prefix.AppendASCII("session_history"); |
| 26 url1_ = net::FilePathToFileURL(path_prefix.AppendASCII("bot1.html")); | 26 url1_ = net::FilePathToFileURL(path_prefix.AppendASCII("bot1.html")); |
| 27 url2_ = net::FilePathToFileURL(path_prefix.AppendASCII("bot2.html")); | 27 url2_ = net::FilePathToFileURL(path_prefix.AppendASCII("bot2.html")); |
| 28 } | 28 } |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 void RestoreTab() { | 31 // Uses the undo-close-tab accelerator to undo a close-tab or close-window |
| 32 int tab_count; | 32 // operation. The newly restored tab is expected to appear in the |
| 33 // window at index |expected_window_index|, at the |expected_tabstrip_index|, |
| 34 // and to be active. If |expected_window_index| is equal to the number of |
| 35 // current windows, the restored tab is expected to be created in a new |
| 36 // window (since the index is 0-based). |
| 37 void RestoreTab(int expected_window_index, |
| 38 int expected_tabstrip_index) { |
| 39 int tab_count = 0; |
| 40 int window_count = 0; |
| 33 | 41 |
| 34 // Reset browser_proxy to new window. | 42 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 35 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 43 ASSERT_GT(window_count, 0); |
| 44 |
| 45 bool expect_new_window = (expected_window_index == window_count); |
| 46 scoped_ptr<BrowserProxy> browser_proxy; |
| 47 if (expect_new_window) { |
| 48 browser_proxy.reset(automation()->GetBrowserWindow(0)); |
| 49 } else { |
| 50 ASSERT_GT(window_count, expected_window_index); |
| 51 browser_proxy.reset( |
| 52 automation()->GetBrowserWindow(expected_window_index)); |
| 53 } |
| 36 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 54 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 37 ASSERT_GT(tab_count, 0); | 55 ASSERT_GT(tab_count, 0); |
| 38 | 56 |
| 39 // Restore the tab. | 57 // Restore the tab. |
| 40 ASSERT_TRUE(browser_proxy->ApplyAccelerator(IDC_RESTORE_TAB)); | 58 ASSERT_TRUE(browser_proxy->ApplyAccelerator(IDC_RESTORE_TAB)); |
| 41 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome( | 59 |
| 42 tab_count + 1, action_max_timeout_ms())); | 60 if (expect_new_window) { |
| 61 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 62 ++window_count, action_max_timeout_ms())); |
| 63 browser_proxy.reset(automation()-> |
| 64 GetBrowserWindow(expected_window_index)); |
| 65 } else { |
| 66 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome( |
| 67 ++tab_count, action_max_timeout_ms())); |
| 68 } |
| 43 | 69 |
| 44 // Get a handle to the restored tab. | 70 // Get a handle to the restored tab. |
| 45 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 71 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 72 ASSERT_GT(tab_count, expected_tabstrip_index); |
| 46 scoped_ptr<TabProxy> restored_tab_proxy( | 73 scoped_ptr<TabProxy> restored_tab_proxy( |
| 47 browser_proxy->GetTab(tab_count - 1)); | 74 browser_proxy->GetTab(expected_tabstrip_index)); |
| 48 // Wait for the restored tab to finish loading. | 75 // Wait for the restored tab to finish loading. |
| 49 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored( | 76 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored( |
| 50 action_max_timeout_ms())); | 77 action_max_timeout_ms())); |
| 78 |
| 79 // Ensure that the tab and window are active. |
| 80 CheckActiveWindow(browser_proxy.get()); |
| 81 EXPECT_EQ(expected_tabstrip_index, |
| 82 GetActiveTabIndex(expected_window_index)); |
| 83 } |
| 84 |
| 85 // Adds tabs to the given browser, all navigated to url1_. Returns |
| 86 // the final number of tabs. |
| 87 int AddSomeTabs(BrowserProxy* browser, int how_many) { |
| 88 int starting_tab_count = -1; |
| 89 // Use EXPECT instead of ASSERT throughout to avoid trying to return void. |
| 90 EXPECT_TRUE(browser->GetTabCount(&starting_tab_count)); |
| 91 |
| 92 for (int i = 0; i < how_many; ++i) { |
| 93 browser->AppendTab(url1_); |
| 94 EXPECT_TRUE(browser->WaitForTabCountToBecome(starting_tab_count + i + 1, |
| 95 action_max_timeout_ms())); |
| 96 } |
| 97 int tab_count; |
| 98 EXPECT_TRUE(browser->GetTabCount(&tab_count)); |
| 99 EXPECT_EQ(starting_tab_count + how_many, tab_count); |
| 100 return tab_count; |
| 51 } | 101 } |
| 52 | 102 |
| 53 // Ensure that the given browser occupies the currently active window. | 103 // Ensure that the given browser occupies the currently active window. |
| 54 void CheckActiveWindow(const BrowserProxy* browser) { | 104 void CheckActiveWindow(const BrowserProxy* browser) { |
| 55 bool is_active = false; | 105 bool is_active = false; |
| 56 scoped_ptr<WindowProxy> window_proxy(browser->GetWindow()); | 106 scoped_ptr<WindowProxy> window_proxy(browser->GetWindow()); |
| 57 ASSERT_TRUE(window_proxy->IsActive(&is_active)); | 107 ASSERT_TRUE(window_proxy->IsActive(&is_active)); |
| 58 // The EXPECT_TRUE may fail if other apps are active while running the | 108 // The EXPECT_TRUE may fail if other apps are active while running the |
| 59 // tests, because Chromium won't be the foremost application at all. To | 109 // tests, because Chromium won't be the foremost application at all. To |
| 60 // prevent this from turning the buildbots red, we disable the check | 110 // prevent this from turning the buildbots red, we disable the check |
| (...skipping 19 matching lines...) Expand all Loading... |
| 80 | 130 |
| 81 private: | 131 private: |
| 82 DISALLOW_EVIL_CONSTRUCTORS(TabRestoreUITest); | 132 DISALLOW_EVIL_CONSTRUCTORS(TabRestoreUITest); |
| 83 }; | 133 }; |
| 84 | 134 |
| 85 // Close the end tab in the current window, then restore it. The tab should be | 135 // Close the end tab in the current window, then restore it. The tab should be |
| 86 // in its original position, and active. | 136 // in its original position, and active. |
| 87 TEST_F(TabRestoreUITest, Basic) { | 137 TEST_F(TabRestoreUITest, Basic) { |
| 88 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 138 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 89 | 139 |
| 90 int tab_count; | 140 int starting_tab_count; |
| 91 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 141 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
| 92 int starting_tab_count = tab_count; | 142 int tab_count = AddSomeTabs(browser_proxy.get(), 1); |
| 93 | |
| 94 // Add a tab | |
| 95 browser_proxy->AppendTab(url1_); | |
| 96 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1, | |
| 97 action_max_timeout_ms())); | |
| 98 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | |
| 99 ASSERT_EQ(starting_tab_count + 1, tab_count); | |
| 100 | 143 |
| 101 int closed_tab_index = tab_count - 1; | 144 int closed_tab_index = tab_count - 1; |
| 102 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 145 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 103 // Make sure we're at url. | 146 // Make sure we're at url. |
| 104 new_tab->NavigateToURL(url1_); | 147 new_tab->NavigateToURL(url1_); |
| 105 // Close the tab. | 148 // Close the tab. |
| 106 new_tab->Close(true); | 149 new_tab->Close(true); |
| 107 new_tab.reset(); | 150 new_tab.reset(); |
| 108 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 151 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 109 ASSERT_EQ(starting_tab_count, tab_count); | 152 EXPECT_EQ(starting_tab_count, tab_count); |
| 110 | 153 |
| 111 RestoreTab(); | 154 RestoreTab(0, closed_tab_index); |
| 112 | 155 |
| 113 // And make sure everything looks right. | 156 // And make sure everything looks right. |
| 114 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 157 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 115 ASSERT_EQ(starting_tab_count + 1, tab_count); | 158 EXPECT_EQ(starting_tab_count + 1, tab_count); |
| 116 ASSERT_EQ(closed_tab_index, GetActiveTabIndex()); | 159 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); |
| 117 ASSERT_EQ(url1_, GetActiveTabURL()); | 160 EXPECT_EQ(url1_, GetActiveTabURL()); |
| 118 } | 161 } |
| 119 | 162 |
| 120 // Close a tab not at the end of the current window, then restore it. The tab | 163 // Close a tab not at the end of the current window, then restore it. The tab |
| 121 // should be in its original position, and active. | 164 // should be in its original position, and active. |
| 122 TEST_F(TabRestoreUITest, MiddleTab) { | 165 TEST_F(TabRestoreUITest, MiddleTab) { |
| 123 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 166 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 124 | 167 |
| 125 int tab_count; | 168 int starting_tab_count; |
| 126 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 169 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
| 127 int starting_tab_count = tab_count; | 170 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
| 128 | |
| 129 // Add a couple of tabs | |
| 130 browser_proxy->AppendTab(url1_); | |
| 131 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1, | |
| 132 action_max_timeout_ms())); | |
| 133 browser_proxy->AppendTab(url1_); | |
| 134 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 2, | |
| 135 action_max_timeout_ms())); | |
| 136 browser_proxy->AppendTab(url1_); | |
| 137 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 3, | |
| 138 action_max_timeout_ms())); | |
| 139 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | |
| 140 ASSERT_EQ(starting_tab_count + 3, tab_count); | |
| 141 | 171 |
| 142 // Close one in the middle | 172 // Close one in the middle |
| 143 int closed_tab_index = starting_tab_count + 1; | 173 int closed_tab_index = starting_tab_count + 1; |
| 144 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 174 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 145 // Make sure we're at url. | 175 // Make sure we're at url. |
| 146 new_tab->NavigateToURL(url1_); | 176 new_tab->NavigateToURL(url1_); |
| 147 // Close the tab. | 177 // Close the tab. |
| 148 new_tab->Close(true); | 178 new_tab->Close(true); |
| 149 new_tab.reset(); | 179 new_tab.reset(); |
| 150 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 180 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 151 ASSERT_EQ(starting_tab_count + 2, tab_count); | 181 EXPECT_EQ(starting_tab_count + 2, tab_count); |
| 152 | 182 |
| 153 RestoreTab(); | 183 RestoreTab(0, closed_tab_index); |
| 154 | 184 |
| 155 // And make sure everything looks right. | 185 // And make sure everything looks right. |
| 156 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 186 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 157 ASSERT_EQ(starting_tab_count + 3, tab_count); | 187 EXPECT_EQ(starting_tab_count + 3, tab_count); |
| 158 ASSERT_EQ(closed_tab_index, GetActiveTabIndex()); | 188 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); |
| 159 ASSERT_EQ(url1_, GetActiveTabURL()); | 189 EXPECT_EQ(url1_, GetActiveTabURL()); |
| 160 } | 190 } |
| 161 | 191 |
| 162 // Close a tab, switch windows, then restore the tab. The tab should be in its | 192 // Close a tab, switch windows, then restore the tab. The tab should be in its |
| 163 // original window and position, and active. | 193 // original window and position, and active. |
| 164 TEST_F(TabRestoreUITest, RestoreToDifferentWindow) { | 194 TEST_F(TabRestoreUITest, RestoreToDifferentWindow) { |
| 165 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 195 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 166 | 196 |
| 167 // This call is virtually guaranteed to pass, assuming that Chromium is the | 197 // This call is virtually guaranteed to pass, assuming that Chromium is the |
| 168 // active application, which will establish a baseline for later calls to | 198 // active application, which will establish a baseline for later calls to |
| 169 // CheckActiveWindow(). See comments in that function. | 199 // CheckActiveWindow(). See comments in that function. |
| 170 CheckActiveWindow(browser_proxy.get()); | 200 CheckActiveWindow(browser_proxy.get()); |
| 171 | 201 |
| 172 int tab_count; | 202 int starting_tab_count; |
| 173 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 203 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
| 174 int starting_tab_count = tab_count; | 204 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
| 175 | |
| 176 // Add a couple of tabs | |
| 177 browser_proxy->AppendTab(url1_); | |
| 178 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 1, | |
| 179 action_max_timeout_ms())); | |
| 180 browser_proxy->AppendTab(url1_); | |
| 181 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 2, | |
| 182 action_max_timeout_ms())); | |
| 183 browser_proxy->AppendTab(url1_); | |
| 184 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(tab_count + 3, | |
| 185 action_max_timeout_ms())); | |
| 186 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | |
| 187 ASSERT_EQ(starting_tab_count + 3, tab_count); | |
| 188 | 205 |
| 189 // Close one in the middle | 206 // Close one in the middle |
| 190 int closed_tab_index = starting_tab_count + 1; | 207 int closed_tab_index = starting_tab_count + 1; |
| 191 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); | 208 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 192 // Make sure we're at url. | 209 // Make sure we're at url. |
| 193 new_tab->NavigateToURL(url1_); | 210 new_tab->NavigateToURL(url1_); |
| 194 // Close the tab. | 211 // Close the tab. |
| 195 new_tab->Close(true); | 212 new_tab->Close(true); |
| 196 new_tab.reset(); | 213 new_tab.reset(); |
| 197 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 214 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 198 ASSERT_EQ(starting_tab_count + 2, tab_count); | 215 EXPECT_EQ(starting_tab_count + 2, tab_count); |
| 199 | 216 |
| 200 // Create a new browser. | 217 // Create a new browser. |
| 201 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 218 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
| 202 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 219 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 203 2, action_max_timeout_ms())); | 220 2, action_max_timeout_ms())); |
| 204 | 221 |
| 205 CheckActiveWindow(automation()->GetBrowserWindow(1)); | 222 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
| 206 | 223 |
| 207 RestoreTab(); | 224 // Restore tab into original browser. |
| 225 RestoreTab(0, closed_tab_index); |
| 208 | 226 |
| 209 // And make sure everything looks right. | 227 // And make sure everything looks right. |
| 210 CheckActiveWindow(browser_proxy.get()); | 228 CheckActiveWindow(browser_proxy.get()); |
| 211 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 229 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 212 EXPECT_EQ(starting_tab_count + 3, tab_count); | 230 EXPECT_EQ(starting_tab_count + 3, tab_count); |
| 213 ASSERT_EQ(closed_tab_index, GetActiveTabIndex()); | 231 EXPECT_EQ(closed_tab_index, GetActiveTabIndex(0)); |
| 214 ASSERT_EQ(url1_, GetActiveTabURL()); | 232 EXPECT_EQ(url1_, GetActiveTabURL(0)); |
| 215 } | 233 } |
| 216 | 234 |
| 217 // Close a tab, open a new window, close the first window, then restore the | 235 // Close a tab, open a new window, close the first window, then restore the |
| 218 // tab. It should be at the end of the current (new) window's tabstrip. | 236 // tab. It should be in a new window. |
| 219 TEST_F(TabRestoreUITest, RestoreFromClosedWindow) { | 237 TEST_F(TabRestoreUITest, BasicRestoreFromClosedWindow) { |
| 220 // This test is disabled on win2k. See bug 1215881. | 238 // This test is disabled on win2k. See bug 1215881. |
| 221 if (win_util::GetWinVersion() == win_util::WINVERSION_2000) | 239 if (win_util::GetWinVersion() == win_util::WINVERSION_2000) |
| 222 return; | 240 return; |
| 223 | 241 |
| 224 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 242 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 225 CheckActiveWindow(browser_proxy.get()); | 243 CheckActiveWindow(browser_proxy.get()); |
| 226 | 244 |
| 227 int tab_count; | 245 int tab_count; |
| 228 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 246 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 229 | 247 |
| 230 // Close tabs until we only have one open. | 248 // Close tabs until we only have one open. |
| 231 while (tab_count > 1) { | 249 while (tab_count > 1) { |
| 232 scoped_ptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); | 250 scoped_ptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); |
| 233 tab_to_close->Close(true); | 251 tab_to_close->Close(true); |
| 234 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 252 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 235 } | 253 } |
| 236 | 254 |
| 237 // Navigate to url1 then url2. | 255 // Navigate to url1 then url2. |
| 238 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 256 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 239 tab_proxy->NavigateToURL(url1_); | 257 tab_proxy->NavigateToURL(url1_); |
| 240 tab_proxy->NavigateToURL(url2_); | 258 tab_proxy->NavigateToURL(url2_); |
| 241 | 259 |
| 242 // Create a new browser. | 260 // Create a new browser. |
| 243 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 261 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
| 244 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 262 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 245 2, action_max_timeout_ms())); | 263 2, action_max_timeout_ms())); |
| 246 CheckActiveWindow(automation()->GetBrowserWindow(1)); | 264 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
| 247 | 265 |
| 248 // Close the first browser. | 266 // Close the final tab in the first browser. |
| 249 EXPECT_TRUE(tab_proxy->Close(true)); | 267 EXPECT_TRUE(tab_proxy->Close(true)); |
| 250 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 268 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 251 1, action_max_timeout_ms())); | 269 1, action_max_timeout_ms())); |
| 252 | 270 |
| 253 // Tab and browser are no longer valid. | 271 // Tab and browser are no longer valid. |
| 254 tab_proxy.reset(); | 272 tab_proxy.reset(); |
| 255 browser_proxy.reset(); | 273 browser_proxy.reset(); |
| 256 | 274 |
| 257 RestoreTab(); | 275 RestoreTab(1, 0); |
| 258 | 276 |
| 259 // Tab should be at the end of the current (only) window. | 277 // Tab should be in a new window. |
| 260 browser_proxy.reset(automation()->GetBrowserWindow(0)); | 278 browser_proxy.reset(automation()->GetBrowserWindow(1)); |
| 261 CheckActiveWindow(browser_proxy.get()); | 279 CheckActiveWindow(browser_proxy.get()); |
| 262 tab_proxy.reset(browser_proxy->GetActiveTab()); | 280 tab_proxy.reset(browser_proxy->GetActiveTab()); |
| 263 // And make sure the URLs matches. | 281 // And make sure the URLs matches. |
| 264 ASSERT_EQ(url2_, GetActiveTabURL()); | 282 EXPECT_EQ(url2_, GetActiveTabURL(1)); |
| 265 ASSERT_TRUE(tab_proxy->GoBack()); | 283 EXPECT_TRUE(tab_proxy->GoBack()); |
| 266 ASSERT_EQ(url1_, GetActiveTabURL()); | 284 EXPECT_EQ(url1_, GetActiveTabURL(1)); |
| 285 } |
| 286 |
| 287 // Open a window with multiple tabs, close a tab, then close the window. |
| 288 // Restore both and make sure the tab goes back into the window. |
| 289 TEST_F(TabRestoreUITest, RestoreWindowAndTab) { |
| 290 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 291 CheckActiveWindow(browser_proxy.get()); |
| 292 |
| 293 int starting_tab_count; |
| 294 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
| 295 int tab_count = AddSomeTabs(browser_proxy.get(), 3); |
| 296 |
| 297 // Close one in the middle |
| 298 int closed_tab_index = starting_tab_count + 1; |
| 299 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); |
| 300 // Make sure we're at url. |
| 301 new_tab->NavigateToURL(url1_); |
| 302 // Close the tab. |
| 303 new_tab->Close(true); |
| 304 new_tab.reset(); |
| 305 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 306 EXPECT_EQ(starting_tab_count + 2, tab_count); |
| 307 |
| 308 // Create a new browser. |
| 309 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
| 310 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 311 2, action_max_timeout_ms())); |
| 312 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
| 313 |
| 314 // Close the first browser. |
| 315 bool application_closing; |
| 316 EXPECT_TRUE(CloseBrowser(browser_proxy.get(), &application_closing)); |
| 317 EXPECT_FALSE(application_closing); |
| 318 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 319 1, action_max_timeout_ms())); |
| 320 |
| 321 // Browser is no longer valid. |
| 322 browser_proxy.reset(); |
| 323 |
| 324 // Restore the first window. The expected_tabstrip_index (second argument) |
| 325 // indicates the expected active tab. |
| 326 RestoreTab(1, starting_tab_count + 1); |
| 327 browser_proxy.reset(automation()->GetBrowserWindow(1)); |
| 328 CheckActiveWindow(browser_proxy.get()); |
| 329 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 330 EXPECT_EQ(starting_tab_count + 2, tab_count); |
| 331 |
| 332 // Restore the closed tab. |
| 333 RestoreTab(1, closed_tab_index); |
| 334 CheckActiveWindow(browser_proxy.get()); |
| 335 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 336 EXPECT_EQ(starting_tab_count + 3, tab_count); |
| 337 EXPECT_EQ(url1_, GetActiveTabURL(1)); |
| 338 } |
| 339 |
| 340 // Open a window with two tabs, close both (closing the window), then restore |
| 341 // both. Make sure both restored tabs are in the same window. |
| 342 TEST_F(TabRestoreUITest, RestoreIntoSameWindow) { |
| 343 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 344 CheckActiveWindow(browser_proxy.get()); |
| 345 |
| 346 int starting_tab_count; |
| 347 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); |
| 348 int tab_count = AddSomeTabs(browser_proxy.get(), 2); |
| 349 |
| 350 // Navigate the rightmost one to url2_ for easier identification. |
| 351 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 1)); |
| 352 tab_proxy->NavigateToURL(url2_); |
| 353 |
| 354 // Create a new browser. |
| 355 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
| 356 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 357 2, action_max_timeout_ms())); |
| 358 CheckActiveWindow(automation()->GetBrowserWindow(1)); |
| 359 |
| 360 // Close all but one tab in the first browser, left to right. |
| 361 while (tab_count > 1) { |
| 362 scoped_ptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); |
| 363 tab_to_close->Close(true); |
| 364 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 365 } |
| 366 |
| 367 // Close the last tab, closing the browser. |
| 368 tab_proxy.reset(browser_proxy->GetTab(0)); |
| 369 EXPECT_TRUE(tab_proxy->Close(true)); |
| 370 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 371 1, action_max_timeout_ms())); |
| 372 browser_proxy.reset(); |
| 373 tab_proxy.reset(); |
| 374 |
| 375 // Restore the last-closed tab into a new window. |
| 376 RestoreTab(1, 0); |
| 377 browser_proxy.reset(automation()->GetBrowserWindow(1)); |
| 378 CheckActiveWindow(browser_proxy.get()); |
| 379 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 380 EXPECT_EQ(1, tab_count); |
| 381 EXPECT_EQ(url2_, GetActiveTabURL(1)); |
| 382 |
| 383 // Restore the next-to-last-closed tab into the same window. |
| 384 RestoreTab(1, 0); |
| 385 CheckActiveWindow(browser_proxy.get()); |
| 386 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 387 EXPECT_EQ(2, tab_count); |
| 388 EXPECT_EQ(url1_, GetActiveTabURL(1)); |
| 267 } | 389 } |
| 268 | 390 |
| 269 // Tests that a duplicate history entry is not created when we restore a page | 391 // Tests that a duplicate history entry is not created when we restore a page |
| 270 // to an existing SiteInstance. (Bug 1230446) | 392 // to an existing SiteInstance. (Bug 1230446) |
| 271 TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { | 393 TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { |
| 272 const wchar_t kDocRoot[] = L"chrome/test/data"; | 394 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 273 scoped_refptr<HTTPTestServer> server = | 395 scoped_refptr<HTTPTestServer> server = |
| 274 HTTPTestServer::CreateServer(kDocRoot, NULL); | 396 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 275 ASSERT_TRUE(NULL != server.get()); | 397 ASSERT_TRUE(NULL != server.get()); |
| 276 GURL http_url1(server->TestServerPageW(L"files/title1.html")); | 398 GURL http_url1(server->TestServerPageW(L"files/title1.html")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 293 // Close the tab. | 415 // Close the tab. |
| 294 tab->Close(true); | 416 tab->Close(true); |
| 295 tab.reset(); | 417 tab.reset(); |
| 296 | 418 |
| 297 // Create a new tab to the original site. Assuming process-per-site is | 419 // Create a new tab to the original site. Assuming process-per-site is |
| 298 // enabled, this will ensure that the SiteInstance used by the restored tab | 420 // enabled, this will ensure that the SiteInstance used by the restored tab |
| 299 // will already exist when the restore happens. | 421 // will already exist when the restore happens. |
| 300 browser_proxy->AppendTab(http_url2); | 422 browser_proxy->AppendTab(http_url2); |
| 301 | 423 |
| 302 // Restore the closed tab. | 424 // Restore the closed tab. |
| 303 RestoreTab(); | 425 RestoreTab(0, tab_count - 1); |
| 304 tab.reset(browser_proxy->GetActiveTab()); | 426 tab.reset(browser_proxy->GetActiveTab()); |
| 305 | 427 |
| 306 // And make sure the URLs match. | 428 // And make sure the URLs match. |
| 307 ASSERT_EQ(http_url2, GetActiveTabURL()); | 429 EXPECT_EQ(http_url2, GetActiveTabURL()); |
| 308 ASSERT_TRUE(tab->GoBack()); | 430 EXPECT_TRUE(tab->GoBack()); |
| 309 ASSERT_EQ(http_url1, GetActiveTabURL()); | 431 EXPECT_EQ(http_url1, GetActiveTabURL()); |
| 310 } | 432 } |
| 311 | 433 |
| 312 // Tests that the SiteInstances used for entries in a restored tab's history | 434 // Tests that the SiteInstances used for entries in a restored tab's history |
| 313 // are given appropriate max page IDs, even if the renderer for the entry | 435 // are given appropriate max page IDs, even if the renderer for the entry |
| 314 // already exists. (Bug 1204135) | 436 // already exists. (Bug 1204135) |
| 315 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { | 437 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { |
| 316 const wchar_t kDocRoot[] = L"chrome/test/data"; | 438 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 317 scoped_refptr<HTTPTestServer> server = | 439 scoped_refptr<HTTPTestServer> server = |
| 318 HTTPTestServer::CreateServer(kDocRoot, NULL); | 440 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 319 ASSERT_TRUE(NULL != server.get()); | 441 ASSERT_TRUE(NULL != server.get()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 339 // Close the tab. | 461 // Close the tab. |
| 340 tab->Close(true); | 462 tab->Close(true); |
| 341 tab.reset(); | 463 tab.reset(); |
| 342 | 464 |
| 343 // Create a new tab to the original site. Assuming process-per-site is | 465 // Create a new tab to the original site. Assuming process-per-site is |
| 344 // enabled, this will ensure that the SiteInstance will already exist when | 466 // enabled, this will ensure that the SiteInstance will already exist when |
| 345 // the user clicks Back in the restored tab. | 467 // the user clicks Back in the restored tab. |
| 346 browser_proxy->AppendTab(http_url2); | 468 browser_proxy->AppendTab(http_url2); |
| 347 | 469 |
| 348 // Restore the closed tab. | 470 // Restore the closed tab. |
| 349 RestoreTab(); | 471 RestoreTab(0, tab_count - 1); |
| 350 tab.reset(browser_proxy->GetActiveTab()); | 472 tab.reset(browser_proxy->GetActiveTab()); |
| 351 | 473 |
| 352 // And make sure the URLs match. | 474 // And make sure the URLs match. |
| 353 ASSERT_EQ(url1_, GetActiveTabURL()); | 475 EXPECT_EQ(url1_, GetActiveTabURL()); |
| 354 ASSERT_TRUE(tab->GoBack()); | 476 EXPECT_TRUE(tab->GoBack()); |
| 355 ASSERT_EQ(http_url1, GetActiveTabURL()); | 477 EXPECT_EQ(http_url1, GetActiveTabURL()); |
| 356 | 478 |
| 357 // Navigating to a new URL should clear the forward list, because the max | 479 // Navigating to a new URL should clear the forward list, because the max |
| 358 // page ID of the renderer should have been updated when we restored the tab. | 480 // page ID of the renderer should have been updated when we restored the tab. |
| 359 tab->NavigateToURL(http_url2); | 481 tab->NavigateToURL(http_url2); |
| 360 ASSERT_FALSE(tab->GoForward()); | 482 EXPECT_FALSE(tab->GoForward()); |
| 361 ASSERT_EQ(http_url2, GetActiveTabURL()); | 483 EXPECT_EQ(http_url2, GetActiveTabURL()); |
| 362 } | 484 } |
| 363 | 485 |
| 364 TEST_F(TabRestoreUITest, RestoreWindow) { | 486 TEST_F(TabRestoreUITest, RestoreWindow) { |
| 365 // Create a new window. | 487 // Create a new window. |
| 366 int window_count; | 488 int window_count; |
| 367 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 489 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 368 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); | 490 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); |
| 369 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( | 491 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( |
| 370 ++window_count, action_max_timeout_ms())); | 492 ++window_count, action_max_timeout_ms())); |
| 371 | 493 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 399 | 521 |
| 400 browser_proxy.reset(automation()->GetBrowserWindow(1)); | 522 browser_proxy.reset(automation()->GetBrowserWindow(1)); |
| 401 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2, | 523 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2, |
| 402 action_max_timeout_ms())); | 524 action_max_timeout_ms())); |
| 403 | 525 |
| 404 scoped_ptr<TabProxy> restored_tab_proxy( | 526 scoped_ptr<TabProxy> restored_tab_proxy( |
| 405 browser_proxy->GetTab(initial_tab_count)); | 527 browser_proxy->GetTab(initial_tab_count)); |
| 406 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 528 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 407 GURL url; | 529 GURL url; |
| 408 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); | 530 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); |
| 409 ASSERT_TRUE(url == url1_); | 531 EXPECT_TRUE(url == url1_); |
| 410 | 532 |
| 411 restored_tab_proxy.reset( | 533 restored_tab_proxy.reset( |
| 412 browser_proxy->GetTab(initial_tab_count + 1)); | 534 browser_proxy->GetTab(initial_tab_count + 1)); |
| 413 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 535 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 414 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); | 536 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); |
| 415 ASSERT_TRUE(url == url2_); | 537 EXPECT_TRUE(url == url2_); |
| 416 } | 538 } |
| OLD | NEW |