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

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
« no previous file with comments | « chrome/browser/background_mode_manager_mac.mm ('k') | chrome/browser/background_mode_manager_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/background_mode_manager_unittest.cc
===================================================================
--- chrome/browser/background_mode_manager_unittest.cc (revision 86624)
+++ chrome/browser/background_mode_manager_unittest.cc (working copy)
@@ -13,6 +13,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
using testing::AtLeast;
using testing::InSequence;
using testing::Return;
@@ -29,12 +30,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,12 +45,14 @@
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, 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.
+ // Call to AppLoaded() will not cause the status tray to be created,
+ // because no apps have been installed. However the call to AppUnloaded()
+ // will result in a call RemoveStatusTrayIcon since it will try to unload
+ // all icons now that there are no apps.
manager.OnBackgroundAppLoaded();
EXPECT_TRUE(BrowserList::WillKeepAlive());
manager.OnBackgroundAppUnloaded();
@@ -59,35 +62,37 @@
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(_));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2);
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- manager.OnBackgroundAppInstalled(NULL);
+ manager.OnBackgroundAppInstalled(NULL, &profile);
manager.OnBackgroundAppLoaded();
manager.OnBackgroundAppUnloaded();
- manager.OnBackgroundAppUninstalled();
-}
+ manager.OnBackgroundAppUninstalled(&profile);}
// App installs while disabled should do nothing.
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.
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_));
manager.SetEnabled(false);
manager.DisableBackgroundMode();
// 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();
+ manager.OnBackgroundAppUninstalled(&profile);
// Re-enable background mode.
manager.SetEnabled(true);
@@ -99,29 +104,77 @@
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(_));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_));
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- EXPECT_CALL(manager, CreateStatusTrayIcon());
EXPECT_CALL(manager, EnableLaunchOnStartup(true));
- EXPECT_CALL(manager, RemoveStatusTrayIcon());
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2);
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
// Install app, should show status tray icon.
- manager.OnBackgroundAppInstalled(NULL);
+ manager.OnBackgroundAppInstalled(NULL, &profile);
+ // OnBackgroundAppInstalled does not actually add an app to the
+ // BackgroundApplicationListModel which would result in another
+ // call to CreateStatusTray.
manager.OnBackgroundAppLoaded();
// Turn off background mode - should hide status tray icon.
manager.SetEnabled(false);
manager.DisableBackgroundMode();
- // Turn back on background mode - should show status tray icon.
+ // Turn back on background mode - again, no status tray icon
+ // will show up since we didn't actually add anything to the list.
manager.SetEnabled(true);
manager.EnableBackgroundMode();
// Uninstall app, should hide status tray icon again.
manager.OnBackgroundAppUnloaded();
- manager.OnBackgroundAppUninstalled();
+ manager.OnBackgroundAppUninstalled(&profile);
}
+
+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(_)).Times(2);
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(2);
+ EXPECT_CALL(manager, EnableLaunchOnStartup(false));
+ EXPECT_CALL(manager, EnableLaunchOnStartup(true));
+ EXPECT_CALL(manager, RemoveStatusTrayIcon(_)).Times(4);
+ EXPECT_CALL(manager, EnableLaunchOnStartup(false));
+ EXPECT_FALSE(BrowserList::WillKeepAlive());
+
+ // Install app, should show status tray icon.
+ manager.OnBackgroundAppInstalled(NULL, &profile1);
+ // OnBackgroundAppInstalled does not actually add an app to the
+ // BackgroundApplicationListModel which would result in another
+ // call to CreateStatusTray.
+ 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(&profile1);
+ // There is still one background app alive
+ EXPECT_TRUE(BrowserList::WillKeepAlive());
+ manager.OnBackgroundAppUnloaded();
+ manager.OnBackgroundAppUninstalled(&profile2);
+ EXPECT_FALSE(BrowserList::WillKeepAlive());
+}
« no previous file with comments | « chrome/browser/background_mode_manager_mac.mm ('k') | chrome/browser/background_mode_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698