summaryrefslogtreecommitdiffstats
path: root/chrome/browser/background_mode_manager_unittest.cc
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 23:17:23 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 23:17:23 +0000
commitab08260d36bbcea95b1010b5e7eae79c12f45dcd (patch)
tree846a21f811c6132d197a9153450f8e78ecd5f7ce /chrome/browser/background_mode_manager_unittest.cc
parentfe9eb4f9d93a56a26d99fba1d3d3761fd6590fb2 (diff)
downloadchromium_src-ab08260d36bbcea95b1010b5e7eae79c12f45dcd.zip
chromium_src-ab08260d36bbcea95b1010b5e7eae79c12f45dcd.tar.gz
chromium_src-ab08260d36bbcea95b1010b5e7eae79c12f45dcd.tar.bz2
Disable background mode when associated pref changes.
BUG=53173 TEST=new BackgroundModeManager unit tests Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=57642 Review URL: http://codereview.chromium.org/3205008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57749 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/background_mode_manager_unittest.cc')
-rw-r--r--chrome/browser/background_mode_manager_unittest.cc61
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());
+}