| 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/background/background_mode_manager.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/content_settings/cookie_settings.h" | 15 #include "chrome/browser/content_settings/cookie_settings.h" |
| 16 #include "chrome/browser/defaults.h" |
| 14 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 17 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" |
| 16 #include "chrome/browser/prefs/session_startup_pref.h" | 20 #include "chrome/browser/prefs/session_startup_pref.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_impl.h" | 22 #include "chrome/browser/profiles/profile_impl.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/sessions/session_backend.h" | 24 #include "chrome/browser/sessions/session_backend.h" |
| 21 #include "chrome/browser/sessions/session_service_factory.h" | 25 #include "chrome/browser/sessions/session_service_factory.h" |
| 26 #include "chrome/browser/sessions/session_service_test_helper.h" |
| 22 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 28 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_iterator.h" | 29 #include "chrome/browser/ui/browser_iterator.h" |
| 25 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| 26 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 31 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/content_settings.h" | 34 #include "chrome/common/content_settings.h" |
| 30 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/test/base/in_process_browser_test.h" | 37 #include "chrome/test/base/in_process_browser_test.h" |
| 33 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
| 34 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/common/url_constants.h" | 40 #include "content/public/common/url_constants.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 41 #include "content/public/test/browser_test_utils.h" |
| 37 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
| 38 #include "net/base/upload_bytes_element_reader.h" | 43 #include "net/base/upload_bytes_element_reader.h" |
| 39 #include "net/base/upload_data_stream.h" | 44 #include "net/base/upload_data_stream.h" |
| 40 #include "net/url_request/url_request.h" | 45 #include "net/url_request/url_request.h" |
| 41 #include "net/url_request/url_request_filter.h" | 46 #include "net/url_request/url_request_filter.h" |
| 42 #include "net/url_request/url_request_test_job.h" | 47 #include "net/url_request/url_request_test_job.h" |
| 43 | 48 |
| 49 #if defined(OS_MACOSX) |
| 50 #include "base/mac/scoped_nsautorelease_pool.h" |
| 51 #endif |
| 52 |
| 44 namespace { | 53 namespace { |
| 45 | 54 |
| 46 Browser* FindOneOtherBrowserForProfile(Profile* profile, | 55 Browser* FindOneOtherBrowserForProfile(Profile* profile, |
| 47 Browser* not_this_browser) { | 56 Browser* not_this_browser) { |
| 48 for (chrome::BrowserIterator it; !it.done(); it.Next()) { | 57 for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| 49 if (*it != not_this_browser && it->profile() == profile) | 58 if (*it != not_this_browser && it->profile() == profile) |
| 50 return *it; | 59 return *it; |
| 51 } | 60 } |
| 52 return NULL; | 61 return NULL; |
| 53 } | 62 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 std::string(bytes_reader->bytes(), bytes_reader->length()); | 99 std::string(bytes_reader->bytes(), bytes_reader->length()); |
| 91 } | 100 } |
| 92 } | 101 } |
| 93 } | 102 } |
| 94 return new net::URLRequestTestJob( | 103 return new net::URLRequestTestJob( |
| 95 request, network_delegate, net::URLRequestTestJob::test_headers(), | 104 request, network_delegate, net::URLRequestTestJob::test_headers(), |
| 96 "<html><head><title>PASS</title></head><body>Data posted</body></html>", | 105 "<html><head><title>PASS</title></head><body>Data posted</body></html>", |
| 97 true); | 106 true); |
| 98 } | 107 } |
| 99 | 108 |
| 109 class FakeBackgroundModeManager : public BackgroundModeManager { |
| 110 public: |
| 111 FakeBackgroundModeManager() |
| 112 : BackgroundModeManager( |
| 113 CommandLine::ForCurrentProcess(), |
| 114 &g_browser_process->profile_manager()->GetProfileInfoCache()), |
| 115 background_mode_active_(false) {} |
| 116 |
| 117 void SetBackgroundModeActive(bool active) { |
| 118 background_mode_active_ = active; |
| 119 } |
| 120 |
| 121 virtual bool IsBackgroundModeActive() OVERRIDE { |
| 122 return background_mode_active_; |
| 123 } |
| 124 |
| 125 private: |
| 126 bool background_mode_active_; |
| 127 |
| 128 }; |
| 129 |
| 100 } // namespace | 130 } // namespace |
| 101 | 131 |
| 102 class BetterSessionRestoreTest : public InProcessBrowserTest { | 132 class BetterSessionRestoreTest : public InProcessBrowserTest { |
| 103 public: | 133 public: |
| 104 BetterSessionRestoreTest() | 134 BetterSessionRestoreTest() |
| 105 : fake_server_address_("http://www.test.com/"), | 135 : fake_server_address_("http://www.test.com/"), |
| 106 test_path_("session_restore/"), | 136 test_path_("session_restore/"), |
| 107 title_pass_(ASCIIToUTF16("PASS")), | 137 title_pass_(ASCIIToUTF16("PASS")), |
| 108 title_storing_(ASCIIToUTF16("STORING")), | 138 title_storing_(ASCIIToUTF16("STORING")), |
| 109 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), | 139 title_error_write_failed_(ASCIIToUTF16("ERROR_WRITE_FAILED")), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 131 net::URLRequestFilter::GetInstance()->AddUrlHandler( | 161 net::URLRequestFilter::GetInstance()->AddUrlHandler( |
| 132 GURL(fake_server_address_ + test_path_ + *it), | 162 GURL(fake_server_address_ + test_path_ + *it), |
| 133 &URLRequestFaker); | 163 &URLRequestFaker); |
| 134 } | 164 } |
| 135 net::URLRequestFilter::GetInstance()->AddUrlHandler( | 165 net::URLRequestFilter::GetInstance()->AddUrlHandler( |
| 136 GURL(fake_server_address_ + test_path_ + "posted.php"), | 166 GURL(fake_server_address_ + test_path_ + "posted.php"), |
| 137 &URLRequestFakerForPostRequests); | 167 &URLRequestFakerForPostRequests); |
| 138 } | 168 } |
| 139 | 169 |
| 140 protected: | 170 protected: |
| 171 virtual void SetUpOnMainThread() OVERRIDE { |
| 172 SessionServiceTestHelper helper( |
| 173 SessionServiceFactory::GetForProfile(browser()->profile())); |
| 174 helper.SetForceBrowserNotAliveWithNoWindows(true); |
| 175 helper.ReleaseService(); |
| 176 g_browser_process->set_background_mode_manager_for_test( |
| 177 scoped_ptr<BackgroundModeManager>(new FakeBackgroundModeManager)); |
| 178 } |
| 179 |
| 141 void StoreDataWithPage(const std::string& filename) { | 180 void StoreDataWithPage(const std::string& filename) { |
| 142 StoreDataWithPage(browser(), filename); | 181 StoreDataWithPage(browser(), filename); |
| 143 } | 182 } |
| 144 | 183 |
| 145 void StoreDataWithPage(Browser* browser, const std::string& filename) { | 184 void StoreDataWithPage(Browser* browser, const std::string& filename) { |
| 146 content::WebContents* web_contents = | 185 content::WebContents* web_contents = |
| 147 browser->tab_strip_model()->GetActiveWebContents(); | 186 browser->tab_strip_model()->GetActiveWebContents(); |
| 148 content::TitleWatcher title_watcher(web_contents, title_storing_); | 187 content::TitleWatcher title_watcher(web_contents, title_storing_); |
| 149 title_watcher.AlsoWaitForTitle(title_pass_); | 188 title_watcher.AlsoWaitForTitle(title_pass_); |
| 150 title_watcher.AlsoWaitForTitle(title_error_write_failed_); | 189 title_watcher.AlsoWaitForTitle(title_error_write_failed_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 177 | 216 |
| 178 void CheckReloadedPageRestored() { | 217 void CheckReloadedPageRestored() { |
| 179 CheckTitle(browser(), title_pass_); | 218 CheckTitle(browser(), title_pass_); |
| 180 } | 219 } |
| 181 | 220 |
| 182 void CheckReloadedPageRestored(Browser* browser) { | 221 void CheckReloadedPageRestored(Browser* browser) { |
| 183 CheckTitle(browser, title_pass_); | 222 CheckTitle(browser, title_pass_); |
| 184 } | 223 } |
| 185 | 224 |
| 186 void CheckReloadedPageNotRestored() { | 225 void CheckReloadedPageNotRestored() { |
| 187 CheckTitle(browser(), title_storing_); | 226 CheckReloadedPageNotRestored(browser()); |
| 227 } |
| 228 |
| 229 void CheckReloadedPageNotRestored(Browser* browser) { |
| 230 CheckTitle(browser, title_storing_); |
| 188 } | 231 } |
| 189 | 232 |
| 190 void CheckTitle(Browser* browser, const string16& expected_title) { | 233 void CheckTitle(Browser* browser, const string16& expected_title) { |
| 191 content::WebContents* web_contents = | 234 content::WebContents* web_contents = |
| 192 browser->tab_strip_model()->GetWebContentsAt(0); | 235 browser->tab_strip_model()->GetWebContentsAt(0); |
| 193 content::TitleWatcher title_watcher(web_contents, expected_title); | 236 content::TitleWatcher title_watcher(web_contents, expected_title); |
| 194 title_watcher.AlsoWaitForTitle(title_pass_); | 237 title_watcher.AlsoWaitForTitle(title_pass_); |
| 195 title_watcher.AlsoWaitForTitle(title_storing_); | 238 title_watcher.AlsoWaitForTitle(title_storing_); |
| 196 title_watcher.AlsoWaitForTitle(title_error_write_failed_); | 239 title_watcher.AlsoWaitForTitle(title_error_write_failed_); |
| 197 title_watcher.AlsoWaitForTitle(title_error_empty_); | 240 title_watcher.AlsoWaitForTitle(title_error_empty_); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 223 std::string::npos); | 266 std::string::npos); |
| 224 if (password_present) { | 267 if (password_present) { |
| 225 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != | 268 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != |
| 226 std::string::npos); | 269 std::string::npos); |
| 227 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != | 270 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != |
| 228 std::string::npos); | 271 std::string::npos); |
| 229 } | 272 } |
| 230 } | 273 } |
| 231 | 274 |
| 232 void CheckFormRestored(bool text_present, bool password_present) { | 275 void CheckFormRestored(bool text_present, bool password_present) { |
| 233 CheckReloadedPageRestored(); | 276 CheckFormRestored(browser(), text_present, password_present); |
| 277 } |
| 278 |
| 279 void CheckFormRestored( |
| 280 Browser* browser, bool text_present, bool password_present) { |
| 281 CheckReloadedPageRestored(browser); |
| 234 if (text_present) { | 282 if (text_present) { |
| 235 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != | 283 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") != |
| 236 std::string::npos); | 284 std::string::npos); |
| 237 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != | 285 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") != |
| 238 std::string::npos); | 286 std::string::npos); |
| 239 } else { | 287 } else { |
| 240 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") == | 288 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-text") == |
| 241 std::string::npos); | 289 std::string::npos); |
| 242 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") == | 290 EXPECT_TRUE(g_last_upload_bytes.Get().find("text-entered") == |
| 243 std::string::npos); | 291 std::string::npos); |
| 244 } | 292 } |
| 245 if (password_present) { | 293 if (password_present) { |
| 246 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != | 294 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") != |
| 247 std::string::npos); | 295 std::string::npos); |
| 248 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != | 296 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") != |
| 249 std::string::npos); | 297 std::string::npos); |
| 250 } else { | 298 } else { |
| 251 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") == | 299 EXPECT_TRUE(g_last_upload_bytes.Get().find("posted-password") == |
| 252 std::string::npos); | 300 std::string::npos); |
| 253 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") == | 301 EXPECT_TRUE(g_last_upload_bytes.Get().find("password-entered") == |
| 254 std::string::npos); | 302 std::string::npos); |
| 255 } | 303 } |
| 256 } | 304 } |
| 257 | 305 |
| 306 void CloseBrowserSynchronously(Browser* browser) { |
| 307 content::WindowedNotificationObserver observer( |
| 308 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 309 content::NotificationService::AllSources()); |
| 310 browser->window()->Close(); |
| 311 #if defined(OS_MACOSX) |
| 312 // BrowserWindowController depends on the auto release pool being recycled |
| 313 // in the message loop to delete itself, which frees the Browser object |
| 314 // which fires this event. |
| 315 AutoreleasePool()->Recycle(); |
| 316 #endif |
| 317 observer.Wait(); |
| 318 } |
| 319 |
| 320 virtual Browser* QuitBrowserAndRestore(Browser* browser) { |
| 321 Profile* profile = browser->profile(); |
| 322 |
| 323 // Close the browser. |
| 324 chrome::StartKeepAlive(); |
| 325 CloseBrowserSynchronously(browser); |
| 326 |
| 327 // Create a new window, which should trigger session restore. |
| 328 ui_test_utils::BrowserAddedObserver window_observer; |
| 329 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 330 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
| 331 chrome::EndKeepAlive(); |
| 332 |
| 333 return new_browser; |
| 334 } |
| 335 |
| 258 std::string fake_server_address() { | 336 std::string fake_server_address() { |
| 259 return fake_server_address_; | 337 return fake_server_address_; |
| 260 } | 338 } |
| 261 | 339 |
| 262 std::string test_path() { | 340 std::string test_path() { |
| 263 return test_path_; | 341 return test_path_; |
| 264 } | 342 } |
| 265 | 343 |
| 344 void EnableBackgroundMode() { |
| 345 static_cast<FakeBackgroundModeManager*>( |
| 346 g_browser_process->background_mode_manager())-> |
| 347 SetBackgroundModeActive(true); |
| 348 } |
| 349 |
| 350 void DisableBackgroundMode() { |
| 351 static_cast<FakeBackgroundModeManager*>( |
| 352 g_browser_process->background_mode_manager())-> |
| 353 SetBackgroundModeActive(false); |
| 354 } |
| 355 |
| 266 private: | 356 private: |
| 267 const std::string fake_server_address_; | 357 const std::string fake_server_address_; |
| 268 const std::string test_path_; | 358 const std::string test_path_; |
| 269 const string16 title_pass_; | 359 const string16 title_pass_; |
| 270 const string16 title_storing_; | 360 const string16 title_storing_; |
| 271 const string16 title_error_write_failed_; | 361 const string16 title_error_write_failed_; |
| 272 const string16 title_error_empty_; | 362 const string16 title_error_empty_; |
| 273 | 363 |
| 274 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); | 364 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreTest); |
| 275 }; | 365 }; |
| 276 | 366 |
| 277 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { | 367 class ContinueWhereILeftOffTest : public BetterSessionRestoreTest { |
| 278 public: | 368 public: |
| 279 ContinueWhereILeftOffTest() { } | 369 ContinueWhereILeftOffTest() { } |
| 280 | 370 |
| 281 virtual void SetUpOnMainThread() OVERRIDE { | 371 virtual void SetUpOnMainThread() OVERRIDE { |
| 282 BetterSessionRestoreTest::SetUpOnMainThread(); | 372 BetterSessionRestoreTest::SetUpOnMainThread(); |
| 283 SessionStartupPref::SetStartupPref( | 373 SessionStartupPref::SetStartupPref( |
| 284 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); | 374 browser()->profile(), SessionStartupPref(SessionStartupPref::LAST)); |
| 285 } | 375 } |
| 286 | 376 |
| 377 protected: |
| 378 virtual Browser* QuitBrowserAndRestore(Browser* browser) OVERRIDE { |
| 379 content::WindowedNotificationObserver session_restore_observer( |
| 380 chrome::NOTIFICATION_SESSION_RESTORE_DONE, |
| 381 content::NotificationService::AllSources()); |
| 382 Browser* new_browser = |
| 383 BetterSessionRestoreTest::QuitBrowserAndRestore(browser); |
| 384 session_restore_observer.Wait(); |
| 385 return new_browser; |
| 386 } |
| 387 |
| 287 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); | 388 DISALLOW_COPY_AND_ASSIGN(ContinueWhereILeftOffTest); |
| 288 }; | 389 }; |
| 289 | 390 |
| 290 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { | 391 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_SessionCookies) { |
| 291 // Set the startup preference to "continue where I left off" and visit a page | 392 // Set the startup preference to "continue where I left off" and visit a page |
| 292 // which stores a session cookie. | 393 // which stores a session cookie. |
| 293 StoreDataWithPage("session_cookies.html"); | 394 StoreDataWithPage("session_cookies.html"); |
| 294 } | 395 } |
| 295 | 396 |
| 296 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { | 397 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookies) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_PostWithPassword) { | 454 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PRE_PostWithPassword) { |
| 354 PostFormWithPage("post_with_password.html", true); | 455 PostFormWithPage("post_with_password.html", true); |
| 355 } | 456 } |
| 356 | 457 |
| 357 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostWithPassword) { | 458 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostWithPassword) { |
| 358 CheckReloadedPageRestored(); | 459 CheckReloadedPageRestored(); |
| 359 // The form data contained passwords, so it's removed completely. | 460 // The form data contained passwords, so it's removed completely. |
| 360 CheckFormRestored(false, false); | 461 CheckFormRestored(false, false); |
| 361 } | 462 } |
| 362 | 463 |
| 464 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, SessionCookiesBrowserClose) { |
| 465 // Set the startup preference to "continue where I left off" and visit a page |
| 466 // which stores a session cookie. |
| 467 StoreDataWithPage("session_cookies.html"); |
| 468 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 469 // The browsing session will be continued; just wait for the page to reload |
| 470 // and check the stored data. |
| 471 CheckReloadedPageRestored(new_browser); |
| 472 } |
| 473 |
| 474 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, |
| 475 CookiesClearedOnBrowserClose) { |
| 476 StoreDataWithPage("cookies.html"); |
| 477 // Normally cookies are restored. |
| 478 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 479 CheckReloadedPageRestored(new_browser); |
| 480 // ... but not if the content setting is set to clear on exit. |
| 481 CookieSettings::Factory::GetForProfile(new_browser->profile())-> |
| 482 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 483 // ... unless background mode is active. |
| 484 EnableBackgroundMode(); |
| 485 new_browser = QuitBrowserAndRestore(new_browser); |
| 486 CheckReloadedPageRestored(new_browser); |
| 487 |
| 488 DisableBackgroundMode(); |
| 489 new_browser = QuitBrowserAndRestore(new_browser); |
| 490 if (browser_defaults::kBrowserAliveWithNoWindows) |
| 491 CheckReloadedPageRestored(new_browser); |
| 492 else |
| 493 CheckReloadedPageNotRestored(new_browser); |
| 494 } |
| 495 |
| 496 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, PostBrowserClose) { |
| 497 PostFormWithPage("post.html", false); |
| 498 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 499 CheckFormRestored(new_browser, true, false); |
| 500 } |
| 501 |
| 502 IN_PROC_BROWSER_TEST_F(ContinueWhereILeftOffTest, |
| 503 PostWithPasswordBrowserClose) { |
| 504 PostFormWithPage("post_with_password.html", true); |
| 505 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 506 CheckReloadedPageRestored(new_browser); |
| 507 // The form data contained passwords, so it's removed completely. |
| 508 CheckFormRestored(new_browser, false, false); |
| 509 } |
| 510 |
| 363 class RestartTest : public BetterSessionRestoreTest { | 511 class RestartTest : public BetterSessionRestoreTest { |
| 364 public: | 512 public: |
| 365 RestartTest() { } | 513 RestartTest() { } |
| 366 virtual ~RestartTest() { } | 514 virtual ~RestartTest() { } |
| 367 protected: | 515 protected: |
| 368 void Restart() { | 516 void Restart() { |
| 369 // Simluate restarting the browser, but let the test exit peacefully. | 517 // Simluate restarting the browser, but let the test exit peacefully. |
| 370 for (chrome::BrowserIterator it; !it.done(); it.Next()) | 518 for (chrome::BrowserIterator it; !it.done(); it.Next()) |
| 371 content::BrowserContext::SaveSessionState(it->profile()); | 519 content::BrowserContext::SaveSessionState(it->profile()); |
| 372 PrefService* pref_service = g_browser_process->local_state(); | 520 PrefService* pref_service = g_browser_process->local_state(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); | 671 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 524 } | 672 } |
| 525 | 673 |
| 526 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { | 674 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { |
| 527 content::WebContents* web_contents = | 675 content::WebContents* web_contents = |
| 528 browser()->tab_strip_model()->GetActiveWebContents(); | 676 browser()->tab_strip_model()->GetActiveWebContents(); |
| 529 EXPECT_EQ(std::string(content::kAboutBlankURL), | 677 EXPECT_EQ(std::string(content::kAboutBlankURL), |
| 530 web_contents->GetURL().spec()); | 678 web_contents->GetURL().spec()); |
| 531 StoreDataWithPage("local_storage.html"); | 679 StoreDataWithPage("local_storage.html"); |
| 532 } | 680 } |
| 681 |
| 682 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, SessionCookiesBrowserClose) { |
| 683 StoreDataWithPage("session_cookies.html"); |
| 684 EnableBackgroundMode(); |
| 685 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 686 NavigateAndCheckStoredData(new_browser, "session_cookies.html"); |
| 687 DisableBackgroundMode(); |
| 688 new_browser = QuitBrowserAndRestore(new_browser); |
| 689 if (browser_defaults::kBrowserAliveWithNoWindows) |
| 690 NavigateAndCheckStoredData(new_browser, "session_cookies.html"); |
| 691 else |
| 692 StoreDataWithPage(new_browser, "session_cookies.html"); |
| 693 } |
| 694 |
| 695 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnBrowserClose) { |
| 696 StoreDataWithPage("cookies.html"); |
| 697 |
| 698 // Normally cookies are restored. |
| 699 Browser* new_browser = QuitBrowserAndRestore(browser()); |
| 700 NavigateAndCheckStoredData(new_browser, "cookies.html"); |
| 701 |
| 702 // ... but not if the content setting is set to clear on exit. |
| 703 CookieSettings::Factory::GetForProfile(new_browser->profile())-> |
| 704 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
| 705 // ... unless background mode is active. |
| 706 EnableBackgroundMode(); |
| 707 new_browser = QuitBrowserAndRestore(new_browser); |
| 708 NavigateAndCheckStoredData(new_browser, "cookies.html"); |
| 709 DisableBackgroundMode(); |
| 710 new_browser = QuitBrowserAndRestore(new_browser); |
| 711 if (browser_defaults::kBrowserAliveWithNoWindows) |
| 712 NavigateAndCheckStoredData(new_browser, "cookies.html"); |
| 713 else |
| 714 StoreDataWithPage(new_browser, "cookies.html"); |
| 715 } |
| OLD | NEW |