Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1109)

Unified Diff: chrome/browser/background_mode_manager_unittest.cc

Issue 6914021: Modifying the BackgroundModeManager to handle multiple profiles. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/background_mode_manager_unittest.cc
===================================================================
--- chrome/browser/background_mode_manager_unittest.cc (revision 85937)
+++ chrome/browser/background_mode_manager_unittest.cc (working copy)
@@ -29,12 +29,12 @@
class TestBackgroundModeManager : public BackgroundModeManager {
public:
- TestBackgroundModeManager(Profile* profile, CommandLine* cl)
- : BackgroundModeManager(profile, cl),
+ explicit TestBackgroundModeManager(CommandLine* command_line)
+ : BackgroundModeManager(command_line),
enabled_(true) {}
MOCK_METHOD1(EnableLaunchOnStartup, void(bool));
- MOCK_METHOD0(CreateStatusTrayIcon, void());
- MOCK_METHOD0(RemoveStatusTrayIcon, void());
+ MOCK_METHOD1(CreateStatusTrayIcon, void(Profile*)); // NOLINT
+ MOCK_METHOD1(RemoveStatusTrayIcon, void(Profile*)); // NOLINT
virtual bool IsBackgroundModePrefEnabled() { return enabled_; }
void SetEnabled(bool enabled) { enabled_ = enabled; }
private:
@@ -44,9 +44,10 @@
TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) {
InSequence s;
TestingProfile profile;
- TestBackgroundModeManager manager(&profile, command_line_.get());
- EXPECT_CALL(manager, CreateStatusTrayIcon());
- EXPECT_CALL(manager, RemoveStatusTrayIcon());
+ TestBackgroundModeManager manager(command_line_.get());
+ manager.RegisterProfile(&profile);
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
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.
@@ -59,14 +60,15 @@
TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) {
InSequence s;
TestingProfile profile;
- TestBackgroundModeManager manager(&profile, command_line_.get());
+ TestBackgroundModeManager manager(command_line_.get());
+ manager.RegisterProfile(&profile);
// Call to AppInstalled() will cause chrome to be set to launch on startup,
// and call to AppUninstalled() set chrome to not launch on startup.
EXPECT_CALL(manager, EnableLaunchOnStartup(true));
- EXPECT_CALL(manager, CreateStatusTrayIcon());
- EXPECT_CALL(manager, RemoveStatusTrayIcon());
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- manager.OnBackgroundAppInstalled(NULL);
+ manager.OnBackgroundAppInstalled(NULL, &profile);
manager.OnBackgroundAppLoaded();
manager.OnBackgroundAppUnloaded();
manager.OnBackgroundAppUninstalled();
@@ -76,7 +78,8 @@
TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) {
InSequence s;
TestingProfile profile;
- TestBackgroundModeManager manager(&profile, command_line_.get());
+ TestBackgroundModeManager manager(command_line_.get());
+ manager.RegisterProfile(&profile);
// Turn off background mode.
manager.SetEnabled(false);
manager.DisableBackgroundMode();
@@ -84,7 +87,7 @@
// Status tray icons will not be created, launch on startup status will be set
// to "do not launch on startup".
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- manager.OnBackgroundAppInstalled(NULL);
+ manager.OnBackgroundAppInstalled(NULL, &profile);
manager.OnBackgroundAppLoaded();
manager.OnBackgroundAppUnloaded();
manager.OnBackgroundAppUninstalled();
@@ -99,18 +102,19 @@
TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) {
InSequence s;
TestingProfile profile;
- TestBackgroundModeManager manager(&profile, command_line_.get());
+ TestBackgroundModeManager manager(command_line_.get());
+ manager.RegisterProfile(&profile);
EXPECT_CALL(manager, EnableLaunchOnStartup(true));
- EXPECT_CALL(manager, CreateStatusTrayIcon());
- EXPECT_CALL(manager, RemoveStatusTrayIcon());
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- EXPECT_CALL(manager, CreateStatusTrayIcon());
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
EXPECT_CALL(manager, EnableLaunchOnStartup(true));
- EXPECT_CALL(manager, RemoveStatusTrayIcon());
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
// Install app, should show status tray icon.
- manager.OnBackgroundAppInstalled(NULL);
+ manager.OnBackgroundAppInstalled(NULL, &profile);
manager.OnBackgroundAppLoaded();
// Turn off background mode - should hide status tray icon.
@@ -125,3 +129,49 @@
manager.OnBackgroundAppUnloaded();
manager.OnBackgroundAppUninstalled();
}
+
+TEST_F(BackgroundModeManagerTest, MultiProfile) {
+ InSequence s;
+ TestingProfile profile1;
+ TestingProfile profile2;
+ TestBackgroundModeManager manager(command_line_.get());
+ manager.RegisterProfile(&profile1);
+ manager.RegisterProfile(&profile2);
+ EXPECT_CALL(manager, EnableLaunchOnStartup(true));
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile1));
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile2));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile1));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile2));
+ EXPECT_CALL(manager, EnableLaunchOnStartup(false));
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile1));
+ EXPECT_CALL(manager, CreateStatusTrayIcon(&profile2));
+ EXPECT_CALL(manager, EnableLaunchOnStartup(true));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile1));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile2));
+ EXPECT_CALL(manager, EnableLaunchOnStartup(false));
+ EXPECT_FALSE(BrowserList::WillKeepAlive());
+
+ // Install app, should show status tray icon.
+ manager.OnBackgroundAppInstalled(NULL, &profile1);
rpetterson 2011/05/20 05:53:17 What needs to be done to be able to call these pri
Miranda Callahan 2011/05/20 15:16:53 Have you tried adding this line to background_mode
Andrew T Wilson (Slow) 2011/05/20 16:52:46 Yeah, Miranda is correct. I really hate this patte
rpetterson 2011/05/23 03:23:19 Thanks!
+ manager.OnBackgroundAppLoaded();
+
+ // Install app for other profile, hsould show other status tray icon.
+ manager.OnBackgroundAppInstalled(NULL, &profile2);
+ manager.OnBackgroundAppLoaded();
+
+ // Should hide both status tray icons.
+ manager.SetEnabled(false);
+ manager.DisableBackgroundMode();
+
+ // Turn back on background mode - should show both status tray icons.
+ manager.SetEnabled(true);
+ manager.EnableBackgroundMode();
+
+ manager.OnBackgroundAppUnloaded();
+ manager.OnBackgroundAppUninstalled();
+ // There is still one background app alive
+ EXPECT_TRUE(BrowserList::WillKeepAlive());
+ manager.OnBackgroundAppUnloaded();
+ manager.OnBackgroundAppUninstalled();
+ EXPECT_FALSE(BrowserList::WillKeepAlive());
+}

Powered by Google App Engine
This is Rietveld 408576698