| 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_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 27 matching lines...) Expand all Loading... |
| 38 IntToWString(expected_tab_count)); | 38 IntToWString(expected_tab_count)); |
| 39 UITest::SetUp(); | 39 UITest::SetUp(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CloseWindow(int window_index, int initial_count) { | 42 void CloseWindow(int window_index, int initial_count) { |
| 43 scoped_refptr<BrowserProxy> browser_proxy( | 43 scoped_refptr<BrowserProxy> browser_proxy( |
| 44 automation()->GetBrowserWindow(window_index)); | 44 automation()->GetBrowserWindow(window_index)); |
| 45 ASSERT_TRUE(browser_proxy.get()); | 45 ASSERT_TRUE(browser_proxy.get()); |
| 46 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); | 46 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); |
| 47 int window_count; | 47 int window_count; |
| 48 automation()->GetBrowserWindowCount(&window_count); | 48 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 49 ASSERT_EQ(initial_count - 1, window_count); | 49 ASSERT_EQ(initial_count - 1, window_count); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void AssertOneWindowWithOneTab() { | 52 void AssertOneWindowWithOneTab() { |
| 53 int window_count; | 53 int window_count; |
| 54 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 54 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 55 ASSERT_EQ(1, window_count); | 55 ASSERT_EQ(1, window_count); |
| 56 GURL url; | 56 GURL url; |
| 57 AssertWindowHasOneTab(0, &url); | 57 AssertWindowHasOneTab(0, &url); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void AssertWindowHasOneTab(int window_index, GURL* url) { | 60 void AssertWindowHasOneTab(int window_index, GURL* url) { |
| 61 scoped_refptr<BrowserProxy> browser_proxy( | 61 scoped_refptr<BrowserProxy> browser_proxy( |
| 62 automation()->GetBrowserWindow(window_index)); | 62 automation()->GetBrowserWindow(window_index)); |
| 63 ASSERT_TRUE(browser_proxy.get()); | 63 ASSERT_TRUE(browser_proxy.get()); |
| 64 | 64 |
| 65 int tab_count; | 65 int tab_count; |
| 66 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 66 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 67 ASSERT_EQ(1, tab_count); | 67 ASSERT_EQ(1, tab_count); |
| 68 | 68 |
| 69 int active_tab_index; | 69 int active_tab_index; |
| 70 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); | 70 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); |
| 71 ASSERT_EQ(0, active_tab_index); | 71 ASSERT_EQ(0, active_tab_index); |
| 72 | 72 |
| 73 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); | 73 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); |
| 74 ASSERT_TRUE(tab_proxy.get()); |
| 74 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 75 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 75 | 76 |
| 76 ASSERT_TRUE(tab_proxy->GetCurrentURL(url)); | 77 ASSERT_TRUE(tab_proxy->GetCurrentURL(url)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 GURL url1_; | 80 GURL url1_; |
| 80 GURL url2_; | 81 GURL url2_; |
| 81 GURL url3_; | 82 GURL url3_; |
| 82 | 83 |
| 83 private: | 84 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 103 tab_proxy->GoBack(); | 104 tab_proxy->GoBack(); |
| 104 ASSERT_EQ(url1_, GetActiveTabURL()); | 105 ASSERT_EQ(url1_, GetActiveTabURL()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { | 108 TEST_F(SessionRestoreUITest, RestoresForwardAndBackwardNavs) { |
| 108 NavigateToURL(url1_); | 109 NavigateToURL(url1_); |
| 109 NavigateToURL(url2_); | 110 NavigateToURL(url2_); |
| 110 NavigateToURL(url3_); | 111 NavigateToURL(url3_); |
| 111 | 112 |
| 112 scoped_refptr<TabProxy> active_tab(GetActiveTab()); | 113 scoped_refptr<TabProxy> active_tab(GetActiveTab()); |
| 114 ASSERT_TRUE(active_tab.get()); |
| 113 ASSERT_TRUE(active_tab->GoBack()); | 115 ASSERT_TRUE(active_tab->GoBack()); |
| 114 | 116 |
| 115 QuitBrowserAndRestore(1); | 117 QuitBrowserAndRestore(1); |
| 116 | 118 |
| 117 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 119 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 118 // active windows returns NULL. | 120 // active windows returns NULL. |
| 119 int window_count; | 121 int window_count; |
| 120 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 122 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 121 window_count == 1); | 123 window_count == 1); |
| 122 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 124 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 141 HTTPTestServer::CreateServer(kDocRoot, NULL); | 143 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 142 ASSERT_TRUE(NULL != server.get()); | 144 ASSERT_TRUE(NULL != server.get()); |
| 143 GURL cross_site_url(server->TestServerPageW(L"files/title2.html")); | 145 GURL cross_site_url(server->TestServerPageW(L"files/title2.html")); |
| 144 | 146 |
| 145 // Visit URLs on different sites. | 147 // Visit URLs on different sites. |
| 146 NavigateToURL(url1_); | 148 NavigateToURL(url1_); |
| 147 NavigateToURL(cross_site_url); | 149 NavigateToURL(cross_site_url); |
| 148 NavigateToURL(url2_); | 150 NavigateToURL(url2_); |
| 149 | 151 |
| 150 scoped_refptr<TabProxy> active_tab(GetActiveTab()); | 152 scoped_refptr<TabProxy> active_tab(GetActiveTab()); |
| 153 ASSERT_TRUE(active_tab.get()); |
| 151 ASSERT_TRUE(active_tab->GoBack()); | 154 ASSERT_TRUE(active_tab->GoBack()); |
| 152 | 155 |
| 153 QuitBrowserAndRestore(1); | 156 QuitBrowserAndRestore(1); |
| 154 | 157 |
| 155 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 158 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 156 // active windows returns NULL. | 159 // active windows returns NULL. |
| 157 int window_count; | 160 int window_count; |
| 158 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 161 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 159 window_count == 1); | 162 window_count == 1); |
| 160 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 163 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 195 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 193 | 196 |
| 194 ASSERT_TRUE(browser_proxy->AppendTab(url2_)); | 197 ASSERT_TRUE(browser_proxy->AppendTab(url2_)); |
| 195 | 198 |
| 196 QuitBrowserAndRestore(2); | 199 QuitBrowserAndRestore(2); |
| 197 browser_proxy = NULL; | 200 browser_proxy = NULL; |
| 198 | 201 |
| 199 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 202 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 200 window_count == 1); | 203 window_count == 1); |
| 201 browser_proxy = automation()->GetBrowserWindow(0); | 204 browser_proxy = automation()->GetBrowserWindow(0); |
| 202 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | |
| 203 | 205 |
| 204 int tab_count; | 206 int tab_count; |
| 205 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); | 207 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); |
| 206 ASSERT_EQ(2, tab_count); | 208 ASSERT_EQ(2, tab_count); |
| 207 | 209 |
| 208 int active_tab_index; | 210 int active_tab_index; |
| 209 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); | 211 ASSERT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index)); |
| 210 ASSERT_EQ(1, active_tab_index); | 212 ASSERT_EQ(1, active_tab_index); |
| 211 | 213 |
| 212 tab_proxy = browser_proxy->GetActiveTab(); | 214 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetActiveTab()); |
| 215 ASSERT_TRUE(tab_proxy.get()); |
| 213 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 216 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 214 | 217 |
| 215 ASSERT_TRUE(GetActiveTabURL() == url2_); | 218 ASSERT_TRUE(GetActiveTabURL() == url2_); |
| 216 | 219 |
| 217 ASSERT_TRUE(browser_proxy->ActivateTab(0)); | 220 ASSERT_TRUE(browser_proxy->ActivateTab(0)); |
| 218 tab_proxy = browser_proxy->GetActiveTab(); | 221 tab_proxy = browser_proxy->GetActiveTab(); |
| 222 ASSERT_TRUE(tab_proxy.get()); |
| 219 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 223 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 220 | 224 |
| 221 ASSERT_TRUE(GetActiveTabURL() == url1_); | 225 ASSERT_TRUE(GetActiveTabURL() == url1_); |
| 222 } | 226 } |
| 223 | 227 |
| 224 // Creates two tabs, closes one, quits and makes sure only one tab is restored. | 228 // Creates two tabs, closes one, quits and makes sure only one tab is restored. |
| 225 TEST_F(SessionRestoreUITest, ClosedTabStaysClosed) { | 229 TEST_F(SessionRestoreUITest, ClosedTabStaysClosed) { |
| 226 NavigateToURL(url1_); | 230 NavigateToURL(url1_); |
| 227 | 231 |
| 228 // NOTE: Don't use GetActiveWindow here, when run with the screen locked | 232 // NOTE: Don't use GetActiveWindow here, when run with the screen locked |
| 229 // active windows returns NULL. | 233 // active windows returns NULL. |
| 230 int window_count; | 234 int window_count; |
| 231 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && | 235 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count) && |
| 232 window_count == 1); | 236 window_count == 1); |
| 233 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 237 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 234 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); | 238 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); |
| 235 | 239 |
| 236 browser_proxy->AppendTab(url2_); | 240 browser_proxy->AppendTab(url2_); |
| 237 | 241 |
| 238 scoped_refptr<TabProxy> active_tab(browser_proxy->GetActiveTab()); | 242 scoped_refptr<TabProxy> active_tab(browser_proxy->GetActiveTab()); |
| 243 ASSERT_TRUE(active_tab.get()); |
| 239 active_tab->Close(true); | 244 active_tab->Close(true); |
| 240 | 245 |
| 241 QuitBrowserAndRestore(1); | 246 QuitBrowserAndRestore(1); |
| 242 browser_proxy = NULL; | 247 browser_proxy = NULL; |
| 243 tab_proxy = NULL; | 248 tab_proxy = NULL; |
| 244 | 249 |
| 245 AssertOneWindowWithOneTab(); | 250 AssertOneWindowWithOneTab(); |
| 246 | 251 |
| 247 ASSERT_TRUE(GetActiveTabURL() == url1_); | 252 ASSERT_TRUE(GetActiveTabURL() == url1_); |
| 248 } | 253 } |
| 249 | 254 |
| 250 #if defined(OS_WIN) | 255 #if defined(OS_WIN) |
| 251 // Creates a browser, goes incognito, closes browser, launches and make sure | 256 // Creates a browser, goes incognito, closes browser, launches and make sure |
| 252 // we don't restore. | 257 // we don't restore. |
| 253 TEST_F(SessionRestoreUITest, DontRestoreWhileIncognito) { | 258 TEST_F(SessionRestoreUITest, DontRestoreWhileIncognito) { |
| 254 NavigateToURL(url1_); | 259 NavigateToURL(url1_); |
| 255 | 260 |
| 256 // Make sure we have one window. | 261 // Make sure we have one window. |
| 257 int initial_window_count; | 262 int initial_window_count; |
| 258 ASSERT_TRUE(automation()->GetBrowserWindowCount(&initial_window_count) && | 263 ASSERT_TRUE(automation()->GetBrowserWindowCount(&initial_window_count) && |
| 259 initial_window_count == 1); | 264 initial_window_count == 1); |
| 260 | 265 |
| 261 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 266 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 262 | 267 |
| 263 // Create an off the record window. | 268 // Create an off the record window. |
| 264 ASSERT_TRUE(browser_proxy->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); | 269 ASSERT_TRUE(browser_proxy->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); |
| 265 int window_count; | 270 int window_count; |
| 266 automation()->GetBrowserWindowCount(&window_count); | 271 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 267 ASSERT_EQ(2, window_count); | 272 ASSERT_EQ(2, window_count); |
| 268 | 273 |
| 269 // Close the first window. | 274 // Close the first window. |
| 270 CloseWindow(0, 2); | 275 CloseWindow(0, 2); |
| 271 browser_proxy = NULL; | 276 browser_proxy = NULL; |
| 272 | 277 |
| 273 // Launch the browser again. Note, this doesn't spawn a new process, instead | 278 // Launch the browser again. Note, this doesn't spawn a new process, instead |
| 274 // it attaches to the current process. | 279 // it attaches to the current process. |
| 275 include_testing_id_ = false; | 280 include_testing_id_ = false; |
| 276 use_existing_browser_ = true; | 281 use_existing_browser_ = true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 412 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 408 tab_proxy = browser_proxy->GetTab(tab_count - 1); | 413 tab_proxy = browser_proxy->GetTab(tab_count - 1); |
| 409 ASSERT_TRUE(tab_proxy.get() != NULL); | 414 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 410 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 415 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 411 | 416 |
| 412 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); | 417 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); |
| 413 } | 418 } |
| 414 #endif | 419 #endif |
| 415 | 420 |
| 416 } // namespace | 421 } // namespace |
| OLD | NEW |