From 97a1122a346843cd92c74173c6011d0abd810816 Mon Sep 17 00:00:00 2001 From: "atwilson@chromium.org" Date: Fri, 27 Aug 2010 06:39:22 +0000 Subject: 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 --- chrome/browser/background_mode_manager_unittest.cc | 61 ++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'chrome/browser/background_mode_manager_unittest.cc') 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()); +} -- cgit v1.1