| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/test/test_timeouts.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/defaults.h" | 11 #include "chrome/browser/defaults.h" |
| 11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
| 14 #include "chrome/test/automation/browser_proxy.h" | 15 #include "chrome/test/automation/browser_proxy.h" |
| 15 #include "chrome/test/automation/window_proxy.h" | 16 #include "chrome/test/automation/window_proxy.h" |
| 16 #include "chrome/test/ui/ui_test.h" | 17 #include "chrome/test/ui/ui_test.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int tab_count; | 70 int tab_count; |
| 70 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 71 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 71 ASSERT_EQ(1, tab_count); | 72 ASSERT_EQ(1, tab_count); |
| 72 | 73 |
| 73 int active_tab_index; | 74 int active_tab_index; |
| 74 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); | 75 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); |
| 75 ASSERT_EQ(0, active_tab_index); | 76 ASSERT_EQ(0, active_tab_index); |
| 76 | 77 |
| 77 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); | 78 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); |
| 78 ASSERT_TRUE(tab_proxy.get()); | 79 ASSERT_TRUE(tab_proxy.get()); |
| 79 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 80 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 81 TestTimeouts::action_max_timeout_ms())); |
| 80 | 82 |
| 81 ASSERT_TRUE(tab_proxy->GetCurrentURL(url)); | 83 ASSERT_TRUE(tab_proxy->GetCurrentURL(url)); |
| 82 } | 84 } |
| 83 | 85 |
| 84 GURL url1_; | 86 GURL url1_; |
| 85 GURL url2_; | 87 GURL url2_; |
| 86 GURL url3_; | 88 GURL url3_; |
| 87 | 89 |
| 88 private: | 90 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(SessionRestoreUITest); | 91 DISALLOW_COPY_AND_ASSIGN(SessionRestoreUITest); |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 TEST_F(SessionRestoreUITest, Basic) { | 94 TEST_F(SessionRestoreUITest, Basic) { |
| 93 NavigateToURL(url1_); | 95 NavigateToURL(url1_); |
| 94 NavigateToURL(url2_); | 96 NavigateToURL(url2_); |
| 95 | 97 |
| 96 QuitBrowserAndRestore(1); | 98 QuitBrowserAndRestore(1); |
| 97 | 99 |
| 98 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 100 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 99 // active windows returns NULL. | 101 // active windows returns NULL. |
| 100 int window_count; | 102 int window_count; |
| 101 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 103 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 102 ASSERT_EQ(1, window_count); | 104 ASSERT_EQ(1, window_count); |
| 103 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 105 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 104 ASSERT_TRUE(browser_proxy.get()); | 106 ASSERT_TRUE(browser_proxy.get()); |
| 105 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 107 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 106 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 108 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 109 TestTimeouts::action_max_timeout_ms())); |
| 107 | 110 |
| 108 ASSERT_EQ(url2_, GetActiveTabURL()); | 111 ASSERT_EQ(url2_, GetActiveTabURL()); |
| 109 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->GoBack()); | 112 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab_proxy->GoBack()); |
| 110 ASSERT_EQ(url1_, GetActiveTabURL()); | 113 ASSERT_EQ(url1_, GetActiveTabURL()); |
| 111 } | 114 } |
| 112 | 115 |
| 113 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { | 116 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { |
| 114 NavigateToURL(url1_); | 117 NavigateToURL(url1_); |
| 115 NavigateToURL(url2_); | 118 NavigateToURL(url2_); |
| 116 NavigateToURL(url3_); | 119 NavigateToURL(url3_); |
| 117 | 120 |
| 118 scoped_refptr<TabProxy> active_tab(GetActiveTab()); | 121 scoped_refptr<TabProxy> active_tab(GetActiveTab()); |
| 119 ASSERT_TRUE(active_tab.get()); | 122 ASSERT_TRUE(active_tab.get()); |
| 120 ASSERT_TRUE(active_tab->GoBack()); | 123 ASSERT_TRUE(active_tab->GoBack()); |
| 121 | 124 |
| 122 QuitBrowserAndRestore(1); | 125 QuitBrowserAndRestore(1); |
| 123 | 126 |
| 124 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 127 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 125 // active windows returns NULL. | 128 // active windows returns NULL. |
| 126 int window_count; | 129 int window_count; |
| 127 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 130 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 128 ASSERT_EQ(1, window_count); | 131 ASSERT_EQ(1, window_count); |
| 129 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 132 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 130 ASSERT_TRUE(browser_proxy.get()); | 133 ASSERT_TRUE(browser_proxy.get()); |
| 131 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 134 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 132 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 135 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 136 TestTimeouts::action_max_timeout_ms())); |
| 133 | 137 |
| 134 ASSERT_TRUE(GetActiveTabURL() == url2_); | 138 ASSERT_TRUE(GetActiveTabURL() == url2_); |
| 135 ASSERT_TRUE(tab_proxy->GoForward()); | 139 ASSERT_TRUE(tab_proxy->GoForward()); |
| 136 ASSERT_TRUE(GetActiveTabURL() == url3_); | 140 ASSERT_TRUE(GetActiveTabURL() == url3_); |
| 137 ASSERT_TRUE(tab_proxy->GoBack()); | 141 ASSERT_TRUE(tab_proxy->GoBack()); |
| 138 ASSERT_TRUE(GetActiveTabURL() == url2_); | 142 ASSERT_TRUE(GetActiveTabURL() == url2_); |
| 139 ASSERT_TRUE(tab_proxy->GoBack()); | 143 ASSERT_TRUE(tab_proxy->GoBack()); |
| 140 ASSERT_TRUE(GetActiveTabURL() == url1_); | 144 ASSERT_TRUE(GetActiveTabURL() == url1_); |
| 141 } | 145 } |
| 142 | 146 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 166 int window_count; | 170 int window_count; |
| 167 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 171 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 168 ASSERT_EQ(1, window_count); | 172 ASSERT_EQ(1, window_count); |
| 169 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 173 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 170 ASSERT_TRUE(browser_proxy.get()); | 174 ASSERT_TRUE(browser_proxy.get()); |
| 171 int tab_count; | 175 int tab_count; |
| 172 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 176 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 173 ASSERT_EQ(1, tab_count); | 177 ASSERT_EQ(1, tab_count); |
| 174 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 178 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 175 ASSERT_TRUE(tab_proxy.get()); | 179 ASSERT_TRUE(tab_proxy.get()); |
| 176 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 180 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 181 TestTimeouts::action_max_timeout_ms())); |
| 177 | 182 |
| 178 // Check that back and forward work as expected. | 183 // Check that back and forward work as expected. |
| 179 GURL url; | 184 GURL url; |
| 180 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); | 185 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); |
| 181 ASSERT_EQ(cross_site_url, url); | 186 ASSERT_EQ(cross_site_url, url); |
| 182 | 187 |
| 183 ASSERT_TRUE(tab_proxy->GoBack()); | 188 ASSERT_TRUE(tab_proxy->GoBack()); |
| 184 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); | 189 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); |
| 185 ASSERT_EQ(url1_, url); | 190 ASSERT_EQ(url1_, url); |
| 186 | 191 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 216 int tab_count; | 221 int tab_count; |
| 217 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 222 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 218 ASSERT_EQ(2, tab_count); | 223 ASSERT_EQ(2, tab_count); |
| 219 | 224 |
| 220 int active_tab_index; | 225 int active_tab_index; |
| 221 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); | 226 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); |
| 222 ASSERT_EQ(1, active_tab_index); | 227 ASSERT_EQ(1, active_tab_index); |
| 223 | 228 |
| 224 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); | 229 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); |
| 225 ASSERT_TRUE(tab_proxy.get()); | 230 ASSERT_TRUE(tab_proxy.get()); |
| 226 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 231 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 232 TestTimeouts::action_max_timeout_ms())); |
| 227 | 233 |
| 228 ASSERT_EQ(url2_, GetActiveTabURL()); | 234 ASSERT_EQ(url2_, GetActiveTabURL()); |
| 229 | 235 |
| 230 ASSERT_TRUE(browser_proxy->ActivateTab(0)); | 236 ASSERT_TRUE(browser_proxy->ActivateTab(0)); |
| 231 tab_proxy = browser_proxy->GetActiveTab(); | 237 tab_proxy = browser_proxy->GetActiveTab(); |
| 232 ASSERT_TRUE(tab_proxy.get()); | 238 ASSERT_TRUE(tab_proxy.get()); |
| 233 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 239 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 240 TestTimeouts::action_max_timeout_ms())); |
| 234 | 241 |
| 235 ASSERT_EQ(url1_, GetActiveTabURL()); | 242 ASSERT_EQ(url1_, GetActiveTabURL()); |
| 236 } | 243 } |
| 237 | 244 |
| 238 // Creates two tabs, closes one, quits and makes sure only one tab is restored. | 245 // Creates two tabs, closes one, quits and makes sure only one tab is restored. |
| 239 TEST_F(SessionRestoreUITest, ClosedTabStaysClosed) { | 246 TEST_F(SessionRestoreUITest, ClosedTabStaysClosed) { |
| 240 NavigateToURL(url1_); | 247 NavigateToURL(url1_); |
| 241 | 248 |
| 242 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 249 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 243 // active windows returns NULL. | 250 // active windows returns NULL. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 LaunchAnotherBrowserBlockUntilClosed(launch_arguments_); | 370 LaunchAnotherBrowserBlockUntilClosed(launch_arguments_); |
| 364 | 371 |
| 365 // A new window should appear; | 372 // A new window should appear; |
| 366 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2)); | 373 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2)); |
| 367 | 374 |
| 368 // And it shouldn't have url1_ in it. | 375 // And it shouldn't have url1_ in it. |
| 369 browser_proxy = automation()->GetBrowserWindow(1); | 376 browser_proxy = automation()->GetBrowserWindow(1); |
| 370 ASSERT_TRUE(browser_proxy.get()); | 377 ASSERT_TRUE(browser_proxy.get()); |
| 371 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 378 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 372 ASSERT_TRUE(tab_proxy.get()); | 379 ASSERT_TRUE(tab_proxy.get()); |
| 373 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 380 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 381 TestTimeouts::action_max_timeout_ms())); |
| 374 GURL url; | 382 GURL url; |
| 375 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); | 383 ASSERT_TRUE(tab_proxy->GetCurrentURL(&url)); |
| 376 ASSERT_TRUE(url != url1_); | 384 ASSERT_TRUE(url != url1_); |
| 377 } | 385 } |
| 378 | 386 |
| 379 // Launches an app window, closes tabbed browser, launches and makes sure | 387 // Launches an app window, closes tabbed browser, launches and makes sure |
| 380 // we restore the tabbed browser url. | 388 // we restore the tabbed browser url. |
| 381 // Flaky: http://crbug.com/29110 | 389 // Flaky: http://crbug.com/29110 |
| 382 TEST_F(SessionRestoreUITest, | 390 TEST_F(SessionRestoreUITest, |
| 383 FLAKY_RestoreAfterClosingTabbedBrowserWithAppAndLaunching) { | 391 FLAKY_RestoreAfterClosingTabbedBrowserWithAppAndLaunching) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 478 |
| 471 // Wait for each tab to finish being restored, then make sure the process | 479 // Wait for each tab to finish being restored, then make sure the process |
| 472 // count matches. | 480 // count matches. |
| 473 browser_proxy = automation()->GetBrowserWindow(0); | 481 browser_proxy = automation()->GetBrowserWindow(0); |
| 474 ASSERT_TRUE(browser_proxy.get() != NULL); | 482 ASSERT_TRUE(browser_proxy.get() != NULL); |
| 475 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 483 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 476 ASSERT_EQ(expected_tab_count, tab_count); | 484 ASSERT_EQ(expected_tab_count, tab_count); |
| 477 | 485 |
| 478 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 2)); | 486 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 2)); |
| 479 ASSERT_TRUE(tab_proxy.get() != NULL); | 487 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 480 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 488 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 489 TestTimeouts::action_max_timeout_ms())); |
| 481 tab_proxy = browser_proxy->GetTab(tab_count - 1); | 490 tab_proxy = browser_proxy->GetTab(tab_count - 1); |
| 482 ASSERT_TRUE(tab_proxy.get() != NULL); | 491 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 483 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_max_timeout_ms())); | 492 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored( |
| 493 TestTimeouts::action_max_timeout_ms())); |
| 484 | 494 |
| 485 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); | 495 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); |
| 486 } | 496 } |
| 487 | 497 |
| 488 } // namespace | 498 } // namespace |
| OLD | NEW |