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/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
10 #include "chrome/browser/ui/browser_list.h" | |
11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 #include "ui/gfx/image/image_unittest_util.h" | 17 #include "ui/gfx/image/image_unittest_util.h" |
18 | 18 |
19 class BackgroundModeManagerTest : public testing::Test { | 19 class BackgroundModeManagerTest : public testing::Test { |
20 public: | 20 public: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 int app_count_; | 63 int app_count_; |
64 int profile_app_count_; | 64 int profile_app_count_; |
65 | 65 |
66 // Flags to track whether we are launching on startup/have a status tray. | 66 // Flags to track whether we are launching on startup/have a status tray. |
67 bool have_status_tray_; | 67 bool have_status_tray_; |
68 bool launch_on_startup_; | 68 bool launch_on_startup_; |
69 }; | 69 }; |
70 | 70 |
71 static void AssertBackgroundModeActive( | 71 static void AssertBackgroundModeActive( |
72 const TestBackgroundModeManager& manager) { | 72 const TestBackgroundModeManager& manager) { |
73 EXPECT_TRUE(BrowserList::WillKeepAlive()); | 73 EXPECT_TRUE(browser::WillKeepAlive()); |
74 EXPECT_TRUE(manager.HaveStatusTray()); | 74 EXPECT_TRUE(manager.HaveStatusTray()); |
75 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 75 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
76 } | 76 } |
77 | 77 |
78 static void AssertBackgroundModeInactive( | 78 static void AssertBackgroundModeInactive( |
79 const TestBackgroundModeManager& manager) { | 79 const TestBackgroundModeManager& manager) { |
80 EXPECT_FALSE(BrowserList::WillKeepAlive()); | 80 EXPECT_FALSE(browser::WillKeepAlive()); |
81 EXPECT_FALSE(manager.HaveStatusTray()); | 81 EXPECT_FALSE(manager.HaveStatusTray()); |
82 EXPECT_FALSE(manager.IsLaunchOnStartup()); | 82 EXPECT_FALSE(manager.IsLaunchOnStartup()); |
83 } | 83 } |
84 | 84 |
85 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 85 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
86 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 86 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
87 TestBackgroundModeManager manager( | 87 TestBackgroundModeManager manager( |
88 command_line_.get(), profile_manager_.profile_info_cache()); | 88 command_line_.get(), profile_manager_.profile_info_cache()); |
89 manager.RegisterProfile(profile); | 89 manager.RegisterProfile(profile); |
90 EXPECT_FALSE(BrowserList::WillKeepAlive()); | 90 EXPECT_FALSE(browser::WillKeepAlive()); |
91 | 91 |
92 // Mimic app load. | 92 // Mimic app load. |
93 manager.OnBackgroundAppInstalled(NULL); | 93 manager.OnBackgroundAppInstalled(NULL); |
94 manager.SetBackgroundAppCount(1); | 94 manager.SetBackgroundAppCount(1); |
95 manager.OnApplicationListChanged(profile); | 95 manager.OnApplicationListChanged(profile); |
96 AssertBackgroundModeActive(manager); | 96 AssertBackgroundModeActive(manager); |
97 | 97 |
98 // Mimic app unload. | 98 // Mimic app unload. |
99 manager.SetBackgroundAppCount(0); | 99 manager.SetBackgroundAppCount(0); |
100 manager.OnApplicationListChanged(profile); | 100 manager.OnApplicationListChanged(profile); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 AssertBackgroundModeInactive(manager); | 164 AssertBackgroundModeInactive(manager); |
165 } | 165 } |
166 | 166 |
167 TEST_F(BackgroundModeManagerTest, MultiProfile) { | 167 TEST_F(BackgroundModeManagerTest, MultiProfile) { |
168 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 168 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
169 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); | 169 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); |
170 TestBackgroundModeManager manager( | 170 TestBackgroundModeManager manager( |
171 command_line_.get(), profile_manager_.profile_info_cache()); | 171 command_line_.get(), profile_manager_.profile_info_cache()); |
172 manager.RegisterProfile(profile1); | 172 manager.RegisterProfile(profile1); |
173 manager.RegisterProfile(profile2); | 173 manager.RegisterProfile(profile2); |
174 EXPECT_FALSE(BrowserList::WillKeepAlive()); | 174 EXPECT_FALSE(browser::WillKeepAlive()); |
175 | 175 |
176 // Install app, should show status tray icon. | 176 // Install app, should show status tray icon. |
177 manager.OnBackgroundAppInstalled(NULL); | 177 manager.OnBackgroundAppInstalled(NULL); |
178 manager.SetBackgroundAppCount(1); | 178 manager.SetBackgroundAppCount(1); |
179 manager.OnApplicationListChanged(profile1); | 179 manager.OnApplicationListChanged(profile1); |
180 AssertBackgroundModeActive(manager); | 180 AssertBackgroundModeActive(manager); |
181 | 181 |
182 // Install app for other profile, hsould show other status tray icon. | 182 // Install app for other profile, hsould show other status tray icon. |
183 manager.OnBackgroundAppInstalled(NULL); | 183 manager.OnBackgroundAppInstalled(NULL); |
184 manager.SetBackgroundAppCount(2); | 184 manager.SetBackgroundAppCount(2); |
(...skipping 20 matching lines...) Expand all Loading... |
205 AssertBackgroundModeInactive(manager); | 205 AssertBackgroundModeInactive(manager); |
206 } | 206 } |
207 | 207 |
208 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { | 208 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { |
209 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 209 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
210 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); | 210 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); |
211 TestBackgroundModeManager manager( | 211 TestBackgroundModeManager manager( |
212 command_line_.get(), profile_manager_.profile_info_cache()); | 212 command_line_.get(), profile_manager_.profile_info_cache()); |
213 manager.RegisterProfile(profile1); | 213 manager.RegisterProfile(profile1); |
214 manager.RegisterProfile(profile2); | 214 manager.RegisterProfile(profile2); |
215 EXPECT_FALSE(BrowserList::WillKeepAlive()); | 215 EXPECT_FALSE(browser::WillKeepAlive()); |
216 | 216 |
217 ProfileInfoCache* cache = profile_manager_.profile_info_cache(); | 217 ProfileInfoCache* cache = profile_manager_.profile_info_cache(); |
218 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 218 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
219 | 219 |
220 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); | 220 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); |
221 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); | 221 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); |
222 | 222 |
223 // Install app, should show status tray icon. | 223 // Install app, should show status tray icon. |
224 manager.OnBackgroundAppInstalled(NULL); | 224 manager.OnBackgroundAppInstalled(NULL); |
225 manager.SetBackgroundAppCount(1); | 225 manager.SetBackgroundAppCount(1); |
(...skipping 23 matching lines...) Expand all Loading... |
249 | 249 |
250 // Even though neither has background status on, there should still be two | 250 // Even though neither has background status on, there should still be two |
251 // profiles in the cache. | 251 // profiles in the cache. |
252 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 252 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
253 } | 253 } |
254 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { | 254 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
255 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 255 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
256 TestBackgroundModeManager manager( | 256 TestBackgroundModeManager manager( |
257 command_line_.get(), profile_manager_.profile_info_cache()); | 257 command_line_.get(), profile_manager_.profile_info_cache()); |
258 manager.RegisterProfile(profile1); | 258 manager.RegisterProfile(profile1); |
259 EXPECT_FALSE(BrowserList::WillKeepAlive()); | 259 EXPECT_FALSE(browser::WillKeepAlive()); |
260 | 260 |
261 // Install app, should show status tray icon. | 261 // Install app, should show status tray icon. |
262 manager.OnBackgroundAppInstalled(NULL); | 262 manager.OnBackgroundAppInstalled(NULL); |
263 manager.SetBackgroundAppCount(1); | 263 manager.SetBackgroundAppCount(1); |
264 manager.SetBackgroundAppCountForProfile(1); | 264 manager.SetBackgroundAppCountForProfile(1); |
265 manager.OnApplicationListChanged(profile1); | 265 manager.OnApplicationListChanged(profile1); |
266 | 266 |
267 manager.OnProfileNameChanged( | 267 manager.OnProfileNameChanged( |
268 profile1->GetPath(), | 268 profile1->GetPath(), |
269 manager.GetBackgroundModeData(profile1)->name()); | 269 manager.GetBackgroundModeData(profile1)->name()); |
270 | 270 |
271 EXPECT_EQ(UTF8ToUTF16("p1"), | 271 EXPECT_EQ(UTF8ToUTF16("p1"), |
272 manager.GetBackgroundModeData(profile1)->name()); | 272 manager.GetBackgroundModeData(profile1)->name()); |
273 | 273 |
274 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); | 274 TestingProfile* profile2 = profile_manager_.CreateTestingProfile("p2"); |
275 manager.RegisterProfile(profile2); | 275 manager.RegisterProfile(profile2); |
276 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); | 276 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
277 | 277 |
278 manager.OnProfileAdded(profile2->GetPath()); | 278 manager.OnProfileAdded(profile2->GetPath()); |
279 EXPECT_EQ(UTF8ToUTF16("p2"), | 279 EXPECT_EQ(UTF8ToUTF16("p2"), |
280 manager.GetBackgroundModeData(profile2)->name()); | 280 manager.GetBackgroundModeData(profile2)->name()); |
281 | 281 |
282 manager.OnProfileWillBeRemoved(profile2->GetPath()); | 282 manager.OnProfileWillBeRemoved(profile2->GetPath()); |
283 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); | 283 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
284 | 284 |
285 // Check that the background mode data we think is in the map actually is. | 285 // Check that the background mode data we think is in the map actually is. |
286 EXPECT_EQ(UTF8ToUTF16("p1"), | 286 EXPECT_EQ(UTF8ToUTF16("p1"), |
287 manager.GetBackgroundModeData(profile1)->name()); | 287 manager.GetBackgroundModeData(profile1)->name()); |
288 } | 288 } |
OLD | NEW |