| 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_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/automation/tab_proxy.h" | 12 #include "chrome/test/automation/tab_proxy.h" |
| 12 #include "chrome/test/automation/browser_proxy.h" | 13 #include "chrome/test/automation/browser_proxy.h" |
| 13 #include "chrome/test/automation/window_proxy.h" | 14 #include "chrome/test/automation/window_proxy.h" |
| 14 #include "chrome/test/ui/ui_test.h" | 15 #include "chrome/test/ui/ui_test.h" |
| 15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 16 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 17 #include "net/url_request/url_request_unittest.h" | 18 #include "net/url_request/url_request_unittest.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class SessionRestoreUITest : public UITest { | 22 class SessionRestoreUITest : public UITest { |
| 22 protected: | 23 protected: |
| 23 SessionRestoreUITest() : UITest() { | 24 SessionRestoreUITest() : UITest() { |
| 24 FilePath path_prefix = FilePath::FromWStringHack(test_data_directory_); | 25 FilePath path_prefix = FilePath::FromWStringHack(test_data_directory_); |
| 25 path_prefix = path_prefix.AppendASCII("session_history") | 26 path_prefix = path_prefix.AppendASCII("session_history") |
| 26 .Append(FilePath::StringType(&FilePath::kSeparators[0], 1)); | 27 .Append(FilePath::StringType(&FilePath::kSeparators[0], 1)); |
| 27 | 28 |
| 28 url1 = net::FilePathToFileURL( | 29 url1 = net::FilePathToFileURL( |
| 29 path_prefix.AppendASCII("bot1.html")); | 30 path_prefix.AppendASCII("bot1.html")); |
| 30 url2 = net::FilePathToFileURL( | 31 url2 = net::FilePathToFileURL( |
| 31 path_prefix.AppendASCII("bot2.html")); | 32 path_prefix.AppendASCII("bot2.html")); |
| 32 url3 = net::FilePathToFileURL( | 33 url3 = net::FilePathToFileURL( |
| 33 path_prefix.AppendASCII("bot3.html")); | 34 path_prefix.AppendASCII("bot3.html")); |
| 34 } | 35 } |
| 35 | 36 |
| 36 virtual void QuitBrowserAndRestore() { | 37 virtual void QuitBrowserAndRestore(int expected_tab_count) { |
| 37 UITest::TearDown(); | 38 UITest::TearDown(); |
| 38 | 39 |
| 39 clear_profile_ = false; | 40 clear_profile_ = false; |
| 40 | 41 |
| 41 launch_arguments_.AppendSwitch(switches::kRestoreLastSession); | 42 launch_arguments_.AppendSwitchWithValue(switches::kRestoreLastSession, |
| 43 IntToWString(expected_tab_count)); |
| 42 UITest::SetUp(); | 44 UITest::SetUp(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void CloseWindow(int window_index, int initial_count) { | 47 void CloseWindow(int window_index, int initial_count) { |
| 46 scoped_ptr<BrowserProxy> browser_proxy( | 48 scoped_ptr<BrowserProxy> browser_proxy( |
| 47 automation()->GetBrowserWindow(window_index)); | 49 automation()->GetBrowserWindow(window_index)); |
| 48 ASSERT_TRUE(browser_proxy.get()); | 50 ASSERT_TRUE(browser_proxy.get()); |
| 49 ASSERT_TRUE(browser_proxy->ApplyAccelerator(IDC_CLOSE_WINDOW)); | 51 ASSERT_TRUE(browser_proxy->ApplyAccelerator(IDC_CLOSE_WINDOW)); |
| 50 browser_proxy.reset(); | 52 browser_proxy.reset(); |
| 51 int window_count; | 53 int window_count; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 private: | 91 private: |
| 90 DISALLOW_EVIL_CONSTRUCTORS(SessionRestoreUITest); | 92 DISALLOW_EVIL_CONSTRUCTORS(SessionRestoreUITest); |
| 91 }; | 93 }; |
| 92 | 94 |
| 93 } // namespace | 95 } // namespace |
| 94 | 96 |
| 95 TEST_F(SessionRestoreUITest, Basic) { | 97 TEST_F(SessionRestoreUITest, Basic) { |
| 96 NavigateToURL(url1); | 98 NavigateToURL(url1); |
| 97 NavigateToURL(url2); | 99 NavigateToURL(url2); |
| 98 | 100 |
| 99 QuitBrowserAndRestore(); | 101 QuitBrowserAndRestore(1); |
| 100 | 102 |
| 101 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 103 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 102 // active windows returns NULL. | 104 // active windows returns NULL. |
| 103 int window_count; | 105 int window_count; |
| 104 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 106 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 105 window_count == 1); | 107 window_count == 1); |
| 106 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 108 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 107 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 109 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 108 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 110 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 109 | 111 |
| 110 ASSERT_EQ(url2, GetActiveTabURL()); | 112 ASSERT_EQ(url2, GetActiveTabURL()); |
| 111 tab_proxy->GoBack(); | 113 tab_proxy->GoBack(); |
| 112 ASSERT_EQ(url1, GetActiveTabURL()); | 114 ASSERT_EQ(url1, GetActiveTabURL()); |
| 113 } | 115 } |
| 114 | 116 |
| 115 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { | 117 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { |
| 116 NavigateToURL(url1); | 118 NavigateToURL(url1); |
| 117 NavigateToURL(url2); | 119 NavigateToURL(url2); |
| 118 NavigateToURL(url3); | 120 NavigateToURL(url3); |
| 119 | 121 |
| 120 scoped_ptr<TabProxy> active_tab(GetActiveTab()); | 122 scoped_ptr<TabProxy> active_tab(GetActiveTab()); |
| 121 ASSERT_TRUE(active_tab->GoBack()); | 123 ASSERT_TRUE(active_tab->GoBack()); |
| 122 | 124 |
| 123 QuitBrowserAndRestore(); | 125 QuitBrowserAndRestore(1); |
| 124 | 126 |
| 125 // 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 |
| 126 // active windows returns NULL. | 128 // active windows returns NULL. |
| 127 int window_count; | 129 int window_count; |
| 128 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 130 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 129 window_count == 1); | 131 window_count == 1); |
| 130 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 132 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 131 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 133 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 132 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 134 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 133 | 135 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 151 GURL cross_site_url(server->TestServerPageW(L"files/title2.html")); | 153 GURL cross_site_url(server->TestServerPageW(L"files/title2.html")); |
| 152 | 154 |
| 153 // Visit URLs on different sites. | 155 // Visit URLs on different sites. |
| 154 NavigateToURL(url1); | 156 NavigateToURL(url1); |
| 155 NavigateToURL(cross_site_url); | 157 NavigateToURL(cross_site_url); |
| 156 NavigateToURL(url2); | 158 NavigateToURL(url2); |
| 157 | 159 |
| 158 scoped_ptr<TabProxy> active_tab(GetActiveTab()); | 160 scoped_ptr<TabProxy> active_tab(GetActiveTab()); |
| 159 ASSERT_TRUE(active_tab->GoBack()); | 161 ASSERT_TRUE(active_tab->GoBack()); |
| 160 | 162 |
| 161 QuitBrowserAndRestore(); | 163 QuitBrowserAndRestore(1); |
| 162 | 164 |
| 163 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 165 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 164 // active windows returns NULL. | 166 // active windows returns NULL. |
| 165 int window_count; | 167 int window_count; |
| 166 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 168 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 167 window_count == 1); | 169 window_count == 1); |
| 168 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 170 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 169 int tab_count; | 171 int tab_count; |
| 170 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count) && tab_count == 1); | 172 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count) && tab_count == 1); |
| 171 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 173 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 194 | 196 |
| 195 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 197 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 196 // active windows returns NULL. | 198 // active windows returns NULL. |
| 197 int window_count; | 199 int window_count; |
| 198 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 200 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 199 window_count == 1); | 201 window_count == 1); |
| 200 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 202 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 201 | 203 |
| 202 ASSERT_TRUE(browser_proxy->AppendTab(url2)); | 204 ASSERT_TRUE(browser_proxy->AppendTab(url2)); |
| 203 | 205 |
| 204 QuitBrowserAndRestore(); | 206 QuitBrowserAndRestore(2); |
| 205 browser_proxy.reset(); | 207 browser_proxy.reset(); |
| 206 | 208 |
| 207 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 209 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 208 window_count == 1); | 210 window_count == 1); |
| 209 browser_proxy.reset(automation()->GetBrowserWindow(0)); | 211 browser_proxy.reset(automation()->GetBrowserWindow(0)); |
| 210 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 212 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 211 | 213 |
| 212 int tab_count; | 214 int tab_count; |
| 213 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 215 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 214 ASSERT_EQ(2, tab_count); | 216 ASSERT_EQ(2, tab_count); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 239 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 241 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 240 window_count == 1); | 242 window_count == 1); |
| 241 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 243 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 242 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 244 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 243 | 245 |
| 244 browser_proxy->AppendTab(url2); | 246 browser_proxy->AppendTab(url2); |
| 245 | 247 |
| 246 scoped_ptr<TabProxy> active_tab(browser_proxy->GetActiveTab()); | 248 scoped_ptr<TabProxy> active_tab(browser_proxy->GetActiveTab()); |
| 247 active_tab->Close(true); | 249 active_tab->Close(true); |
| 248 | 250 |
| 249 QuitBrowserAndRestore(); | 251 QuitBrowserAndRestore(1); |
| 250 browser_proxy.reset(); | 252 browser_proxy.reset(); |
| 251 tab_proxy.reset(); | 253 tab_proxy.reset(); |
| 252 | 254 |
| 253 AssertOneWindowWithOneTab(); | 255 AssertOneWindowWithOneTab(); |
| 254 | 256 |
| 255 ASSERT_TRUE(GetActiveTabURL() == url1); | 257 ASSERT_TRUE(GetActiveTabURL() == url1); |
| 256 } | 258 } |
| 257 | 259 |
| 258 // This test is failing on win2k. | 260 // This test is failing on win2k. |
| 259 // | 261 // |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 int window_count; | 323 int window_count; |
| 322 ASSERT_TRUE(automation()->WaitForWindowCountToChange(1, &window_count, | 324 ASSERT_TRUE(automation()->WaitForWindowCountToChange(1, &window_count, |
| 323 action_timeout_ms()) && | 325 action_timeout_ms()) && |
| 324 window_count == 2); | 326 window_count == 2); |
| 325 | 327 |
| 326 // Close it. | 328 // Close it. |
| 327 CloseWindow(1, 2); | 329 CloseWindow(1, 2); |
| 328 | 330 |
| 329 // Restart and make sure we have only one window with one tab and the url | 331 // Restart and make sure we have only one window with one tab and the url |
| 330 // is url1. | 332 // is url1. |
| 331 QuitBrowserAndRestore(); | 333 QuitBrowserAndRestore(1); |
| 332 | 334 |
| 333 AssertOneWindowWithOneTab(); | 335 AssertOneWindowWithOneTab(); |
| 334 | 336 |
| 335 ASSERT_TRUE(GetActiveTabURL() == url1); | 337 ASSERT_TRUE(GetActiveTabURL() == url1); |
| 336 } | 338 } |
| 337 | 339 |
| 338 // This test is disabled because it's triggering a bug in chrome_plugin_host. | 340 // This test is disabled because it's triggering a bug in chrome_plugin_host. |
| 339 // | 341 // |
| 340 // Launches an app window, closes tabbed browser, launches and makes sure | 342 // Launches an app window, closes tabbed browser, launches and makes sure |
| 341 // we restore the tabbed browser url. | 343 // we restore the tabbed browser url. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 action_timeout_ms())); | 407 action_timeout_ms())); |
| 406 last_tab.reset(browser_proxy->GetTab(new_tab_count - 1)); | 408 last_tab.reset(browser_proxy->GetTab(new_tab_count - 1)); |
| 407 ASSERT_TRUE(last_tab.get() != NULL); | 409 ASSERT_TRUE(last_tab.get() != NULL); |
| 408 // Do a reload to ensure new tab page has loaded. | 410 // Do a reload to ensure new tab page has loaded. |
| 409 ASSERT_TRUE(last_tab->Reload()); | 411 ASSERT_TRUE(last_tab->Reload()); |
| 410 int expected_process_count = GetBrowserProcessCount(); | 412 int expected_process_count = GetBrowserProcessCount(); |
| 411 | 413 |
| 412 // Restart. | 414 // Restart. |
| 413 browser_proxy.reset(); | 415 browser_proxy.reset(); |
| 414 last_tab.reset(); | 416 last_tab.reset(); |
| 415 QuitBrowserAndRestore(); | 417 QuitBrowserAndRestore(3); |
| 416 | 418 |
| 417 // Wait for each tab to finish being restored, then make sure the process | 419 // Wait for each tab to finish being restored, then make sure the process |
| 418 // count matches. | 420 // count matches. |
| 419 browser_proxy.reset(automation()->GetBrowserWindow(0)); | 421 browser_proxy.reset(automation()->GetBrowserWindow(0)); |
| 420 ASSERT_TRUE(browser_proxy.get() != NULL); | 422 ASSERT_TRUE(browser_proxy.get() != NULL); |
| 421 int restored_tab_count; | 423 int restored_tab_count; |
| 422 ASSERT_TRUE(browser_proxy->GetTabCount(&restored_tab_count)); | 424 ASSERT_TRUE(browser_proxy->GetTabCount(&restored_tab_count)); |
| 423 ASSERT_EQ(new_tab_count, restored_tab_count); | 425 ASSERT_EQ(new_tab_count, restored_tab_count); |
| 424 | 426 |
| 425 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(restored_tab_count - 2)); | 427 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(restored_tab_count - 2)); |
| 426 ASSERT_TRUE(tab_proxy.get() != NULL); | 428 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 427 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 429 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 428 tab_proxy.reset(browser_proxy->GetTab(restored_tab_count - 1)); | 430 tab_proxy.reset(browser_proxy->GetTab(restored_tab_count - 1)); |
| 429 ASSERT_TRUE(tab_proxy.get() != NULL); | 431 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 430 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 432 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 431 | 433 |
| 432 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); | 434 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); |
| 433 } | 435 } |
| OLD | NEW |