Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: chrome/browser/sessions/better_session_restore_browsertest.cc

Issue 11597010: Automate more Better Session Restore tests: Crashes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sessions/better_session_restore_browsertest.cc
diff --git a/chrome/browser/sessions/better_session_restore_browsertest.cc b/chrome/browser/sessions/better_session_restore_browsertest.cc
index 64387deda51a480889d64167e5e97c9094cbaaec..682f2027afe60db892ccaacd601b7ec5ea7901bb 100644
--- a/chrome/browser/sessions/better_session_restore_browsertest.cc
+++ b/chrome/browser/sessions/better_session_restore_browsertest.cc
@@ -8,17 +8,27 @@
#include "base/lazy_instance.h"
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings.h"
+#include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_impl.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/sessions/session_backend.h"
+#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
@@ -33,6 +43,16 @@
namespace {
+Browser* FindOneOtherBrowserForProfile(Profile* profile,
+ Browser* not_this_browser) {
+ for (BrowserList::const_iterator i = BrowserList::begin();
+ i != BrowserList::end(); ++i) {
+ if (*i != not_this_browser && (*i)->profile() == profile)
+ return *i;
+ }
+ return NULL;
+}
+
// We need to serve the test files so that PRE_Test and Test can access the same
// page using the same URL. In addition, perceived security origin of the page
// needs to stay the same, so e.g., redirecting the URL requests doesn't
@@ -120,43 +140,56 @@ class BetterSessionRestoreTest : public InProcessBrowserTest {
protected:
void StoreDataWithPage(const std::string& filename) {
+ StoreDataWithPage(browser(), filename);
+ }
+
+ void StoreDataWithPage(Browser* browser, const std::string& filename) {
content::WebContents* web_contents =
- chrome::GetActiveWebContents(browser());
+ chrome::GetActiveWebContents(browser);
content::TitleWatcher title_watcher(web_contents, title_storing_);
title_watcher.AlsoWaitForTitle(title_pass_);
title_watcher.AlsoWaitForTitle(title_error_write_failed_);
title_watcher.AlsoWaitForTitle(title_error_empty_);
ui_test_utils::NavigateToURL(
- browser(), GURL(fake_server_address_ + test_path_ + filename));
+ browser, GURL(fake_server_address_ + test_path_ + filename));
string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(title_storing_, final_title);
}
void NavigateAndCheckStoredData(const std::string& filename) {
+ NavigateAndCheckStoredData(browser(), filename);
+ }
+
+ void NavigateAndCheckStoredData(Browser* browser,
+ const std::string& filename) {
// Navigate to a page which has previously stored data; check that the
// stored data can be accessed.
content::WebContents* web_contents =
- chrome::GetActiveWebContents(browser());
+ chrome::GetActiveWebContents(browser);
content::TitleWatcher title_watcher(web_contents, title_pass_);
title_watcher.AlsoWaitForTitle(title_storing_);
title_watcher.AlsoWaitForTitle(title_error_write_failed_);
title_watcher.AlsoWaitForTitle(title_error_empty_);
ui_test_utils::NavigateToURL(
- browser(), GURL(fake_server_address_ + test_path_ + filename));
+ browser, GURL(fake_server_address_ + test_path_ + filename));
string16 final_title = title_watcher.WaitAndGetTitle();
EXPECT_EQ(title_pass_, final_title);
}
void CheckReloadedPageRestored() {
- CheckTitle(title_pass_);
+ CheckTitle(browser(), title_pass_);
+ }
+
+ void CheckReloadedPageRestored(Browser* browser) {
+ CheckTitle(browser, title_pass_);
}
void CheckReloadedPageNotRestored() {
- CheckTitle(title_storing_);
+ CheckTitle(browser(), title_storing_);
}
- void CheckTitle(const string16& expected_title) {
- content::WebContents* web_contents = chrome::GetWebContentsAt(browser(), 0);
+ void CheckTitle(Browser* browser, const string16& expected_title) {
+ content::WebContents* web_contents = chrome::GetWebContentsAt(browser, 0);
content::TitleWatcher title_watcher(web_contents, expected_title);
title_watcher.AlsoWaitForTitle(title_pass_);
title_watcher.AlsoWaitForTitle(title_storing_);
@@ -222,9 +255,11 @@ class BetterSessionRestoreTest : public InProcessBrowserTest {
}
}
- private:
+ protected:
std::string fake_server_address_;
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 since you're only reading these values, it would b
marja 2012/12/17 16:45:58 Done.
std::string test_path_;
+
+ private:
string16 title_pass_;
string16 title_storing_;
string16 title_error_write_failed_;
@@ -475,3 +510,71 @@ IN_PROC_BROWSER_TEST_F(NoSessionRestoreTest, CookiesClearedOnExit) {
EXPECT_EQ(std::string(chrome::kAboutBlankURL), web_contents->GetURL().spec());
StoreDataWithPage("local_storage.html");
}
+
+class BetterSessionRestoreCrashTest : public BetterSessionRestoreTest {
+ public:
+ virtual void SetUpOnMainThread() OVERRIDE {
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 you should invoke the BetterSessionRestoreTest::Se
marja 2012/12/17 16:45:58 Done.
+ SessionStartupPref::SetStartupPref(
+ browser()->profile(), SessionStartupPref(SessionStartupPref::DEFAULT));
+ }
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 nit empty line after this
marja 2012/12/17 16:45:58 Done.
+ protected:
+ void CrashTestWithPage(const std::string& filename) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ FilePath profile_path = profile_manager->user_data_dir().Append(
+ FILE_PATH_LITERAL("test_profile"));
+ Profile* profile = profile_manager->GetProfile(profile_path);
+ ASSERT_TRUE(profile);
+ chrome::NewEmptyWindow(profile);
+ Browser* browser1 = FindOneOtherBrowserForProfile(profile, NULL);
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 can you pick a more descriptive name?
marja 2012/12/17 16:45:58 Done.
+ ASSERT_TRUE(browser1);
+ StoreDataWithPage(browser1, filename);
+
+ // Session restore data is written lazily but we cannot restore data that
+ // was not saved. Be less lazy for the test.
+ SessionServiceFactory::GetForProfile(profile)->Save();
+
+ // Simulate a crash and a restart.
+ browser()->window()->Close();
+ browser1->window()->Close();
+ SessionServiceFactory::GetForProfile(profile)->backend()->
+ MoveCurrentSessionToLastSession();
+ static_cast<ProfileImpl*>(profile)->last_session_exit_type_ =
+ Profile::EXIT_CRASHED;
+
+ CommandLine dummy(CommandLine::NO_PROGRAM);
+ int return_code;
+ StartupBrowserCreator browser_creator;
+ std::vector<Profile*> last_opened_profiles(1, profile);
+ browser_creator.Start(dummy, profile_manager->user_data_dir(), profile,
+ last_opened_profiles, &return_code);
+
+ // The browser displays an info bar, use it to restore the session.
+ Browser* browser2 = FindOneOtherBrowserForProfile(profile, browser1);
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 same here
marja 2012/12/17 16:45:58 Done.
+ ASSERT_TRUE(browser2);
+ content::WebContents* web_contents = chrome::GetWebContentsAt(browser2, 0);
+ ASSERT_TRUE(web_contents);
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL());
+ InfoBarTabHelper* info_bar_tab_helper =
+ InfoBarTabHelper::FromWebContents(web_contents);
+ EXPECT_EQ(1U, info_bar_tab_helper->GetInfoBarCount());
+ ConfirmInfoBarDelegate* info_bar_delegate =
+ static_cast<ConfirmInfoBarDelegate*>(
+ info_bar_tab_helper->GetInfoBarDelegateAt(0));
+ info_bar_delegate->Accept();
+
+ // Session restore is done ascynhronously.
+ base::RunLoop loop;
+ loop.RunUntilIdle();
+
+ // Check the restored page.
+ web_contents = chrome::GetWebContentsAt(browser2, 0);
+ ASSERT_TRUE(web_contents);
+ EXPECT_EQ(GURL(fake_server_address_ + test_path_ + filename),
+ web_contents->GetURL());
+ CheckReloadedPageRestored(browser2);
+ }
+};
jochen (gone - plz use gerrit) 2012/12/17 16:21:20 DISALLOW_COPY_AND_ASSIGN
marja 2012/12/17 16:45:58 Done.
+
+IN_PROC_BROWSER_TEST_F(BetterSessionRestoreCrashTest, SessionCookies) {
+ CrashTestWithPage("session_cookies.html");
+}

Powered by Google App Engine
This is Rietveld 408576698