diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-09 23:44:50 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-09 23:44:50 +0000 |
commit | 8d3cb43fa226eb45efcc14c902627dc98e4bf5ab (patch) | |
tree | 26cb5177cbb869e0ee294dba5e92c37745d824b4 | |
parent | 56a7efc80a04caed92f3a22448195ecb3c887f15 (diff) | |
download | chromium_src-8d3cb43fa226eb45efcc14c902627dc98e4bf5ab.zip chromium_src-8d3cb43fa226eb45efcc14c902627dc98e4bf5ab.tar.gz chromium_src-8d3cb43fa226eb45efcc14c902627dc98e4bf5ab.tar.bz2 |
Merge 94585 - BackgroundModeManager now relies on BALM to count installed bg apps.
Changed the BackgroundModeManager to drive background mode logic based on
BackgroundApplicationListManager::OnApplicationListChanged() notifications
rather than listening directly to extension notifications. This fixes bugs with
unforeseen edge cases like crashed app processes, due to our manual application
count getting out-of-sync with the extension service.
We still need to detect bg app installation so we can display UI/turn on Mac
launch-on-startup, but we don't manage our own count any more.
BUG=82215
TEST=Run through BG mode test cases (install/uninstall/disable/crash BG apps, make sure UI is updated properly).
Review URL: http://codereview.chromium.org/7497002
TBR=atwilson@chromium.org
Review URL: http://codereview.chromium.org/7590015
git-svn-id: svn://svn.chromium.org/chrome/branches/835/src@96100 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 178 insertions, 175 deletions
diff --git a/chrome/browser/background/background_mode_manager.cc b/chrome/browser/background/background_mode_manager.cc index c44362c..236b2f8 100644 --- a/chrome/browser/background/background_mode_manager.cc +++ b/chrome/browser/background/background_mode_manager.cc @@ -88,8 +88,8 @@ Browser* BackgroundModeManager::BackgroundModeData::GetBrowserWindow() { return browser; } -bool BackgroundModeManager::BackgroundModeData::HasBackgroundApp() { - return (applications_->size() > 0); +int BackgroundModeManager::BackgroundModeData::GetBackgroundAppCount() const { + return applications_->size(); } void BackgroundModeManager::BackgroundModeData::BuildProfileMenu( @@ -131,9 +131,9 @@ BackgroundModeManager::BackgroundModeManager(CommandLine* command_line) : status_tray_(NULL), status_icon_(NULL), context_menu_(NULL), - background_app_count_(0), in_background_mode_(false), keep_alive_for_startup_(false), + keep_alive_for_test_(false), current_command_id_(0) { // If background mode is currently disabled, just exit - don't listen for any // notifications. @@ -158,8 +158,10 @@ BackgroundModeManager::BackgroundModeManager(CommandLine* command_line) // If the -keep-alive-for-test flag is passed, then always keep chrome running // in the background until the user explicitly terminates it, by acting as if // we loaded a background app. - if (command_line->HasSwitch(switches::kKeepAliveForTest)) - OnBackgroundAppLoaded(); + if (command_line->HasSwitch(switches::kKeepAliveForTest)) { + keep_alive_for_test_ = true; + StartBackgroundMode(); + } // Listen for the application shutting down so we can decrement our KeepAlive // count. @@ -168,6 +170,8 @@ BackgroundModeManager::BackgroundModeManager(CommandLine* command_line) } BackgroundModeManager::~BackgroundModeManager() { + // Remove ourselves from the application observer list (only needed by unit + // tests since APP_TERMINATING is what does this in a real running system). for (std::map<Profile*, BackgroundModeInfo>::iterator it = background_mode_data_.begin(); it != background_mode_data_.end(); @@ -196,13 +200,11 @@ void BackgroundModeManager::RegisterProfile(Profile* profile) { profile, this)); background_mode_data_[profile] = bmd; - // Listen for when extensions are loaded/unloaded so we can track the - // number of background apps and modify our keep-alive and launch-on-startup - // state appropriately. + // Listen for when extensions are loaded so we can display a "background app + // installed" notification and enter "launch on login" mode on the Mac. registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, Source<Profile>(profile)); - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, - Source<Profile>(profile)); + // Check for the presence of background apps after all extensions have been // loaded, to handle the case where an extension has been manually removed @@ -236,17 +238,8 @@ void BackgroundModeManager::Observe(int type, // Extensions are loaded, so we don't need to manually keep the browser // process alive any more when running in no-startup-window mode. EndKeepAliveForStartup(); - - // On a Mac, we use 'login items' mechanism which has user-facing UI so we - // don't want to stomp on user choice every time we start and load - // registered extensions. This means that if a background app is removed - // or added while Chrome is not running, we could leave Chrome in the - // wrong state, but this is better than constantly forcing Chrome to - // launch on startup even after the user removes the LoginItem manually. -#if !defined(OS_MACOSX) - EnableLaunchOnStartup(background_app_count_ > 0); -#endif break; + case chrome::NOTIFICATION_EXTENSION_LOADED: { Extension* extension = Details<Extension>(details).ptr(); if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) { @@ -255,25 +248,9 @@ void BackgroundModeManager::Observe(int type, Profile* profile = Source<Profile>(source).ptr(); if (profile->GetExtensionService()->is_ready()) OnBackgroundAppInstalled(extension); - OnBackgroundAppLoaded(); } } break; - case chrome::NOTIFICATION_EXTENSION_UNLOADED: - if (BackgroundApplicationListModel::IsBackgroundApp( - *Details<UnloadedExtensionInfo>(details)->extension)) { - Details<UnloadedExtensionInfo> info = - Details<UnloadedExtensionInfo>(details); - // If we already got an unload notification when it was disabled, ignore - // this one. - // TODO(atwilson): Change BackgroundModeManager to use - // BackgroundApplicationListModel instead of tracking the count here. - if (info->already_disabled) - return; - OnBackgroundAppUnloaded(); - OnBackgroundAppUninstalled(); - } - break; case content::NOTIFICATION_APP_TERMINATING: // Make sure we aren't still keeping the app alive (only happens if we // don't receive an EXTENSIONS_READY notification for some reason). @@ -284,6 +261,12 @@ void BackgroundModeManager::Observe(int type, // Shutting down, so don't listen for any more notifications so we don't // try to re-enter/exit background mode again. registrar_.RemoveAll(); + for (std::map<Profile*, BackgroundModeInfo>::iterator it = + background_mode_data_.begin(); + it != background_mode_data_.end(); + ++it) { + it->second->applications_->RemoveObserver(this); + } break; default: NOTREACHED(); @@ -299,7 +282,38 @@ void BackgroundModeManager::OnApplicationDataChanged( } void BackgroundModeManager::OnApplicationListChanged(Profile* profile) { - UpdateStatusTrayIconContextMenu(); + if (!IsBackgroundModePrefEnabled()) + return; + + // Figure out what just happened based on the count of background apps. + int count = GetBackgroundAppCount(); + + if (count == 0) { + // We've uninstalled our last background app, make sure we exit background + // mode and no longer launch on startup. + EnableLaunchOnStartup(false); + EndBackgroundMode(); + } else { + // We have at least one background app running - make sure we're in + // background mode. + if (!in_background_mode_) { + // We're entering background mode - make sure we have launch-on-startup + // enabled. + // On a Mac, we use 'login items' mechanism which has user-facing UI so we + // don't want to stomp on user choice every time we start and load + // registered extensions. This means that if a background app is removed + // or added while Chrome is not running, we could leave Chrome in the + // wrong state, but this is better than constantly forcing Chrome to + // launch on startup even after the user removes the LoginItem manually. +#if !defined(OS_MACOSX) + EnableLaunchOnStartup(true); +#endif + + StartBackgroundMode(); + } + // List of applications changed so update the UI. + UpdateStatusTrayIconContextMenu(); + } } /////////////////////////////////////////////////////////////////////////////// @@ -370,16 +384,6 @@ void BackgroundModeManager::EndKeepAliveForStartup() { } } -void BackgroundModeManager::OnBackgroundAppLoaded() { - // When a background app loads, increment our count and also enable - // KeepAlive mode if the preference is set. - // The count here is across all profiles since we must have background - // mode if there is even one. - background_app_count_++; - if (background_app_count_ == 1) - StartBackgroundMode(); -} - void BackgroundModeManager::StartBackgroundMode() { // Don't bother putting ourselves in background mode if we're already there // or if background mode is disabled. @@ -399,28 +403,11 @@ void BackgroundModeManager::StartBackgroundMode() { void BackgroundModeManager::InitStatusTrayIcon() { // Only initialize status tray icons for those profiles which actually // have a background app running. - for (std::map<Profile*, BackgroundModeInfo>::iterator it = - background_mode_data_.begin(); - it != background_mode_data_.end(); - ++it) { - if (it->second->HasBackgroundApp()) { - // Once we've found a profile with a background app, we know to create - // the icon. - CreateStatusTrayIcon(); - return; - } + if (keep_alive_for_test_ || GetBackgroundAppCount() > 0) { + CreateStatusTrayIcon(); } } -void BackgroundModeManager::OnBackgroundAppUnloaded() { - // When a background app unloads, decrement our count and also end - // KeepAlive mode if appropriate. - background_app_count_--; - DCHECK_GE(background_app_count_, 0); - if (background_app_count_ == 0) - EndBackgroundMode(); -} - void BackgroundModeManager::EndBackgroundMode() { if (!in_background_mode_) return; @@ -435,7 +422,8 @@ void BackgroundModeManager::EndBackgroundMode() { void BackgroundModeManager::EnableBackgroundMode() { DCHECK(IsBackgroundModePrefEnabled()); // If background mode should be enabled, but isn't, turn it on. - if (background_app_count_ > 0 && !in_background_mode_) { + if (!in_background_mode_ && + (GetBackgroundAppCount() > 0 || keep_alive_for_test_)) { StartBackgroundMode(); EnableLaunchOnStartup(true); } @@ -450,18 +438,36 @@ void BackgroundModeManager::DisableBackgroundMode() { } } +int BackgroundModeManager::GetBackgroundAppCount() const { + int count = 0; + // Walk the BackgroundModeData for all profiles and count the number of apps. + for (std::map<Profile*, BackgroundModeInfo>::const_iterator it = + background_mode_data_.begin(); + it != background_mode_data_.end(); + ++it) { + count += it->second->GetBackgroundAppCount(); + } + DCHECK(count >= 0); + return count; +} + void BackgroundModeManager::OnBackgroundAppInstalled( const Extension* extension) { // Background mode is disabled - don't do anything. if (!IsBackgroundModePrefEnabled()) return; - // We're installing a background app. If this is the first background app - // being installed, make sure we are set to launch on startup. - if (background_app_count_ == 0) - EnableLaunchOnStartup(true); + // Special behavior for the Mac: We enable "launch-on-startup" only on new app + // installation rather than every time we go into background mode. This is + // because the Mac exposes "Open at Login" UI to the user and we don't want to + // clobber the user's selection on every browser launch. + // Other platforms enable launch-on-startup in OnApplicationListChanged(). +#if defined(OS_MACOSX) + EnableLaunchOnStartup(true); +#endif - // Check if we need a status tray icon and make one if we do. + // Check if we need a status tray icon and make one if we do (needed so we + // can display the app-installed notification below). CreateStatusTrayIcon(); // Notify the user that a background app has been installed. @@ -469,15 +475,6 @@ void BackgroundModeManager::OnBackgroundAppInstalled( DisplayAppInstalledNotification(extension); } -void BackgroundModeManager::OnBackgroundAppUninstalled() { - UpdateStatusTrayIconContextMenu(); - - // When uninstalling a background app, disable launch on startup if - // we have no more background apps. - if (background_app_count_ == 0) - EnableLaunchOnStartup(false); -} - void BackgroundModeManager::CreateStatusTrayIcon() { // Only need status icons on windows/linux. ChromeOS doesn't allow exiting // Chrome and Mac can use the dock icon instead. @@ -519,6 +516,13 @@ void BackgroundModeManager::UpdateStatusTrayIconContextMenu() { if (!status_icon_) return; + // We should only get here if we have a profile loaded, or if we're running + // in test mode. + if (background_mode_data_.empty()) { + DCHECK(keep_alive_for_test_); + return; + } + // TODO(rlp): Add current profile color or indicator. // Create a context menu item for Chrome. ui::SimpleMenuModel* menu = new ui::SimpleMenuModel(this); @@ -592,7 +596,7 @@ bool BackgroundModeManager::IsBackgroundModePermanentlyDisabled( #endif } -bool BackgroundModeManager::IsBackgroundModePrefEnabled() { +bool BackgroundModeManager::IsBackgroundModePrefEnabled() const { PrefService* service = g_browser_process->local_state(); DCHECK(service); return service->GetBoolean(prefs::kBackgroundModeEnabled); diff --git a/chrome/browser/background/background_mode_manager.h b/chrome/browser/background/background_mode_manager.h index 86028b1..75bb8af 100644 --- a/chrome/browser/background/background_mode_manager.h +++ b/chrome/browser/background/background_mode_manager.h @@ -58,7 +58,7 @@ class BackgroundModeManager FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, BackgroundAppLoadUnload); FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, - BackgroundAppInstallUninstall); + BackgroundLaunchOnStartup); FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled); FRIEND_TEST_ALL_PREFIXES(BackgroundModeManagerTest, @@ -90,8 +90,8 @@ class BackgroundModeManager // Browser window. Browser* GetBrowserWindow(); - // Returns whether any of the extensions are background apps. - bool HasBackgroundApp(); + // Returns the number of background apps for this profile. + int GetBackgroundAppCount() const; // Builds the profile specific parts of the menu. The menu passed in may // be a submenu in the case of multi-profiles or the main menu in the case @@ -145,21 +145,11 @@ class BackgroundModeManager OVERRIDE; virtual void ExecuteCommand(int command_id) OVERRIDE; - // Called when an extension is loaded to manage count of background apps. - void OnBackgroundAppLoaded(); - - // Called when an extension is unloaded to manage count of background apps. - void OnBackgroundAppUnloaded(); - // Invoked when an extension is installed so we can ensure that // launch-on-startup is enabled if appropriate. |extension| can be NULL when // called from unit tests. void OnBackgroundAppInstalled(const Extension* extension); - // Invoked when an extension is uninstalled so we can ensure that - // launch-on-startup is disabled if appropriate. - void OnBackgroundAppUninstalled(); - // Called to make sure that our launch-on-startup mode is properly set. // (virtual so we can override for tests). virtual void EnableLaunchOnStartup(bool should_launch); @@ -211,7 +201,7 @@ class BackgroundModeManager // Returns true if the "Let chrome run in the background" pref is checked. // (virtual to allow overriding in tests). - virtual bool IsBackgroundModePrefEnabled(); + virtual bool IsBackgroundModePrefEnabled() const; // Turns off background mode if it's currently enabled. void DisableBackgroundMode(); @@ -219,6 +209,10 @@ class BackgroundModeManager // Turns on background mode if it's currently disabled. void EnableBackgroundMode(); + // Returns the number of background apps in the system (virtual to allow + // overriding in unit tests). + virtual int GetBackgroundAppCount() const; + // Returns true if background mode is permanently disabled for this chrome // session. static bool IsBackgroundModePermanentlyDisabled( @@ -242,10 +236,6 @@ class BackgroundModeManager // status_icon_. ui::SimpleMenuModel* context_menu_; - // The number of background apps currently loaded. This is the total over - // all profiles. - int background_app_count_; - // Set to true when we are running in background mode. Allows us to track our // current background state so we can take the appropriate action when the // user disables/enables background mode via preferences. @@ -256,6 +246,11 @@ class BackgroundModeManager // chrome would immediately exit due to having no open windows. bool keep_alive_for_startup_; + // Set to true when Chrome is running with the --keep-alive-for-test flag + // (used for testing background mode without having to install a background + // app). + bool keep_alive_for_test_; + // Provides a command id for each profile as they are created. int current_command_id_; diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc index e35408c..be130b9 100644 --- a/chrome/browser/background/background_mode_manager_unittest.cc +++ b/chrome/browser/background/background_mode_manager_unittest.cc @@ -10,14 +10,8 @@ #include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_browser_process_test.h" #include "chrome/test/testing_profile.h" -#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; - class BackgroundModeManagerTest : public TestingBrowserProcessTest { public: BackgroundModeManagerTest() {} @@ -32,149 +26,159 @@ class TestBackgroundModeManager : public BackgroundModeManager { public: explicit TestBackgroundModeManager(CommandLine* command_line) : BackgroundModeManager(command_line), - enabled_(true) {} - MOCK_METHOD1(EnableLaunchOnStartup, void(bool)); - MOCK_METHOD0(CreateStatusTrayIcon, void()); - MOCK_METHOD0(RemoveStatusTrayIcon, void()); - virtual bool IsBackgroundModePrefEnabled() { return enabled_; } + enabled_(true), + app_count_(0), + have_status_tray_(false), + launch_on_startup_(false) {} + virtual void EnableLaunchOnStartup(bool launch) OVERRIDE { + launch_on_startup_ = launch; + } + virtual void CreateStatusTrayIcon() OVERRIDE { have_status_tray_ = true; } + virtual void RemoveStatusTrayIcon() OVERRIDE { have_status_tray_ = false; } + virtual int GetBackgroundAppCount() const OVERRIDE { return app_count_; } + virtual bool IsBackgroundModePrefEnabled() const OVERRIDE { return enabled_; } + void SetBackgroundAppCount(int count) { app_count_ = count; } void SetEnabled(bool enabled) { enabled_ = enabled; } + bool HaveStatusTray() const { return have_status_tray_; } + bool IsLaunchOnStartup() const { return launch_on_startup_; } private: bool enabled_; + int app_count_; + + // Flags to track whether we are launching on startup/have a status tray. + bool have_status_tray_; + bool launch_on_startup_; }; -TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { - InSequence s; - TestingProfile profile; - TestBackgroundModeManager manager(command_line_.get()); - manager.RegisterProfile(&profile); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); - EXPECT_FALSE(BrowserList::WillKeepAlive()); - // 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(); +static void AssertBackgroundModeActive( + const TestBackgroundModeManager& manager) { EXPECT_TRUE(BrowserList::WillKeepAlive()); - manager.OnBackgroundAppUnloaded(); + EXPECT_TRUE(manager.HaveStatusTray()); + EXPECT_TRUE(manager.IsLaunchOnStartup()); +} + +static void AssertBackgroundModeInactive( + const TestBackgroundModeManager& manager) { EXPECT_FALSE(BrowserList::WillKeepAlive()); + EXPECT_FALSE(manager.HaveStatusTray()); + EXPECT_FALSE(manager.IsLaunchOnStartup()); } -TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) { - InSequence s; +TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { TestingProfile profile; 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, EnableLaunchOnStartup(false)); + EXPECT_FALSE(BrowserList::WillKeepAlive()); + + // Mimic app load. manager.OnBackgroundAppInstalled(NULL); - manager.OnBackgroundAppLoaded(); - manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled();} + manager.SetBackgroundAppCount(1); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeActive(manager); + + // Mimic app unload. + manager.SetBackgroundAppCount(0); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeInactive(manager); +} -// App installs while disabled should do nothing. +// App installs while background mode is disabled should do nothing. TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { - InSequence s; TestingProfile profile; TestBackgroundModeManager manager(command_line_.get()); manager.RegisterProfile(&profile); // Turn off background mode. manager.SetEnabled(false); manager.DisableBackgroundMode(); + AssertBackgroundModeInactive(manager); - // 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)); + // Status tray icons will not be created, launch on startup status will not + // be modified. manager.OnBackgroundAppInstalled(NULL); - manager.OnBackgroundAppLoaded(); - manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); + manager.SetBackgroundAppCount(1); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeInactive(manager); + + manager.SetBackgroundAppCount(0); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeInactive(manager); // Re-enable background mode. manager.SetEnabled(true); manager.EnableBackgroundMode(); + AssertBackgroundModeInactive(manager); } -// App installs while disabled should do nothing. +// App installs while disabled should do nothing until background mode is +// enabled.. TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) { - InSequence s; TestingProfile profile; TestBackgroundModeManager manager(command_line_.get()); manager.RegisterProfile(&profile); - EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); - EXPECT_CALL(manager, EnableLaunchOnStartup(false)); - EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); - EXPECT_CALL(manager, EnableLaunchOnStartup(false)); // Install app, should show status tray icon. manager.OnBackgroundAppInstalled(NULL); // OnBackgroundAppInstalled does not actually add an app to the // BackgroundApplicationListModel which would result in another // call to CreateStatusTray. - manager.OnBackgroundAppLoaded(); + manager.SetBackgroundAppCount(1); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeActive(manager); // Turn off background mode - should hide status tray icon. manager.SetEnabled(false); manager.DisableBackgroundMode(); + AssertBackgroundModeInactive(manager); // 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(); + AssertBackgroundModeActive(manager); // Uninstall app, should hide status tray icon again. - manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); + manager.SetBackgroundAppCount(0); + manager.OnApplicationListChanged(&profile); + AssertBackgroundModeInactive(manager); } 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()); - EXPECT_CALL(manager, EnableLaunchOnStartup(false)); - EXPECT_CALL(manager, EnableLaunchOnStartup(true)); - EXPECT_CALL(manager, CreateStatusTrayIcon()); - EXPECT_CALL(manager, RemoveStatusTrayIcon()); - EXPECT_CALL(manager, EnableLaunchOnStartup(false)); EXPECT_FALSE(BrowserList::WillKeepAlive()); // Install app, should show status tray icon. manager.OnBackgroundAppInstalled(NULL); - // OnBackgroundAppInstalled does not actually add an app to the - // BackgroundApplicationListModel which would result in another - // call to CreateStatusTray. - manager.OnBackgroundAppLoaded(); + manager.SetBackgroundAppCount(1); + manager.OnApplicationListChanged(&profile1); + AssertBackgroundModeActive(manager); // Install app for other profile, hsould show other status tray icon. manager.OnBackgroundAppInstalled(NULL); - manager.OnBackgroundAppLoaded(); + manager.SetBackgroundAppCount(2); + manager.OnApplicationListChanged(&profile2); + AssertBackgroundModeActive(manager); // Should hide both status tray icons. manager.SetEnabled(false); manager.DisableBackgroundMode(); + AssertBackgroundModeInactive(manager); // Turn back on background mode - should show both status tray icons. manager.SetEnabled(true); manager.EnableBackgroundMode(); + AssertBackgroundModeActive(manager); - manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); + manager.SetBackgroundAppCount(1); + manager.OnApplicationListChanged(&profile2); // There is still one background app alive - EXPECT_TRUE(BrowserList::WillKeepAlive()); - manager.OnBackgroundAppUnloaded(); - manager.OnBackgroundAppUninstalled(); - EXPECT_FALSE(BrowserList::WillKeepAlive()); + AssertBackgroundModeActive(manager); + + manager.SetBackgroundAppCount(0); + manager.OnApplicationListChanged(&profile1); + AssertBackgroundModeInactive(manager); } |