diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 06:39:22 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-27 06:39:22 +0000 |
commit | 97a1122a346843cd92c74173c6011d0abd810816 (patch) | |
tree | 21332d63c36c31c0beaa2c1dcd407b8222b75ba7 /chrome/browser/background_mode_manager_unittest.cc | |
parent | 6506f2aee4619a49f4ac32e729f7a01e34b9d8e8 (diff) | |
download | chromium_src-97a1122a346843cd92c74173c6011d0abd810816.zip chromium_src-97a1122a346843cd92c74173c6011d0abd810816.tar.gz chromium_src-97a1122a346843cd92c74173c6011d0abd810816.tar.bz2 |
Disable background mode when associated pref changes.
BUG=53173
TEST=new BackgroundModeManager unit tests
Review URL: http://codereview.chromium.org/3205008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57642 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_mode_manager_unittest.cc')
-rw-r--r-- | chrome/browser/background_mode_manager_unittest.cc | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/chrome/browser/background_mode_manager_unittest.cc b/chrome/browser/background_mode_manager_unittest.cc index 087b4fe..f028c7c 100644 --- a/chrome/browser/background_mode_manager_unittest.cc +++ b/chrome/browser/background_mode_manager_unittest.cc @@ -4,10 +4,14 @@ #include "chrome/browser/background_mode_manager.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/common/pref_names.h" #include "chrome/test/testing_profile.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" +using testing::InSequence; + class TestBackgroundModeManager : public BackgroundModeManager { public: explicit TestBackgroundModeManager(Profile* profile) @@ -19,28 +23,79 @@ class TestBackgroundModeManager : public BackgroundModeManager { }; TEST(BackgroundModeManagerTest, BackgroundAppLoadUnload) { + InSequence s; TestingProfile profile; TestBackgroundModeManager manager(&profile); + EXPECT_CALL(manager, CreateStatusTrayIcon()); + EXPECT_CALL(manager, RemoveStatusTrayIcon()); EXPECT_FALSE(BrowserList::WillKeepAlive()); // Call to AppLoaded() will cause the status tray to be created, then call to // unloaded will result in call to remove the icon. - EXPECT_CALL(manager, CreateStatusTrayIcon()); manager.OnBackgroundAppLoaded(); EXPECT_TRUE(BrowserList::WillKeepAlive()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); manager.OnBackgroundAppUnloaded(); EXPECT_FALSE(BrowserList::WillKeepAlive()); } TEST(BackgroundModeManagerTest, BackgroundAppInstallUninstall) { + InSequence s; TestingProfile profile; TestBackgroundModeManager manager(&profile); // Call to AppInstalled() will cause chrome to be set to launch on startup, // and call to AppUninstalling() set chrome to not launch on startup. EXPECT_CALL(manager, EnableLaunchOnStartup(true)); + EXPECT_CALL(manager, CreateStatusTrayIcon()); + EXPECT_CALL(manager, EnableLaunchOnStartup(false)); + EXPECT_CALL(manager, RemoveStatusTrayIcon()); manager.OnBackgroundAppInstalled(); manager.OnBackgroundAppLoaded(); - EXPECT_CALL(manager, EnableLaunchOnStartup(false)); manager.OnBackgroundAppUninstalled(); manager.OnBackgroundAppUnloaded(); } + +TEST(BackgroundModeManagerTest, BackgroundPrefDisabled) { + InSequence s; + TestingProfile profile; + profile.GetPrefs()->SetBoolean(prefs::kBackgroundModeEnabled, false); + TestBackgroundModeManager manager(&profile); + // Should not change launch on startup status when installing/uninstalling + // if background mode is disabled. + EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(0); + EXPECT_CALL(manager, CreateStatusTrayIcon()).Times(0); + manager.OnBackgroundAppInstalled(); + manager.OnBackgroundAppLoaded(); + EXPECT_FALSE(BrowserList::WillKeepAlive()); + manager.OnBackgroundAppUninstalled(); + manager.OnBackgroundAppUnloaded(); +} + +TEST(BackgroundModeManagerTest, BackgroundPrefDynamicDisable) { + InSequence s; + TestingProfile profile; + TestBackgroundModeManager manager(&profile); + EXPECT_CALL(manager, EnableLaunchOnStartup(true)); + EXPECT_CALL(manager, CreateStatusTrayIcon()); + EXPECT_CALL(manager, EnableLaunchOnStartup(false)); + EXPECT_CALL(manager, RemoveStatusTrayIcon()); + manager.OnBackgroundAppInstalled(); + manager.OnBackgroundAppLoaded(); + EXPECT_TRUE(BrowserList::WillKeepAlive()); + // Disable status on the fly. + profile.GetPrefs()->SetBoolean(prefs::kBackgroundModeEnabled, false); + EXPECT_FALSE(BrowserList::WillKeepAlive()); +} + +TEST(BackgroundModeManagerTest, BackgroundPrefDynamicEnable) { + InSequence s; + TestingProfile profile; + TestBackgroundModeManager manager(&profile); + profile.GetPrefs()->SetBoolean(prefs::kBackgroundModeEnabled, false); + EXPECT_CALL(manager, EnableLaunchOnStartup(true)); + EXPECT_CALL(manager, CreateStatusTrayIcon()); + manager.OnBackgroundAppInstalled(); + manager.OnBackgroundAppLoaded(); + EXPECT_FALSE(BrowserList::WillKeepAlive()); + // Enable status on the fly. + profile.GetPrefs()->SetBoolean(prefs::kBackgroundModeEnabled, true); + EXPECT_TRUE(BrowserList::WillKeepAlive()); +} |