| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/background/background_mode_manager.h" | 14 #include "chrome/browser/background/background_mode_manager.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 16 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 17 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" | 19 #include "chrome/browser/lifetime/application_lifetime.h" |
| 20 #include "chrome/browser/lifetime/browser_keep_alive.h" |
| 20 #include "chrome/browser/prefs/session_startup_pref.h" | 21 #include "chrome/browser/prefs/session_startup_pref.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_impl.h" | 23 #include "chrome/browser/profiles/profile_impl.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/sessions/session_restore_test_helper.h" | 25 #include "chrome/browser/sessions/session_restore_test_helper.h" |
| 25 #include "chrome/browser/sessions/session_service_factory.h" | 26 #include "chrome/browser/sessions/session_service_factory.h" |
| 26 #include "chrome/browser/sessions/session_service_test_helper.h" | 27 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/browser/ui/browser_commands.h" | 29 #include "chrome/browser/ui/browser_commands.h" |
| 29 #include "chrome/browser/ui/browser_iterator.h" | 30 #include "chrome/browser/ui/browser_iterator.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 background_mode_active_(false) {} | 141 background_mode_active_(false) {} |
| 141 | 142 |
| 142 void SetBackgroundModeActive(bool active) { | 143 void SetBackgroundModeActive(bool active) { |
| 143 background_mode_active_ = active; | 144 background_mode_active_ = active; |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool IsBackgroundModeActive() override { return background_mode_active_; } | 147 bool IsBackgroundModeActive() override { return background_mode_active_; } |
| 147 | 148 |
| 148 private: | 149 private: |
| 149 bool background_mode_active_; | 150 bool background_mode_active_; |
| 150 | |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 class BetterSessionRestoreTest : public InProcessBrowserTest { | 155 class BetterSessionRestoreTest : public InProcessBrowserTest { |
| 156 public: | 156 public: |
| 157 BetterSessionRestoreTest() | 157 BetterSessionRestoreTest() |
| 158 : fake_server_address_("http://www.test.com/"), | 158 : fake_server_address_("http://www.test.com/"), |
| 159 test_path_("session_restore/"), | 159 test_path_("session_restore/"), |
| 160 title_pass_(base::ASCIIToUTF16("PASS")), | 160 title_pass_(base::ASCIIToUTF16("PASS")), |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 post_interceptor_->DidLastUploadContain("posted-password")); | 307 post_interceptor_->DidLastUploadContain("posted-password")); |
| 308 EXPECT_EQ(password_present, | 308 EXPECT_EQ(password_present, |
| 309 post_interceptor_->DidLastUploadContain("password-entered")); | 309 post_interceptor_->DidLastUploadContain("password-entered")); |
| 310 } | 310 } |
| 311 | 311 |
| 312 virtual Browser* QuitBrowserAndRestore(Browser* browser, | 312 virtual Browser* QuitBrowserAndRestore(Browser* browser, |
| 313 bool close_all_windows) { | 313 bool close_all_windows) { |
| 314 Profile* profile = browser->profile(); | 314 Profile* profile = browser->profile(); |
| 315 | 315 |
| 316 // Close the browser. | 316 // Close the browser. |
| 317 chrome::IncrementKeepAliveCount(); | 317 browser_lifetime::ScopedKeepAlive keep_alive; |
| 318 if (close_all_windows) | 318 if (close_all_windows) |
| 319 CloseAllBrowsers(); | 319 CloseAllBrowsers(); |
| 320 else | 320 else |
| 321 CloseBrowserSynchronously(browser); | 321 CloseBrowserSynchronously(browser); |
| 322 | 322 |
| 323 SessionServiceTestHelper helper; | 323 SessionServiceTestHelper helper; |
| 324 helper.SetService( | 324 helper.SetService( |
| 325 SessionServiceFactory::GetForProfileForSessionRestore(profile)); | 325 SessionServiceFactory::GetForProfileForSessionRestore(profile)); |
| 326 helper.SetForceBrowserNotAliveWithNoWindows(true); | 326 helper.SetForceBrowserNotAliveWithNoWindows(true); |
| 327 helper.ReleaseService(); | 327 helper.ReleaseService(); |
| 328 | 328 |
| 329 // Create a new window, which should trigger session restore. | 329 // Create a new window, which should trigger session restore. |
| 330 ui_test_utils::BrowserAddedObserver window_observer; | 330 ui_test_utils::BrowserAddedObserver window_observer; |
| 331 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 331 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 332 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 332 return window_observer.WaitForSingleNewBrowser(); |
| 333 chrome::DecrementKeepAliveCount(); | |
| 334 | |
| 335 return new_browser; | |
| 336 } | 333 } |
| 337 | 334 |
| 338 std::string fake_server_address() { | 335 std::string fake_server_address() { |
| 339 return fake_server_address_; | 336 return fake_server_address_; |
| 340 } | 337 } |
| 341 | 338 |
| 342 std::string test_path() { | 339 std::string test_path() { |
| 343 return test_path_; | 340 return test_path_; |
| 344 } | 341 } |
| 345 | 342 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 protected: | 380 protected: |
| 384 Browser* QuitBrowserAndRestore(Browser* browser, | 381 Browser* QuitBrowserAndRestore(Browser* browser, |
| 385 bool close_all_windows) override { | 382 bool close_all_windows) override { |
| 386 SessionRestoreTestHelper session_restore_observer; | 383 SessionRestoreTestHelper session_restore_observer; |
| 387 Browser* new_browser = BetterSessionRestoreTest::QuitBrowserAndRestore( | 384 Browser* new_browser = BetterSessionRestoreTest::QuitBrowserAndRestore( |
| 388 browser, close_all_windows); | 385 browser, close_all_windows); |
| 389 session_restore_observer.Wait(); | 386 session_restore_observer.Wait(); |
| 390 return new_browser; | 387 return new_browser; |
| 391 } | 388 } |
| 392 | 389 |
| 390 private: |
| 393 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); | 391 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); |
| 394 }; | 392 }; |
| 395 | 393 |
| 396 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { | 394 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { |
| 397 // Set the startup preference to "continue where I left off" and visit a page | 395 // Set the startup preference to "continue where I left off" and visit a page |
| 398 // which stores a session cookie. | 396 // which stores a session cookie. |
| 399 StoreDataWithPage("session_cookies.html"); | 397 StoreDataWithPage("session_cookies.html"); |
| 400 } | 398 } |
| 401 | 399 |
| 402 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { | 400 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 CookieSettingsFactory::GetForProfile(new_browser->profile()) | 838 CookieSettingsFactory::GetForProfile(new_browser->profile()) |
| 841 ->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); | 839 ->SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 842 // ... even if background mode is active. | 840 // ... even if background mode is active. |
| 843 EnableBackgroundMode(); | 841 EnableBackgroundMode(); |
| 844 new_browser = QuitBrowserAndRestore(new_browser, true); | 842 new_browser = QuitBrowserAndRestore(new_browser, true); |
| 845 StoreDataWithPage(new_browser, "cookies.html"); | 843 StoreDataWithPage(new_browser, "cookies.html"); |
| 846 DisableBackgroundMode(); | 844 DisableBackgroundMode(); |
| 847 new_browser = QuitBrowserAndRestore(new_browser, true); | 845 new_browser = QuitBrowserAndRestore(new_browser, true); |
| 848 StoreDataWithPage(new_browser, "cookies.html"); | 846 StoreDataWithPage(new_browser, "cookies.html"); |
| 849 } | 847 } |
| OLD | NEW |