diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 17:56:39 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-14 17:56:39 +0000 |
commit | 9c65ad7d4c211e352e5db57e4ab38042d6e7af15 (patch) | |
tree | 5737a2d3660d85862675c85fe0ea28945caa09c7 /chrome/browser/ui | |
parent | 79d7a042a94dd6bd02acd02d9d6fef8238eab654 (diff) | |
download | chromium_src-9c65ad7d4c211e352e5db57e4ab38042d6e7af15.zip chromium_src-9c65ad7d4c211e352e5db57e4ab38042d6e7af15.tar.gz chromium_src-9c65ad7d4c211e352e5db57e4ab38042d6e7af15.tar.bz2 |
Revert 114441 - Follow-up changes to http://codereview.chromium.org/8937001
Adding tests + minor code cleanup.
BUG=NONE
TEST=BrowserListTest.AttemptRestart, BrowserInitTest.ReadingWasRestartAfter(Restart|NormalStart)
Review URL: http://codereview.chromium.org/8929027
TBR=marja@chromium.org
Review URL: http://codereview.chromium.org/8916006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser_init.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/browser_init_browsertest.cc | 23 | ||||
-rw-r--r-- | chrome/browser/ui/browser_list_unittest.cc | 30 |
4 files changed, 12 insertions, 63 deletions
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index fb97a24..6d2bc1e 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -498,6 +498,9 @@ void RegisterComponentsForUpdate(const CommandLine& command_line) { // BrowserInit ---------------------------------------------------------------- +bool BrowserInit::was_restarted_ = false; +bool BrowserInit::was_restarted_read_ = false; + BrowserInit::BrowserInit() {} BrowserInit::~BrowserInit() {} @@ -586,20 +589,14 @@ bool BrowserInit::LaunchBrowser(const CommandLine& command_line, // static bool BrowserInit::WasRestarted() { - // 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) { + 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 9e2ebfc..84b1973 100644 --- a/chrome/browser/ui/browser_init.h +++ b/chrome/browser/ui/browser_init.h @@ -255,6 +255,11 @@ 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 4f16d2d..f04fc8b 100644 --- a/chrome/browser/ui/browser_init_browsertest.cc +++ b/chrome/browser/ui/browser_init_browsertest.cc @@ -5,11 +5,9 @@ #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" @@ -17,7 +15,6 @@ #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" @@ -312,24 +309,4 @@ 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 c96e152..ca5d26c 100644 --- a/chrome/browser/ui/browser_list_unittest.cc +++ b/chrome/browser/ui/browser_list_unittest.cc @@ -2,19 +2,12 @@ // 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; @@ -239,26 +232,3 @@ TEST_F(BrowserListTest, TabContentsIteratorBackgroundPrinting) { EXPECT_EQ(0U, CountAllTabs()); } #endif - -TEST_F(BrowserListTest, 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); -} |