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