summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/browser_init.cc17
-rw-r--r--chrome/browser/ui/browser_init.h5
-rw-r--r--chrome/browser/ui/browser_init_browsertest.cc23
-rw-r--r--chrome/browser/ui/browser_list_unittest.cc37
4 files changed, 70 insertions, 12 deletions
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index ecb78e4..a6555eb 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -504,9 +504,6 @@ void RegisterComponentsForUpdate(const CommandLine& command_line) {
// BrowserInit ----------------------------------------------------------------
-bool BrowserInit::was_restarted_ = false;
-bool BrowserInit::was_restarted_read_ = false;
-
BrowserInit::BrowserInit() {}
BrowserInit::~BrowserInit() {}
@@ -595,14 +592,20 @@ bool BrowserInit::LaunchBrowser(const CommandLine& command_line,
// static
bool BrowserInit::WasRestarted() {
- if (!was_restarted_read_) {
+ // Stores the value of the preference kWasRestarted had when it was read.
+ static bool was_restarted = false;
+
+ // True if we have already read and reset the preference kWasRestarted.
+ static bool was_restarted_read = false;
+
+ if (!was_restarted_read) {
PrefService* pref_service = g_browser_process->local_state();
- was_restarted_ = pref_service->GetBoolean(prefs::kWasRestarted);
+ was_restarted = pref_service->GetBoolean(prefs::kWasRestarted);
pref_service->SetBoolean(prefs::kWasRestarted, false);
pref_service->ScheduleSavePersistentPrefs();
- was_restarted_read_ = true;
+ was_restarted_read = true;
}
- return was_restarted_;
+ return was_restarted;
}
// BrowserInit::LaunchWithProfile::Tab ----------------------------------------
diff --git a/chrome/browser/ui/browser_init.h b/chrome/browser/ui/browser_init.h
index 84b1973..9e2ebfc 100644
--- a/chrome/browser/ui/browser_init.h
+++ b/chrome/browser/ui/browser_init.h
@@ -255,11 +255,6 @@ class BrowserInit {
// Additional tabs to open during first run.
std::vector<GURL> first_run_tabs_;
- // Stores the value of the preference kWasRestarted had when it was read.
- static bool was_restarted_;
- // True if we have already read and reset the preference kWasRestarted.
- static bool was_restarted_read_;
-
DISALLOW_COPY_AND_ASSIGN(BrowserInit);
};
diff --git a/chrome/browser/ui/browser_init_browsertest.cc b/chrome/browser/ui/browser_init_browsertest.cc
index f04fc8b..4f16d2d 100644
--- a/chrome/browser/ui/browser_init_browsertest.cc
+++ b/chrome/browser/ui/browser_init_browsertest.cc
@@ -5,9 +5,11 @@
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/first_run/first_run.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/ui/browser.h"
@@ -15,6 +17,7 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -309,4 +312,24 @@ IN_PROC_BROWSER_TEST_F(BrowserInitTest, OpenAppShortcutPanel) {
std::string::npos) << new_browser->app_name_;
}
+IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterRestart) {
+ // Tests that BrowserInit::WasRestarted reads and resets the preference
+ // kWasRestarted correctly.
+ PrefService* pref_service = g_browser_process->local_state();
+ pref_service->SetBoolean(prefs::kWasRestarted, true);
+ EXPECT_TRUE(BrowserInit::WasRestarted());
+ EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
+ EXPECT_TRUE(BrowserInit::WasRestarted());
+}
+
+IN_PROC_BROWSER_TEST_F(BrowserInitTest, ReadingWasRestartedAfterNormalStart) {
+ // Tests that BrowserInit::WasRestarted reads and resets the preference
+ // kWasRestarted correctly.
+ PrefService* pref_service = g_browser_process->local_state();
+ pref_service->SetBoolean(prefs::kWasRestarted, false);
+ EXPECT_FALSE(BrowserInit::WasRestarted());
+ EXPECT_FALSE(pref_service->GetBoolean(prefs::kWasRestarted));
+ EXPECT_FALSE(BrowserInit::WasRestarted());
+}
+
#endif // !defined(OS_MACOSX)
diff --git a/chrome/browser/ui/browser_list_unittest.cc b/chrome/browser/ui/browser_list_unittest.cc
index ca5d26c..7cff8a5 100644
--- a/chrome/browser/ui/browser_list_unittest.cc
+++ b/chrome/browser/ui/browser_list_unittest.cc
@@ -2,12 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_shutdown.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/printing/background_printing_manager.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_pref_service.h"
+#include "chrome/test/base/testing_profile_manager.h"
#include "content/browser/tab_contents/tab_contents.h"
typedef BrowserWithTestWindowTest BrowserListTest;
@@ -232,3 +239,33 @@ TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) {
EXPECT_EQ(0U, CountAllTabs());
}
#endif
+
+#if defined(OS_CHROMEOS)
+// Calling AttemptRestart on ChromeOS will exit the test.
+#define MAYBE_AttemptRestart DISABLED_AttemptRestart
+#else
+#define MAYBE_AttemptRestart AttemptRestart
+#endif
+
+TEST_F(BrowserListTest, MAYBE_AttemptRestart) {
+ ASSERT_TRUE(g_browser_process);
+ TestingPrefService testing_pref_service;
+ testing_pref_service.RegisterBooleanPref(prefs::kWasRestarted, false);
+ testing_pref_service.RegisterBooleanPref(prefs::kRestartLastSessionOnShutdown,
+ false);
+
+ TestingBrowserProcess* testing_browser_process =
+ static_cast<TestingBrowserProcess*>(g_browser_process);
+ testing_browser_process->SetLocalState(&testing_pref_service);
+ ASSERT_TRUE(g_browser_process->local_state());
+ ProfileManager* profile_manager = new ProfileManager(FilePath());
+ testing_browser_process->SetProfileManager(profile_manager);
+
+ BrowserList::AttemptRestart();
+ // Cancel the effects of us calling BrowserList::AttemptRestart. Otherwise
+ // tests ran after this one will fail.
+ browser_shutdown::SetTryingToQuit(false);
+
+ EXPECT_TRUE(testing_pref_service.GetBoolean(prefs::kWasRestarted));
+ testing_browser_process->SetLocalState(NULL);
+}