| 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/browser/defaults.h" |
| 10 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/test/automation/tab_proxy.h" | 13 #include "chrome/test/automation/tab_proxy.h" |
| 13 #include "chrome/test/automation/browser_proxy.h" | 14 #include "chrome/test/automation/browser_proxy.h" |
| 14 #include "chrome/test/automation/window_proxy.h" | 15 #include "chrome/test/automation/window_proxy.h" |
| 15 #include "chrome/test/ui/ui_test.h" | 16 #include "chrome/test/ui/ui_test.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 18 #include "net/url_request/url_request_unittest.h" | 19 #include "net/url_request/url_request_unittest.h" |
| 19 | 20 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 247 |
| 247 QuitBrowserAndRestore(1); | 248 QuitBrowserAndRestore(1); |
| 248 browser_proxy = NULL; | 249 browser_proxy = NULL; |
| 249 tab_proxy = NULL; | 250 tab_proxy = NULL; |
| 250 | 251 |
| 251 AssertOneWindowWithOneTab(); | 252 AssertOneWindowWithOneTab(); |
| 252 | 253 |
| 253 ASSERT_TRUE(GetActiveTabURL() == url1_); | 254 ASSERT_TRUE(GetActiveTabURL() == url1_); |
| 254 } | 255 } |
| 255 | 256 |
| 257 // Creates a tabbed browser and popup and makes sure we restore both. |
| 258 TEST_F(SessionRestoreUITest, NormalAndPopup) { |
| 259 if (!browser_defaults::kRestorePopups) |
| 260 return; // Test only applicable if restoring popups. |
| 261 |
| 262 NavigateToURL(url1_); |
| 263 |
| 264 // Make sure we have one window. |
| 265 int window_count; |
| 266 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 267 ASSERT_EQ(1, window_count); |
| 268 |
| 269 // Open a popup. |
| 270 ASSERT_TRUE(automation()->OpenNewBrowserWindow(BrowserProxy::TYPE_POPUP, |
| 271 true)); |
| 272 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 273 ASSERT_EQ(2, window_count); |
| 274 |
| 275 // Restart and make sure we have only one window with one tab and the url |
| 276 // is url1_. |
| 277 QuitBrowserAndRestore(1); |
| 278 |
| 279 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 280 ASSERT_EQ(2, window_count); |
| 281 |
| 282 scoped_refptr<BrowserProxy> browser_proxy1( |
| 283 automation()->GetBrowserWindow(0)); |
| 284 ASSERT_TRUE(browser_proxy1.get()); |
| 285 |
| 286 scoped_refptr<BrowserProxy> browser_proxy2( |
| 287 automation()->GetBrowserWindow(1)); |
| 288 ASSERT_TRUE(browser_proxy2.get()); |
| 289 |
| 290 BrowserProxy::Type type1, type2; |
| 291 ASSERT_TRUE(browser_proxy1->GetType(&type1)); |
| 292 ASSERT_TRUE(browser_proxy2->GetType(&type2)); |
| 293 |
| 294 // The order of whether the normal window or popup is first depends upon |
| 295 // activation order, which is not necessarily consistant across runs. |
| 296 if (type1 == BrowserProxy::TYPE_NORMAL) { |
| 297 EXPECT_EQ(type2, BrowserProxy::TYPE_POPUP); |
| 298 } else { |
| 299 EXPECT_EQ(type1, BrowserProxy::TYPE_POPUP); |
| 300 EXPECT_EQ(type2, BrowserProxy::TYPE_NORMAL); |
| 301 } |
| 302 } |
| 303 |
| 304 |
| 256 #if defined(OS_WIN) | 305 #if defined(OS_WIN) |
| 257 // Creates a browser, goes incognito, closes browser, launches and make sure | 306 // Creates a browser, goes incognito, closes browser, launches and make sure |
| 258 // we don't restore. | 307 // we don't restore. |
| 259 TEST_F(SessionRestoreUITest, DontRestoreWhileIncognito) { | 308 TEST_F(SessionRestoreUITest, DontRestoreWhileIncognito) { |
| 260 NavigateToURL(url1_); | 309 NavigateToURL(url1_); |
| 261 | 310 |
| 262 // Make sure we have one window. | 311 // Make sure we have one window. |
| 263 int initial_window_count; | 312 int initial_window_count; |
| 264 ASSERT_TRUE(automation()->GetBrowserWindowCount(&initial_window_count)); | 313 ASSERT_TRUE(automation()->GetBrowserWindowCount(&initial_window_count)); |
| 265 ASSERT_EQ(1, initial_window_count); | 314 ASSERT_EQ(1, initial_window_count); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // Creates two windows, closes one, restores, make sure only one window open. | 350 // Creates two windows, closes one, restores, make sure only one window open. |
| 302 TEST_F(SessionRestoreUITest, TwoWindowsCloseOneRestoreOnlyOne) { | 351 TEST_F(SessionRestoreUITest, TwoWindowsCloseOneRestoreOnlyOne) { |
| 303 NavigateToURL(url1_); | 352 NavigateToURL(url1_); |
| 304 | 353 |
| 305 // Make sure we have one window. | 354 // Make sure we have one window. |
| 306 int window_count; | 355 int window_count; |
| 307 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 356 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 308 ASSERT_EQ(1, window_count); | 357 ASSERT_EQ(1, window_count); |
| 309 | 358 |
| 310 // Open a second window. | 359 // Open a second window. |
| 311 ASSERT_TRUE(automation()->OpenNewBrowserWindow(true)); | 360 ASSERT_TRUE(automation()->OpenNewBrowserWindow(BrowserProxy::TYPE_NORMAL, |
| 361 true)); |
| 312 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | 362 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 313 ASSERT_EQ(2, window_count); | 363 ASSERT_EQ(2, window_count); |
| 314 | 364 |
| 315 // Close it. | 365 // Close it. |
| 316 CloseWindow(1, 2); | 366 CloseWindow(1, 2); |
| 317 | 367 |
| 318 // Restart and make sure we have only one window with one tab and the url | 368 // Restart and make sure we have only one window with one tab and the url |
| 319 // is url1_. | 369 // is url1_. |
| 320 QuitBrowserAndRestore(1); | 370 QuitBrowserAndRestore(1); |
| 321 | 371 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 463 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 414 tab_proxy = browser_proxy->GetTab(tab_count - 1); | 464 tab_proxy = browser_proxy->GetTab(tab_count - 1); |
| 415 ASSERT_TRUE(tab_proxy.get() != NULL); | 465 ASSERT_TRUE(tab_proxy.get() != NULL); |
| 416 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); | 466 ASSERT_TRUE(tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); |
| 417 | 467 |
| 418 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); | 468 ASSERT_EQ(expected_process_count, GetBrowserProcessCount()); |
| 419 } | 469 } |
| 420 #endif | 470 #endif |
| 421 | 471 |
| 422 } // namespace | 472 } // namespace |
| OLD | NEW |