| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 FakeBackgroundModeManager() | 104 FakeBackgroundModeManager() |
| 105 : BackgroundModeManager( | 105 : BackgroundModeManager( |
| 106 CommandLine::ForCurrentProcess(), | 106 CommandLine::ForCurrentProcess(), |
| 107 &g_browser_process->profile_manager()->GetProfileInfoCache()), | 107 &g_browser_process->profile_manager()->GetProfileInfoCache()), |
| 108 background_mode_active_(false) {} | 108 background_mode_active_(false) {} |
| 109 | 109 |
| 110 void SetBackgroundModeActive(bool active) { | 110 void SetBackgroundModeActive(bool active) { |
| 111 background_mode_active_ = active; | 111 background_mode_active_ = active; |
| 112 } | 112 } |
| 113 | 113 |
| 114 virtual bool IsBackgroundModeActive() override { | 114 bool IsBackgroundModeActive() override { return background_mode_active_; } |
| 115 return background_mode_active_; | |
| 116 } | |
| 117 | 115 |
| 118 private: | 116 private: |
| 119 bool background_mode_active_; | 117 bool background_mode_active_; |
| 120 | 118 |
| 121 }; | 119 }; |
| 122 | 120 |
| 123 } // namespace | 121 } // namespace |
| 124 | 122 |
| 125 class BetterSessionRestoreTest : public InProcessBrowserTest { | 123 class BetterSessionRestoreTest : public InProcessBrowserTest { |
| 126 public: | 124 public: |
| (...skipping 27 matching lines...) Expand all Loading... |
| 154 net::URLRequestFilter::GetInstance()->AddUrlHandler( | 152 net::URLRequestFilter::GetInstance()->AddUrlHandler( |
| 155 GURL(fake_server_address_ + test_path_ + *it), | 153 GURL(fake_server_address_ + test_path_ + *it), |
| 156 &URLRequestFaker); | 154 &URLRequestFaker); |
| 157 } | 155 } |
| 158 net::URLRequestFilter::GetInstance()->AddUrlHandler( | 156 net::URLRequestFilter::GetInstance()->AddUrlHandler( |
| 159 GURL(fake_server_address_ + test_path_ + "posted.php"), | 157 GURL(fake_server_address_ + test_path_ + "posted.php"), |
| 160 &URLRequestFakerForPostRequests); | 158 &URLRequestFakerForPostRequests); |
| 161 } | 159 } |
| 162 | 160 |
| 163 protected: | 161 protected: |
| 164 virtual void SetUpOnMainThread() override { | 162 void SetUpOnMainThread() override { |
| 165 SessionServiceTestHelper helper( | 163 SessionServiceTestHelper helper( |
| 166 SessionServiceFactory::GetForProfile(browser()->profile())); | 164 SessionServiceFactory::GetForProfile(browser()->profile())); |
| 167 helper.SetForceBrowserNotAliveWithNoWindows(true); | 165 helper.SetForceBrowserNotAliveWithNoWindows(true); |
| 168 helper.ReleaseService(); | 166 helper.ReleaseService(); |
| 169 g_browser_process->set_background_mode_manager_for_test( | 167 g_browser_process->set_background_mode_manager_for_test( |
| 170 scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); | 168 scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); |
| 171 } | 169 } |
| 172 | 170 |
| 173 void StoreDataWithPage(const std::string& filename) { | 171 void StoreDataWithPage(const std::string& filename) { |
| 174 StoreDataWithPage(browser(), filename); | 172 StoreDataWithPage(browser(), filename); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 const base::string16 title_error_write_failed_; | 362 const base::string16 title_error_write_failed_; |
| 365 const base::string16 title_error_empty_; | 363 const base::string16 title_error_empty_; |
| 366 | 364 |
| 367 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); | 365 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); |
| 368 }; | 366 }; |
| 369 | 367 |
| 370 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { | 368 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { |
| 371 public: | 369 public: |
| 372 ContinueWhereILeftOffTest() { } | 370 ContinueWhereILeftOffTest() { } |
| 373 | 371 |
| 374 virtual void SetUpOnMainThread() override { | 372 void SetUpOnMainThread() override { |
| 375 BetterSessionRestoreTest::SetUpOnMainThread(); | 373 BetterSessionRestoreTest::SetUpOnMainThread(); |
| 376 SessionStartupPref::SetStartupPref( | 374 SessionStartupPref::SetStartupPref( |
| 377 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | 375 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 378 } | 376 } |
| 379 | 377 |
| 380 protected: | 378 protected: |
| 381 virtual Browser* QuitBrowserAndRestore(Browser* browser, | 379 Browser* QuitBrowserAndRestore(Browser* browser, |
| 382 bool close_all_windows) override { | 380 bool close_all_windows) override { |
| 383 content::WindowedNotificationObserver session_restore_observer( | 381 content::WindowedNotificationObserver session_restore_observer( |
| 384 chrome::NOTIFICATION_SESSION_RESTORE_DONE, | 382 chrome::NOTIFICATION_SESSION_RESTORE_DONE, |
| 385 content::NotificationService::AllSources()); | 383 content::NotificationService::AllSources()); |
| 386 Browser* new_browser = BetterSessionRestoreTest::QuitBrowserAndRestore( | 384 Browser* new_browser = BetterSessionRestoreTest::QuitBrowserAndRestore( |
| 387 browser, close_all_windows); | 385 browser, close_all_windows); |
| 388 session_restore_observer.Wait(); | 386 session_restore_observer.Wait(); |
| 389 return new_browser; | 387 return new_browser; |
| 390 } | 388 } |
| 391 | 389 |
| 392 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); | 390 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 CheckFormRestored(false, false); | 660 CheckFormRestored(false, false); |
| 663 } | 661 } |
| 664 #endif | 662 #endif |
| 665 | 663 |
| 666 // These tests ensure that the Better Session Restore features are not triggered | 664 // These tests ensure that the Better Session Restore features are not triggered |
| 667 // when they shouldn't be. | 665 // when they shouldn't be. |
| 668 class NoSessionRestoreTest : public BetterSessionRestoreTest { | 666 class NoSessionRestoreTest : public BetterSessionRestoreTest { |
| 669 public: | 667 public: |
| 670 NoSessionRestoreTest() { } | 668 NoSessionRestoreTest() { } |
| 671 | 669 |
| 672 virtual void SetUpOnMainThread() override { | 670 void SetUpOnMainThread() override { |
| 673 BetterSessionRestoreTest::SetUpOnMainThread(); | 671 BetterSessionRestoreTest::SetUpOnMainThread(); |
| 674 SessionStartupPref::SetStartupPref( | 672 SessionStartupPref::SetStartupPref( |
| 675 browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT)); | 673 browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT)); |
| 676 } | 674 } |
| 677 | 675 |
| 678 private: | 676 private: |
| 679 DISALLOW_COPY_AND_ASSIGN(NoSessionRestoreTest); | 677 DISALLOW_COPY_AND_ASSIGN(NoSessionRestoreTest); |
| 680 }; | 678 }; |
| 681 | 679 |
| 682 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionCookies) { | 680 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, PRE_SessionCookies) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 CookieSettings::Factory::GetForProfile(new_browser->profile())-> | 836 CookieSettings::Factory::GetForProfile(new_browser->profile())-> |
| 839 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); | 837 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 840 // ... even if background mode is active. | 838 // ... even if background mode is active. |
| 841 EnableBackgroundMode(); | 839 EnableBackgroundMode(); |
| 842 new_browser = QuitBrowserAndRestore(new_browser, true); | 840 new_browser = QuitBrowserAndRestore(new_browser, true); |
| 843 StoreDataWithPage(new_browser, "cookies.html"); | 841 StoreDataWithPage(new_browser, "cookies.html"); |
| 844 DisableBackgroundMode(); | 842 DisableBackgroundMode(); |
| 845 new_browser = QuitBrowserAndRestore(new_browser, true); | 843 new_browser = QuitBrowserAndRestore(new_browser, true); |
| 846 StoreDataWithPage(new_browser, "cookies.html"); | 844 StoreDataWithPage(new_browser, "cookies.html"); |
| 847 } | 845 } |
| OLD | NEW |