| 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/utf_string_conversions.h" | 7 #include "base/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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 int app_count_; | 65 int app_count_; |
| 66 int profile_app_count_; | 66 int profile_app_count_; |
| 67 | 67 |
| 68 // Flags to track whether we are launching on startup/have a status tray. | 68 // Flags to track whether we are launching on startup/have a status tray. |
| 69 bool have_status_tray_; | 69 bool have_status_tray_; |
| 70 bool launch_on_startup_; | 70 bool launch_on_startup_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 static void AssertBackgroundModeActive( | 73 static void AssertBackgroundModeActive( |
| 74 const TestBackgroundModeManager& manager) { | 74 const TestBackgroundModeManager& manager) { |
| 75 EXPECT_TRUE(browser::WillKeepAlive()); | 75 EXPECT_TRUE(chrome::WillKeepAlive()); |
| 76 EXPECT_TRUE(manager.HaveStatusTray()); | 76 EXPECT_TRUE(manager.HaveStatusTray()); |
| 77 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 77 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static void AssertBackgroundModeInactive( | 80 static void AssertBackgroundModeInactive( |
| 81 const TestBackgroundModeManager& manager) { | 81 const TestBackgroundModeManager& manager) { |
| 82 EXPECT_FALSE(browser::WillKeepAlive()); | 82 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 83 EXPECT_FALSE(manager.HaveStatusTray()); | 83 EXPECT_FALSE(manager.HaveStatusTray()); |
| 84 EXPECT_FALSE(manager.IsLaunchOnStartup()); | 84 EXPECT_FALSE(manager.IsLaunchOnStartup()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 87 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
| 88 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 88 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
| 89 TestBackgroundModeManager manager( | 89 TestBackgroundModeManager manager( |
| 90 command_line_.get(), profile_manager_.profile_info_cache(), true); | 90 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 91 manager.RegisterProfile(profile); | 91 manager.RegisterProfile(profile); |
| 92 EXPECT_FALSE(browser::WillKeepAlive()); | 92 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 93 | 93 |
| 94 // Mimic app load. | 94 // Mimic app load. |
| 95 manager.OnBackgroundAppInstalled(NULL); | 95 manager.OnBackgroundAppInstalled(NULL); |
| 96 manager.SetBackgroundAppCount(1); | 96 manager.SetBackgroundAppCount(1); |
| 97 manager.OnApplicationListChanged(profile); | 97 manager.OnApplicationListChanged(profile); |
| 98 AssertBackgroundModeActive(manager); | 98 AssertBackgroundModeActive(manager); |
| 99 | 99 |
| 100 // Mimic app unload. | 100 // Mimic app unload. |
| 101 manager.SetBackgroundAppCount(0); | 101 manager.SetBackgroundAppCount(0); |
| 102 manager.OnApplicationListChanged(profile); | 102 manager.OnApplicationListChanged(profile); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 AssertBackgroundModeInactive(manager); | 166 AssertBackgroundModeInactive(manager); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(BackgroundModeManagerTest, MultiProfile) { | 169 TEST_F(BackgroundModeManagerTest, MultiProfile) { |
| 170 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 170 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
| 171 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); | 171 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); |
| 172 TestBackgroundModeManager manager( | 172 TestBackgroundModeManager manager( |
| 173 command_line_.get(), profile_manager_.profile_info_cache(), true); | 173 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 174 manager.RegisterProfile(profile1); | 174 manager.RegisterProfile(profile1); |
| 175 manager.RegisterProfile(profile2); | 175 manager.RegisterProfile(profile2); |
| 176 EXPECT_FALSE(browser::WillKeepAlive()); | 176 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 177 | 177 |
| 178 // Install app, should show status tray icon. | 178 // Install app, should show status tray icon. |
| 179 manager.OnBackgroundAppInstalled(NULL); | 179 manager.OnBackgroundAppInstalled(NULL); |
| 180 manager.SetBackgroundAppCount(1); | 180 manager.SetBackgroundAppCount(1); |
| 181 manager.OnApplicationListChanged(profile1); | 181 manager.OnApplicationListChanged(profile1); |
| 182 AssertBackgroundModeActive(manager); | 182 AssertBackgroundModeActive(manager); |
| 183 | 183 |
| 184 // Install app for other profile, hsould show other status tray icon. | 184 // Install app for other profile, hsould show other status tray icon. |
| 185 manager.OnBackgroundAppInstalled(NULL); | 185 manager.OnBackgroundAppInstalled(NULL); |
| 186 manager.SetBackgroundAppCount(2); | 186 manager.SetBackgroundAppCount(2); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 207 AssertBackgroundModeInactive(manager); | 207 AssertBackgroundModeInactive(manager); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { | 210 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { |
| 211 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 211 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
| 212 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); | 212 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); |
| 213 TestBackgroundModeManager manager( | 213 TestBackgroundModeManager manager( |
| 214 command_line_.get(), profile_manager_.profile_info_cache(), true); | 214 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 215 manager.RegisterProfile(profile1); | 215 manager.RegisterProfile(profile1); |
| 216 manager.RegisterProfile(profile2); | 216 manager.RegisterProfile(profile2); |
| 217 EXPECT_FALSE(browser::WillKeepAlive()); | 217 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 218 | 218 |
| 219 ProfileInfoCache* cache = profile_manager_.profile_info_cache(); | 219 ProfileInfoCache* cache = profile_manager_.profile_info_cache(); |
| 220 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 220 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
| 221 | 221 |
| 222 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); | 222 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); |
| 223 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); | 223 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); |
| 224 | 224 |
| 225 // Install app, should show status tray icon. | 225 // Install app, should show status tray icon. |
| 226 manager.OnBackgroundAppInstalled(NULL); | 226 manager.OnBackgroundAppInstalled(NULL); |
| 227 manager.SetBackgroundAppCount(1); | 227 manager.SetBackgroundAppCount(1); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 252 // Even though neither has background status on, there should still be two | 252 // Even though neither has background status on, there should still be two |
| 253 // profiles in the cache. | 253 // profiles in the cache. |
| 254 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 254 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { | 257 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
| 258 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 258 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
| 259 TestBackgroundModeManager manager( | 259 TestBackgroundModeManager manager( |
| 260 command_line_.get(), profile_manager_.profile_info_cache(), true); | 260 command_line_.get(), profile_manager_.profile_info_cache(), true); |
| 261 manager.RegisterProfile(profile1); | 261 manager.RegisterProfile(profile1); |
| 262 EXPECT_FALSE(browser::WillKeepAlive()); | 262 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 263 | 263 |
| 264 // Install app, should show status tray icon. | 264 // Install app, should show status tray icon. |
| 265 manager.OnBackgroundAppInstalled(NULL); | 265 manager.OnBackgroundAppInstalled(NULL); |
| 266 manager.SetBackgroundAppCount(1); | 266 manager.SetBackgroundAppCount(1); |
| 267 manager.SetBackgroundAppCountForProfile(1); | 267 manager.SetBackgroundAppCountForProfile(1); |
| 268 manager.OnApplicationListChanged(profile1); | 268 manager.OnApplicationListChanged(profile1); |
| 269 | 269 |
| 270 manager.OnProfileNameChanged( | 270 manager.OnProfileNameChanged( |
| 271 profile1->GetPath(), | 271 profile1->GetPath(), |
| 272 manager.GetBackgroundModeData(profile1)->name()); | 272 manager.GetBackgroundModeData(profile1)->name()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 303 | 303 |
| 304 TEST_F(BackgroundModeManagerTest, | 304 TEST_F(BackgroundModeManagerTest, |
| 305 BackgroundModeDisabledPreventsKeepAliveOnStartup) { | 305 BackgroundModeDisabledPreventsKeepAliveOnStartup) { |
| 306 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 306 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
| 307 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 307 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
| 308 TestBackgroundModeManager manager( | 308 TestBackgroundModeManager manager( |
| 309 command_line_.get(), profile_manager_.profile_info_cache(), false); | 309 command_line_.get(), profile_manager_.profile_info_cache(), false); |
| 310 manager.RegisterProfile(profile1); | 310 manager.RegisterProfile(profile1); |
| 311 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); | 311 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); |
| 312 } | 312 } |
| OLD | NEW |