Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/background/background_mode_manager.h" | 8 #include "chrome/browser/background/background_mode_manager.h" |
| 9 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 class TestBackgroundModeManager : public BackgroundModeManager { | 32 class TestBackgroundModeManager : public BackgroundModeManager { |
| 33 public: | 33 public: |
| 34 TestBackgroundModeManager( | 34 TestBackgroundModeManager( |
| 35 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) | 35 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) |
| 36 : BackgroundModeManager(command_line, cache), | 36 : BackgroundModeManager(command_line, cache), |
| 37 enabled_(enabled), | 37 enabled_(enabled), |
| 38 app_count_(0), | 38 app_count_(0), |
| 39 profile_app_count_(0), | 39 profile_app_count_(0), |
| 40 have_status_tray_(false), | 40 have_status_tray_(false), |
| 41 launch_on_startup_(false) {} | 41 launch_on_startup_(false) { |
| 42 ResumeBackgroundMode(); | |
| 43 } | |
| 42 virtual void EnableLaunchOnStartup(bool launch) OVERRIDE { | 44 virtual void EnableLaunchOnStartup(bool launch) OVERRIDE { |
| 43 launch_on_startup_ = launch; | 45 launch_on_startup_ = launch; |
| 44 } | 46 } |
| 45 virtual void CreateStatusTrayIcon() OVERRIDE { have_status_tray_ = true; } | 47 virtual void CreateStatusTrayIcon() OVERRIDE { have_status_tray_ = true; } |
| 46 virtual void RemoveStatusTrayIcon() OVERRIDE { have_status_tray_ = false; } | 48 virtual void RemoveStatusTrayIcon() OVERRIDE { have_status_tray_ = false; } |
| 47 virtual int GetBackgroundAppCount() const OVERRIDE { return app_count_; } | 49 virtual int GetBackgroundAppCount() const OVERRIDE { return app_count_; } |
| 48 virtual int GetBackgroundAppCountForProfile( | 50 virtual int GetBackgroundAppCountForProfile( |
| 49 Profile* const profile) const OVERRIDE { | 51 Profile* const profile) const OVERRIDE { |
| 50 return profile_app_count_; | 52 return profile_app_count_; |
| 51 } | 53 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 77 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 79 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
| 78 } | 80 } |
| 79 | 81 |
| 80 static void AssertBackgroundModeInactive( | 82 static void AssertBackgroundModeInactive( |
| 81 const TestBackgroundModeManager& manager) { | 83 const TestBackgroundModeManager& manager) { |
| 82 EXPECT_FALSE(chrome::WillKeepAlive()); | 84 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 83 EXPECT_FALSE(manager.HaveStatusTray()); | 85 EXPECT_FALSE(manager.HaveStatusTray()); |
| 84 EXPECT_FALSE(manager.IsLaunchOnStartup()); | 86 EXPECT_FALSE(manager.IsLaunchOnStartup()); |
| 85 } | 87 } |
| 86 | 88 |
| 89 static void AssertBackgroundModeSuspended( | |
| 90 const TestBackgroundModeManager& manager) { | |
| 91 EXPECT_FALSE(chrome::WillKeepAlive()); | |
| 92 EXPECT_FALSE(manager.HaveStatusTray()); | |
| 93 EXPECT_TRUE(manager.IsLaunchOnStartup()); | |
| 94 } | |
| 95 | |
| 87 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 96 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
| 88 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 97 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
| 89 TestBackgroundModeManager manager( | 98 TestBackgroundModeManager manager( |
| 90 command_line_.get(), profile_manager_.profile_info_cache(), true); | 99 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 91 manager.RegisterProfile(profile); | 100 manager.RegisterProfile(profile); |
| 92 EXPECT_FALSE(chrome::WillKeepAlive()); | 101 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 93 | 102 |
| 94 // Mimic app load. | 103 // Mimic app load. |
| 95 manager.OnBackgroundAppInstalled(NULL); | 104 manager.OnBackgroundAppInstalled(NULL); |
| 96 manager.SetBackgroundAppCount(1); | 105 manager.SetBackgroundAppCount(1); |
| 97 manager.OnApplicationListChanged(profile); | 106 manager.OnApplicationListChanged(profile); |
| 98 AssertBackgroundModeActive(manager); | 107 AssertBackgroundModeActive(manager); |
| 99 | 108 |
| 109 manager.SuspendBackgroundMode(); | |
| 110 AssertBackgroundModeSuspended(manager); | |
| 111 manager.ResumeBackgroundMode(); | |
| 112 | |
| 100 // Mimic app unload. | 113 // Mimic app unload. |
| 101 manager.SetBackgroundAppCount(0); | 114 manager.SetBackgroundAppCount(0); |
| 102 manager.OnApplicationListChanged(profile); | 115 manager.OnApplicationListChanged(profile); |
| 103 AssertBackgroundModeInactive(manager); | 116 AssertBackgroundModeInactive(manager); |
| 117 | |
| 118 manager.SuspendBackgroundMode(); | |
| 119 AssertBackgroundModeInactive(manager); | |
| 120 | |
| 121 // Mimic app load while suspended. | |
| 122 manager.OnBackgroundAppInstalled(NULL); | |
| 123 manager.SetBackgroundAppCount(1); | |
|
Andrew T Wilson (Slow)
2013/10/23 10:00:21
How would an app get installed in this profile whi
Sam McNally
2013/10/24 02:01:37
Yes, sync is still running. I suspect newly added
| |
| 124 manager.OnApplicationListChanged(profile); | |
| 125 AssertBackgroundModeSuspended(manager); | |
| 126 | |
| 104 } | 127 } |
| 105 | 128 |
| 106 // App installs while background mode is disabled should do nothing. | 129 // App installs while background mode is disabled should do nothing. |
| 107 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { | 130 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { |
| 108 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 131 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
| 109 TestBackgroundModeManager manager( | 132 TestBackgroundModeManager manager( |
| 110 command_line_.get(), profile_manager_.profile_info_cache(), true); | 133 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 111 manager.RegisterProfile(profile); | 134 manager.RegisterProfile(profile); |
| 112 // Turn off background mode. | 135 // Turn off background mode. |
| 113 manager.SetEnabled(false); | 136 manager.SetEnabled(false); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 326 |
| 304 TEST_F(BackgroundModeManagerTest, | 327 TEST_F(BackgroundModeManagerTest, |
| 305 BackgroundModeDisabledPreventsKeepAliveOnStartup) { | 328 BackgroundModeDisabledPreventsKeepAliveOnStartup) { |
| 306 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 329 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
| 307 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 330 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
| 308 TestBackgroundModeManager manager( | 331 TestBackgroundModeManager manager( |
| 309 command_line_.get(), profile_manager_.profile_info_cache(), false); | 332 command_line_.get(), profile_manager_.profile_info_cache(), false); |
| 310 manager.RegisterProfile(profile1); | 333 manager.RegisterProfile(profile1); |
| 311 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); | 334 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); |
| 312 } | 335 } |
| OLD | NEW |