| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list_impl.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
| 15 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 15 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/page_navigator.h" | 26 #include "content/public/browser/page_navigator.h" |
| 27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| 31 #include "net/test/test_server.h" | 31 #include "net/test/test_server.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" |
| 33 | 33 |
| 34 class TabRestoreTest : public InProcessBrowserTest { | 34 class TabRestoreTest : public InProcessBrowserTest { |
| 35 public: | 35 public: |
| 36 TabRestoreTest() : InProcessBrowserTest() { | 36 TabRestoreTest() |
| 37 : native_browser_list(chrome::BrowserListImpl::GetInstance( |
| 38 chrome::HOST_DESKTOP_TYPE_NATIVE)) { |
| 37 url1_ = ui_test_utils::GetTestUrl( | 39 url1_ = ui_test_utils::GetTestUrl( |
| 38 base::FilePath().AppendASCII("session_history"), | 40 base::FilePath().AppendASCII("session_history"), |
| 39 base::FilePath().AppendASCII("bot1.html")); | 41 base::FilePath().AppendASCII("bot1.html")); |
| 40 url2_ = ui_test_utils::GetTestUrl( | 42 url2_ = ui_test_utils::GetTestUrl( |
| 41 base::FilePath().AppendASCII("session_history"), | 43 base::FilePath().AppendASCII("session_history"), |
| 42 base::FilePath().AppendASCII("bot2.html")); | 44 base::FilePath().AppendASCII("bot2.html")); |
| 43 } | 45 } |
| 44 | 46 |
| 45 protected: | 47 protected: |
| 46 Browser* GetBrowser(int index) { | 48 Browser* GetBrowser(int index) { |
| 47 CHECK(static_cast<int>(BrowserList::size()) > index); | 49 |
| 48 return *(BrowserList::begin() + index); | 50 CHECK(static_cast<int>(native_browser_list->size()) > index); |
| 51 return native_browser_list->get(index); |
| 49 } | 52 } |
| 50 | 53 |
| 51 // Adds tabs to the given browser, all navigated to url1_. Returns | 54 // Adds tabs to the given browser, all navigated to url1_. Returns |
| 52 // the final number of tabs. | 55 // the final number of tabs. |
| 53 int AddSomeTabs(Browser* browser, int how_many) { | 56 int AddSomeTabs(Browser* browser, int how_many) { |
| 54 int starting_tab_count = browser->tab_strip_model()->count(); | 57 int starting_tab_count = browser->tab_strip_model()->count(); |
| 55 | 58 |
| 56 for (int i = 0; i < how_many; ++i) { | 59 for (int i = 0; i < how_many; ++i) { |
| 57 ui_test_utils::NavigateToURLWithDisposition( | 60 ui_test_utils::NavigateToURLWithDisposition( |
| 58 browser, url1_, NEW_FOREGROUND_TAB, | 61 browser, url1_, NEW_FOREGROUND_TAB, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 } | 76 } |
| 74 | 77 |
| 75 // Uses the undo-close-tab accelerator to undo a close-tab or close-window | 78 // Uses the undo-close-tab accelerator to undo a close-tab or close-window |
| 76 // operation. The newly restored tab is expected to appear in the | 79 // operation. The newly restored tab is expected to appear in the |
| 77 // window at index |expected_window_index|, at the |expected_tabstrip_index|, | 80 // window at index |expected_window_index|, at the |expected_tabstrip_index|, |
| 78 // and to be active. If |expected_window_index| is equal to the number of | 81 // and to be active. If |expected_window_index| is equal to the number of |
| 79 // current windows, the restored tab is expected to be created in a new | 82 // current windows, the restored tab is expected to be created in a new |
| 80 // window (since the index is 0-based). | 83 // window (since the index is 0-based). |
| 81 void RestoreTab(int expected_window_index, | 84 void RestoreTab(int expected_window_index, |
| 82 int expected_tabstrip_index) { | 85 int expected_tabstrip_index) { |
| 83 int window_count = static_cast<int>(BrowserList::size()); | 86 int window_count = static_cast<int>(native_browser_list->size()); |
| 84 ASSERT_GT(window_count, 0); | 87 ASSERT_GT(window_count, 0); |
| 85 | 88 |
| 86 bool expect_new_window = (expected_window_index == window_count); | 89 bool expect_new_window = (expected_window_index == window_count); |
| 87 | 90 |
| 88 Browser* browser; | 91 Browser* browser; |
| 89 if (expect_new_window) { | 92 if (expect_new_window) { |
| 90 browser = *(BrowserList::begin()); | 93 browser = native_browser_list->get(0); |
| 91 } else { | 94 } else { |
| 92 browser = GetBrowser(expected_window_index); | 95 browser = GetBrowser(expected_window_index); |
| 93 } | 96 } |
| 94 int tab_count = browser->tab_strip_model()->count(); | 97 int tab_count = browser->tab_strip_model()->count(); |
| 95 ASSERT_GT(tab_count, 0); | 98 ASSERT_GT(tab_count, 0); |
| 96 | 99 |
| 97 // Restore the tab. | 100 // Restore the tab. |
| 98 content::WindowedNotificationObserver tab_added_observer( | 101 content::WindowedNotificationObserver tab_added_observer( |
| 99 chrome::NOTIFICATION_TAB_PARENTED, | 102 chrome::NOTIFICATION_TAB_PARENTED, |
| 100 content::NotificationService::AllSources()); | 103 content::NotificationService::AllSources()); |
| 101 content::WindowedNotificationObserver tab_loaded_observer( | 104 content::WindowedNotificationObserver tab_loaded_observer( |
| 102 content::NOTIFICATION_LOAD_STOP, | 105 content::NOTIFICATION_LOAD_STOP, |
| 103 content::NotificationService::AllSources()); | 106 content::NotificationService::AllSources()); |
| 104 chrome::RestoreTab(browser); | 107 chrome::RestoreTab(browser); |
| 105 tab_added_observer.Wait(); | 108 tab_added_observer.Wait(); |
| 106 tab_loaded_observer.Wait(); | 109 tab_loaded_observer.Wait(); |
| 107 | 110 |
| 108 if (expect_new_window) { | 111 if (expect_new_window) { |
| 109 int new_window_count = static_cast<int>(BrowserList::size()); | 112 int new_window_count = static_cast<int>(native_browser_list->size()); |
| 110 EXPECT_EQ(++window_count, new_window_count); | 113 EXPECT_EQ(++window_count, new_window_count); |
| 111 browser = GetBrowser(expected_window_index); | 114 browser = GetBrowser(expected_window_index); |
| 112 } else { | 115 } else { |
| 113 EXPECT_EQ(++tab_count, browser->tab_strip_model()->count()); | 116 EXPECT_EQ(++tab_count, browser->tab_strip_model()->count()); |
| 114 } | 117 } |
| 115 | 118 |
| 116 // Get a handle to the restored tab. | 119 // Get a handle to the restored tab. |
| 117 ASSERT_GT(browser->tab_strip_model()->count(), expected_tabstrip_index); | 120 ASSERT_GT(browser->tab_strip_model()->count(), expected_tabstrip_index); |
| 118 | 121 |
| 119 // Ensure that the tab and window are active. | 122 // Ensure that the tab and window are active. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 137 | 140 |
| 138 content::WindowedNotificationObserver observer( | 141 content::WindowedNotificationObserver observer( |
| 139 content::NOTIFICATION_LOAD_STOP, | 142 content::NOTIFICATION_LOAD_STOP, |
| 140 content::Source<content::NavigationController>(controller)); | 143 content::Source<content::NavigationController>(controller)); |
| 141 observer.Wait(); | 144 observer.Wait(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 GURL url1_; | 147 GURL url1_; |
| 145 GURL url2_; | 148 GURL url2_; |
| 146 | 149 |
| 150 // The TabRestore browser tests only uses the native desktop for now. |
| 151 const chrome::BrowserListImpl* native_browser_list; |
| 152 |
| 147 private: | 153 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(TabRestoreTest); | 154 DISALLOW_COPY_AND_ASSIGN(TabRestoreTest); |
| 149 }; | 155 }; |
| 150 | 156 |
| 151 // Close the end tab in the current window, then restore it. The tab should be | 157 // Close the end tab in the current window, then restore it. The tab should be |
| 152 // in its original position, and active. | 158 // in its original position, and active. |
| 153 IN_PROC_BROWSER_TEST_F(TabRestoreTest, Basic) { | 159 IN_PROC_BROWSER_TEST_F(TabRestoreTest, Basic) { |
| 154 int starting_tab_count = browser()->tab_strip_model()->count(); | 160 int starting_tab_count = browser()->tab_strip_model()->count(); |
| 155 int tab_count = AddSomeTabs(browser(), 1); | 161 int tab_count = AddSomeTabs(browser(), 1); |
| 156 | 162 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 201 |
| 196 // Close one in the middle | 202 // Close one in the middle |
| 197 int closed_tab_index = starting_tab_count + 1; | 203 int closed_tab_index = starting_tab_count + 1; |
| 198 CloseTab(closed_tab_index); | 204 CloseTab(closed_tab_index); |
| 199 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); | 205 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); |
| 200 | 206 |
| 201 // Create a new browser. | 207 // Create a new browser. |
| 202 ui_test_utils::NavigateToURLWithDisposition( | 208 ui_test_utils::NavigateToURLWithDisposition( |
| 203 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 209 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
| 204 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 210 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 205 EXPECT_EQ(2u, BrowserList::size()); | 211 EXPECT_EQ(2u, native_browser_list->size()); |
| 206 | 212 |
| 207 // Restore tab into original browser. | 213 // Restore tab into original browser. |
| 208 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); | 214 ASSERT_NO_FATAL_FAILURE(RestoreTab(0, closed_tab_index)); |
| 209 | 215 |
| 210 // And make sure everything looks right. | 216 // And make sure everything looks right. |
| 211 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count()); | 217 EXPECT_EQ(starting_tab_count + 3, browser()->tab_strip_model()->count()); |
| 212 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index()); | 218 EXPECT_EQ(closed_tab_index, browser()->tab_strip_model()->active_index()); |
| 213 EXPECT_EQ(url1_, | 219 EXPECT_EQ(url1_, |
| 214 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 220 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 215 } | 221 } |
| 216 | 222 |
| 217 // Close a tab, open a new window, close the first window, then restore the | 223 // Close a tab, open a new window, close the first window, then restore the |
| 218 // tab. It should be in a new window. | 224 // tab. It should be in a new window. |
| 219 // If this becomes flaky, use http://crbug.com/14774 | 225 // If this becomes flaky, use http://crbug.com/14774 |
| 220 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DISABLED_BasicRestoreFromClosedWindow) { | 226 IN_PROC_BROWSER_TEST_F(TabRestoreTest, DISABLED_BasicRestoreFromClosedWindow) { |
| 221 // Navigate to url1 then url2. | 227 // Navigate to url1 then url2. |
| 222 ui_test_utils::NavigateToURL(browser(), url1_); | 228 ui_test_utils::NavigateToURL(browser(), url1_); |
| 223 ui_test_utils::NavigateToURL(browser(), url2_); | 229 ui_test_utils::NavigateToURL(browser(), url2_); |
| 224 | 230 |
| 225 // Create a new browser. | 231 // Create a new browser. |
| 226 ui_test_utils::NavigateToURLWithDisposition( | 232 ui_test_utils::NavigateToURLWithDisposition( |
| 227 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 233 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
| 228 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 234 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 229 EXPECT_EQ(2u, BrowserList::size()); | 235 EXPECT_EQ(2u, native_browser_list->size()); |
| 230 | 236 |
| 231 // Close the final tab in the first browser. | 237 // Close the final tab in the first browser. |
| 232 content::WindowedNotificationObserver window_observer( | 238 content::WindowedNotificationObserver window_observer( |
| 233 chrome::NOTIFICATION_BROWSER_CLOSED, | 239 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 234 content::NotificationService::AllSources()); | 240 content::NotificationService::AllSources()); |
| 235 CloseTab(0); | 241 CloseTab(0); |
| 236 window_observer.Wait(); | 242 window_observer.Wait(); |
| 237 | 243 |
| 238 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 244 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
| 239 | 245 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 287 |
| 282 // Close one in the middle | 288 // Close one in the middle |
| 283 int closed_tab_index = starting_tab_count + 1; | 289 int closed_tab_index = starting_tab_count + 1; |
| 284 CloseTab(closed_tab_index); | 290 CloseTab(closed_tab_index); |
| 285 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); | 291 EXPECT_EQ(starting_tab_count + 2, browser()->tab_strip_model()->count()); |
| 286 | 292 |
| 287 // Create a new browser. | 293 // Create a new browser. |
| 288 ui_test_utils::NavigateToURLWithDisposition( | 294 ui_test_utils::NavigateToURLWithDisposition( |
| 289 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 295 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
| 290 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 296 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 291 EXPECT_EQ(2u, BrowserList::size()); | 297 EXPECT_EQ(2u, native_browser_list->size()); |
| 292 | 298 |
| 293 // Close the first browser. | 299 // Close the first browser. |
| 294 content::WindowedNotificationObserver observer( | 300 content::WindowedNotificationObserver observer( |
| 295 chrome::NOTIFICATION_BROWSER_CLOSED, | 301 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 296 content::NotificationService::AllSources()); | 302 content::NotificationService::AllSources()); |
| 297 chrome::CloseWindow(browser()); | 303 chrome::CloseWindow(browser()); |
| 298 observer.Wait(); | 304 observer.Wait(); |
| 299 EXPECT_EQ(1u, BrowserList::size()); | 305 EXPECT_EQ(1u, native_browser_list->size()); |
| 300 | 306 |
| 301 // Restore the first window. The expected_tabstrip_index (second argument) | 307 // Restore the first window. The expected_tabstrip_index (second argument) |
| 302 // indicates the expected active tab. | 308 // indicates the expected active tab. |
| 303 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1)); | 309 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, starting_tab_count + 1)); |
| 304 Browser* browser = GetBrowser(1); | 310 Browser* browser = GetBrowser(1); |
| 305 EXPECT_EQ(starting_tab_count + 2, browser->tab_strip_model()->count()); | 311 EXPECT_EQ(starting_tab_count + 2, browser->tab_strip_model()->count()); |
| 306 | 312 |
| 307 // Restore the closed tab. | 313 // Restore the closed tab. |
| 308 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index)); | 314 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, closed_tab_index)); |
| 309 EXPECT_EQ(starting_tab_count + 3, browser->tab_strip_model()->count()); | 315 EXPECT_EQ(starting_tab_count + 3, browser->tab_strip_model()->count()); |
| 310 EXPECT_EQ(url1_, | 316 EXPECT_EQ(url1_, |
| 311 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 317 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 312 } | 318 } |
| 313 | 319 |
| 314 // Open a window with two tabs, close both (closing the window), then restore | 320 // Open a window with two tabs, close both (closing the window), then restore |
| 315 // both. Make sure both restored tabs are in the same window. | 321 // both. Make sure both restored tabs are in the same window. |
| 316 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) { | 322 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreIntoSameWindow) { |
| 317 ui_test_utils::NavigateToURLWithDisposition( | 323 ui_test_utils::NavigateToURLWithDisposition( |
| 318 browser(), url1_, NEW_FOREGROUND_TAB, | 324 browser(), url1_, NEW_FOREGROUND_TAB, |
| 319 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 325 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 320 // Navigate the rightmost one to url2_ for easier identification. | 326 // Navigate the rightmost one to url2_ for easier identification. |
| 321 ui_test_utils::NavigateToURLWithDisposition( | 327 ui_test_utils::NavigateToURLWithDisposition( |
| 322 browser(), url2_, NEW_FOREGROUND_TAB, | 328 browser(), url2_, NEW_FOREGROUND_TAB, |
| 323 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 329 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 324 | 330 |
| 325 // Create a new browser. | 331 // Create a new browser. |
| 326 ui_test_utils::NavigateToURLWithDisposition( | 332 ui_test_utils::NavigateToURLWithDisposition( |
| 327 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 333 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
| 328 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 334 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 329 EXPECT_EQ(2u, BrowserList::size()); | 335 EXPECT_EQ(2u, native_browser_list->size()); |
| 330 | 336 |
| 331 // Close all but one tab in the first browser, left to right. | 337 // Close all but one tab in the first browser, left to right. |
| 332 while (browser()->tab_strip_model()->count() > 1) | 338 while (browser()->tab_strip_model()->count() > 1) |
| 333 CloseTab(0); | 339 CloseTab(0); |
| 334 | 340 |
| 335 // Close the last tab, closing the browser. | 341 // Close the last tab, closing the browser. |
| 336 content::WindowedNotificationObserver observer( | 342 content::WindowedNotificationObserver observer( |
| 337 chrome::NOTIFICATION_BROWSER_CLOSED, | 343 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 338 content::NotificationService::AllSources()); | 344 content::NotificationService::AllSources()); |
| 339 CloseTab(0); | 345 CloseTab(0); |
| 340 observer.Wait(); | 346 observer.Wait(); |
| 341 EXPECT_EQ(1u, BrowserList::size()); | 347 EXPECT_EQ(1u, native_browser_list->size()); |
| 342 | 348 |
| 343 // Restore the last-closed tab into a new window. | 349 // Restore the last-closed tab into a new window. |
| 344 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 350 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
| 345 Browser* browser = GetBrowser(1); | 351 Browser* browser = GetBrowser(1); |
| 346 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 352 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| 347 EXPECT_EQ(url2_, | 353 EXPECT_EQ(url2_, |
| 348 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); | 354 browser->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 349 | 355 |
| 350 // Restore the next-to-last-closed tab into the same window. | 356 // Restore the next-to-last-closed tab into the same window. |
| 351 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); | 357 ASSERT_NO_FATAL_FAILURE(RestoreTab(1, 0)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 ui_test_utils::NavigateToURLWithDisposition( | 462 ui_test_utils::NavigateToURLWithDisposition( |
| 457 browser(), http_url2, CURRENT_TAB, | 463 browser(), http_url2, CURRENT_TAB, |
| 458 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 464 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 459 EXPECT_FALSE(chrome::CanGoForward(browser())); | 465 EXPECT_FALSE(chrome::CanGoForward(browser())); |
| 460 EXPECT_EQ(http_url2, | 466 EXPECT_EQ(http_url2, |
| 461 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); | 467 browser()->tab_strip_model()->GetActiveWebContents()->GetURL()); |
| 462 } | 468 } |
| 463 | 469 |
| 464 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) { | 470 IN_PROC_BROWSER_TEST_F(TabRestoreTest, RestoreWindow) { |
| 465 // Create a new window. | 471 // Create a new window. |
| 466 size_t window_count = BrowserList::size(); | 472 size_t window_count = native_browser_list->size(); |
| 467 ui_test_utils::NavigateToURLWithDisposition( | 473 ui_test_utils::NavigateToURLWithDisposition( |
| 468 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, | 474 browser(), GURL(chrome::kChromeUINewTabURL), NEW_WINDOW, |
| 469 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 475 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 470 EXPECT_EQ(++window_count, BrowserList::size()); | 476 EXPECT_EQ(++window_count, native_browser_list->size()); |
| 471 | 477 |
| 472 // Create two more tabs, one with url1, the other url2. | 478 // Create two more tabs, one with url1, the other url2. |
| 473 int initial_tab_count = browser()->tab_strip_model()->count(); | 479 int initial_tab_count = browser()->tab_strip_model()->count(); |
| 474 ui_test_utils::NavigateToURLWithDisposition( | 480 ui_test_utils::NavigateToURLWithDisposition( |
| 475 browser(), url1_, NEW_FOREGROUND_TAB, | 481 browser(), url1_, NEW_FOREGROUND_TAB, |
| 476 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 482 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 477 ui_test_utils::NavigateToURLWithDisposition( | 483 ui_test_utils::NavigateToURLWithDisposition( |
| 478 browser(), url2_, NEW_FOREGROUND_TAB, | 484 browser(), url2_, NEW_FOREGROUND_TAB, |
| 479 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 485 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 480 | 486 |
| 481 // Close the window. | 487 // Close the window. |
| 482 content::WindowedNotificationObserver close_window_observer( | 488 content::WindowedNotificationObserver close_window_observer( |
| 483 chrome::NOTIFICATION_BROWSER_CLOSED, | 489 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 484 content::NotificationService::AllSources()); | 490 content::NotificationService::AllSources()); |
| 485 chrome::CloseWindow(browser()); | 491 chrome::CloseWindow(browser()); |
| 486 close_window_observer.Wait(); | 492 close_window_observer.Wait(); |
| 487 EXPECT_EQ(window_count - 1, BrowserList::size()); | 493 EXPECT_EQ(window_count - 1, native_browser_list->size()); |
| 488 | 494 |
| 489 // Restore the window. | 495 // Restore the window. |
| 490 content::WindowedNotificationObserver open_window_observer( | 496 content::WindowedNotificationObserver open_window_observer( |
| 491 chrome::NOTIFICATION_BROWSER_OPENED, | 497 chrome::NOTIFICATION_BROWSER_OPENED, |
| 492 content::NotificationService::AllSources()); | 498 content::NotificationService::AllSources()); |
| 493 content::WindowedNotificationObserver load_stop_observer( | 499 content::WindowedNotificationObserver load_stop_observer( |
| 494 content::NOTIFICATION_LOAD_STOP, | 500 content::NOTIFICATION_LOAD_STOP, |
| 495 content::NotificationService::AllSources()); | 501 content::NotificationService::AllSources()); |
| 496 chrome::RestoreTab(*BrowserList::begin()); | 502 chrome::RestoreTab(native_browser_list->get(0)); |
| 497 open_window_observer.Wait(); | 503 open_window_observer.Wait(); |
| 498 EXPECT_EQ(window_count, BrowserList::size()); | 504 EXPECT_EQ(window_count, native_browser_list->size()); |
| 499 | 505 |
| 500 Browser* browser = GetBrowser(1); | 506 Browser* browser = GetBrowser(1); |
| 501 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count()); | 507 EXPECT_EQ(initial_tab_count + 2, browser->tab_strip_model()->count()); |
| 502 load_stop_observer.Wait(); | 508 load_stop_observer.Wait(); |
| 503 | 509 |
| 504 content::WebContents* restored_tab = | 510 content::WebContents* restored_tab = |
| 505 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count); | 511 browser->tab_strip_model()->GetWebContentsAt(initial_tab_count); |
| 506 EnsureTabFinishedRestoring(restored_tab); | 512 EnsureTabFinishedRestoring(restored_tab); |
| 507 EXPECT_EQ(url1_, restored_tab->GetURL()); | 513 EXPECT_EQ(url1_, restored_tab->GetURL()); |
| 508 | 514 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 EnsureTabFinishedRestoring(tab); | 565 EnsureTabFinishedRestoring(tab); |
| 560 ASSERT_EQ(http_url, tab->GetURL()); | 566 ASSERT_EQ(http_url, tab->GetURL()); |
| 561 | 567 |
| 562 // Go back, and see if content is as expected. | 568 // Go back, and see if content is as expected. |
| 563 GoBack(browser()); | 569 GoBack(browser()); |
| 564 EXPECT_GT( | 570 EXPECT_GT( |
| 565 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL, | 571 ui_test_utils::FindInPage(tab, ASCIIToUTF16("webkit"), true, false, NULL, |
| 566 NULL), | 572 NULL), |
| 567 0); | 573 0); |
| 568 } | 574 } |
| OLD | NEW |