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_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 CookieSettings::Factory::GetForProfile(browser()->profile())-> | 518 CookieSettings::Factory::GetForProfile(browser()->profile())-> |
519 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); | 519 SetDefaultCookieSetting(CONTENT_SETTING_SESSION_ONLY); |
520 } | 520 } |
521 | 521 |
522 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { | 522 IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) { |
523 content::WebContents* web_contents = | 523 content::WebContents* web_contents = |
524 browser()->tab_strip_model()->GetActiveWebContents(); | 524 browser()->tab_strip_model()->GetActiveWebContents(); |
525 EXPECT_EQ(std::string(chrome::kAboutBlankURL), web_contents->GetURL().spec()); | 525 EXPECT_EQ(std::string(chrome::kAboutBlankURL), web_contents->GetURL().spec()); |
526 StoreDataWithPage("local_storage.html"); | 526 StoreDataWithPage("local_storage.html"); |
527 } | 527 } |
528 | |
529 class BetterSessionRestoreCrashTest : public BetterSessionRestoreTest { | |
530 public: | |
531 BetterSessionRestoreCrashTest() { } | |
532 | |
533 virtual void SetUpOnMainThread() OVERRIDE { | |
534 BetterSessionRestoreTest::SetUpOnMainThread(); | |
535 SessionStartupPref::SetStartupPref( | |
536 browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT)); | |
537 } | |
538 | |
539 protected: | |
540 void CrashTestWithPage(const std::string& filename) { | |
541 Profile* profile = browser()->profile(); | |
542 Browser* browser_before_restore = browser(); | |
543 ASSERT_TRUE(browser_before_restore); | |
544 StoreDataWithPage(browser_before_restore, filename); | |
545 | |
546 // Session restore data is written lazily but we cannot restore data that | |
547 // was not saved. Be less lazy for the test. | |
548 SessionServiceFactory::GetForProfile(profile)->Save(); | |
549 | |
550 // Simulate a crash and a restart. | |
551 browser_before_restore->window()->Close(); | |
552 SessionServiceFactory::GetForProfile(profile)->backend()-> | |
553 MoveCurrentSessionToLastSession(); | |
554 ProfileImpl* profile_impl = static_cast<ProfileImpl*>(profile); | |
555 profile_impl->last_session_exit_type_ = Profile::EXIT_CRASHED; | |
556 #if defined(OS_CHROMEOS) | |
557 profile_impl->chromeos_enterprise_extension_observer_.reset(NULL); | |
558 #endif | |
559 StartupBrowserCreator::ClearLaunchedProfilesForTesting(); | |
560 | |
561 CommandLine dummy(CommandLine::NO_PROGRAM); | |
562 dummy.AppendSwitchASCII(switches::kTestType, "browser"); | |
563 int return_code; | |
564 StartupBrowserCreator browser_creator; | |
565 std::vector<Profile*> last_opened_profiles(1, profile); | |
566 browser_creator.Start(dummy, | |
567 g_browser_process->profile_manager()->user_data_dir(), | |
568 profile, last_opened_profiles, &return_code); | |
569 | |
570 // The browser displays an info bar, use it to restore the session. | |
571 Browser* browser_after_restore = | |
572 FindOneOtherBrowserForProfile(profile, browser_before_restore); | |
573 ASSERT_TRUE(browser_after_restore); | |
574 content::WebContents* web_contents = | |
575 browser_after_restore->tab_strip_model()->GetActiveWebContents(); | |
576 ASSERT_TRUE(web_contents); | |
577 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); | |
578 InfoBarService* infobar_service = | |
579 InfoBarService::FromWebContents(web_contents); | |
580 EXPECT_EQ(1U, infobar_service->GetInfoBarCount()); | |
581 infobar_service->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate()-> | |
582 Accept(); | |
583 | |
584 // Session restore is done ascynhronously. | |
585 base::RunLoop loop; | |
586 loop.RunUntilIdle(); | |
587 | |
588 // Check the restored page. | |
589 web_contents = | |
590 browser_after_restore->tab_strip_model()->GetWebContentsAt(0); | |
591 ASSERT_TRUE(web_contents); | |
592 EXPECT_EQ(GURL(fake_server_address() + test_path() + filename), | |
593 web_contents->GetURL()); | |
594 CheckReloadedPageRestored(browser_after_restore); | |
595 } | |
596 | |
597 private: | |
598 DISALLOW_COPY_AND_ASSIGN(BetterSessionRestoreCrashTest); | |
599 }; | |
600 | |
601 // http://crbug.com/172770 | |
602 IN_PROC_BROWSER_TEST_F(BetterSessionRestoreCrashTest, DISABLED_SessionCookies) { | |
603 CrashTestWithPage("session_cookies.html"); | |
604 } | |
OLD | NEW |