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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "chrome/browser/background/background_mode_manager.h" | 12 #include "chrome/browser/background/background_mode_manager.h" |
13 #include "chrome/browser/background/background_trigger.h" | 13 #include "chrome/browser/background/background_trigger.h" |
14 #include "chrome/browser/browser_shutdown.h" | 14 #include "chrome/browser/browser_shutdown.h" |
15 #include "chrome/browser/extensions/extension_function_test_utils.h" | 15 #include "chrome/browser/extensions/extension_function_test_utils.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
18 #include "chrome/browser/lifetime/application_lifetime.h" | 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 19 #include "chrome/browser/lifetime/browser_keep_alive.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 20 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/status_icons/status_icon_menu_model.h" | 21 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
25 #include "chrome/test/base/testing_profile_manager.h" | 26 #include "chrome/test/base/testing_profile_manager.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "extensions/browser/api_test_utils.h" | 28 #include "extensions/browser/api_test_utils.h" |
28 #include "extensions/browser/extension_prefs.h" | 29 #include "extensions/browser/extension_prefs.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void DisplayBalloon(const gfx::ImageSkia& icon, | 124 void DisplayBalloon(const gfx::ImageSkia& icon, |
124 const base::string16& title, | 125 const base::string16& title, |
125 const base::string16& contents) override {} | 126 const base::string16& contents) override {} |
126 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} | 127 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
127 | 128 |
128 private: | 129 private: |
129 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); | 130 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); |
130 }; | 131 }; |
131 | 132 |
132 void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { | 133 void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { |
133 EXPECT_TRUE(chrome::WillKeepAlive()); | 134 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
134 EXPECT_TRUE(manager.HaveStatusTray()); | 135 EXPECT_TRUE(manager.HaveStatusTray()); |
135 } | 136 } |
136 | 137 |
137 void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { | 138 void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { |
138 EXPECT_FALSE(chrome::WillKeepAlive()); | 139 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
139 EXPECT_FALSE(manager.HaveStatusTray()); | 140 EXPECT_FALSE(manager.HaveStatusTray()); |
140 } | 141 } |
141 | 142 |
142 } // namespace | 143 } // namespace |
143 | 144 |
144 // More complex test helper that exposes APIs for fine grained control of | 145 // More complex test helper that exposes APIs for fine grained control of |
145 // things like the number of background applications. This allows writing | 146 // things like the number of background applications. This allows writing |
146 // smaller tests that don't have to install/uninstall extensions. | 147 // smaller tests that don't have to install/uninstall extensions. |
147 class AdvancedTestBackgroundModeManager : public TestBackgroundModeManager { | 148 class AdvancedTestBackgroundModeManager : public TestBackgroundModeManager { |
148 public: | 149 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 185 |
185 class BackgroundModeManagerTest : public testing::Test { | 186 class BackgroundModeManagerTest : public testing::Test { |
186 public: | 187 public: |
187 BackgroundModeManagerTest() {} | 188 BackgroundModeManagerTest() {} |
188 ~BackgroundModeManagerTest() override {} | 189 ~BackgroundModeManagerTest() override {} |
189 | 190 |
190 void SetUp() override { | 191 void SetUp() override { |
191 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); | 192 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
192 profile_manager_ = CreateTestingProfileManager(); | 193 profile_manager_ = CreateTestingProfileManager(); |
193 profile_ = profile_manager_->CreateTestingProfile("p1"); | 194 profile_ = profile_manager_->CreateTestingProfile("p1"); |
194 chrome::DisableShutdownForTesting(true); | 195 browser_lifetime::DisableShutdownForTesting(true); |
195 } | 196 } |
196 | 197 |
197 void TearDown() override { | 198 void TearDown() override { |
198 // Don't allow the browser to be closed because the shutdown procedure will | 199 // Don't allow the browser to be closed because the shutdown procedure will |
199 // attempt to access objects that we haven't created (e.g., MessageCenter). | 200 // attempt to access objects that we haven't created (e.g., MessageCenter). |
200 browser_shutdown::SetTryingToQuit(true); | 201 browser_shutdown::SetTryingToQuit(true); |
201 chrome::DisableShutdownForTesting(false); | 202 browser_lifetime::DisableShutdownForTesting(false); |
202 browser_shutdown::SetTryingToQuit(false); | 203 browser_shutdown::SetTryingToQuit(false); |
203 } | 204 } |
204 | 205 |
205 protected: | 206 protected: |
206 content::TestBrowserThreadBundle thread_bundle_; | 207 content::TestBrowserThreadBundle thread_bundle_; |
207 scoped_ptr<base::CommandLine> command_line_; | 208 scoped_ptr<base::CommandLine> command_line_; |
208 | 209 |
209 scoped_ptr<TestingProfileManager> profile_manager_; | 210 scoped_ptr<TestingProfileManager> profile_manager_; |
210 // Test profile used by all tests - this is owned by profile_manager_. | 211 // Test profile used by all tests - this is owned by profile_manager_. |
211 TestingProfile* profile_; | 212 TestingProfile* profile_; |
(...skipping 12 matching lines...) Expand all Loading... |
224 profile_manager_ = CreateTestingProfileManager(); | 225 profile_manager_ = CreateTestingProfileManager(); |
225 profile_ = profile_manager_->CreateTestingProfile("p1"); | 226 profile_ = profile_manager_->CreateTestingProfile("p1"); |
226 | 227 |
227 // Aura clears notifications from the message center at shutdown. | 228 // Aura clears notifications from the message center at shutdown. |
228 message_center::MessageCenter::Initialize(); | 229 message_center::MessageCenter::Initialize(); |
229 | 230 |
230 // BackgroundModeManager actually affects Chrome start/stop state, | 231 // BackgroundModeManager actually affects Chrome start/stop state, |
231 // tearing down our thread bundle before we've had chance to clean | 232 // tearing down our thread bundle before we've had chance to clean |
232 // everything up. Keeping Chrome alive prevents this. | 233 // everything up. Keeping Chrome alive prevents this. |
233 // We aren't interested in if the keep alive works correctly in this test. | 234 // We aren't interested in if the keep alive works correctly in this test. |
234 chrome::IncrementKeepAliveCount(); | 235 keep_alive_.reset(new browser_lifetime::ScopedKeepAlive); |
235 | 236 |
236 #if defined(OS_CHROMEOS) | 237 #if defined(OS_CHROMEOS) |
237 // On ChromeOS shutdown, HandleAppExitingForPlatform will call | 238 // On ChromeOS shutdown, HandleAppExitingForPlatform() will call |
238 // chrome::DecrementKeepAliveCount because it assumes the aura shell | 239 // browser_lifetime::DecrementKeepAliveCount() because it assumes the aura |
239 // called chrome::IncrementKeepAliveCount. Simulate the call here. | 240 // shell called browser_lifetime::IncrementKeepAliveCount(). Simulate the |
240 chrome::IncrementKeepAliveCount(); | 241 // call here. |
| 242 browser_lifetime::IncrementKeepAliveCount(); |
241 #endif | 243 #endif |
242 | 244 |
243 // Create our test BackgroundModeManager. | 245 // Create our test BackgroundModeManager. |
244 manager_.reset(new TestBackgroundModeManager( | 246 manager_.reset(new TestBackgroundModeManager( |
245 *command_line_, profile_manager_->profile_info_cache())); | 247 *command_line_, profile_manager_->profile_info_cache())); |
246 manager_->RegisterProfile(profile_); | 248 manager_->RegisterProfile(profile_); |
247 } | 249 } |
248 | 250 |
249 void TearDown() override { | 251 void TearDown() override { |
250 // Clean up the status icon. If this is not done before profile deletes, | 252 // Clean up the status icon. If this is not done before profile deletes, |
251 // the context menu updates will DCHECK with the now deleted profiles. | 253 // the context menu updates will DCHECK with the now deleted profiles. |
252 StatusIcon* status_icon = manager_->status_icon_; | 254 StatusIcon* status_icon = manager_->status_icon_; |
253 manager_->status_icon_ = NULL; | 255 manager_->status_icon_ = NULL; |
254 delete status_icon; | 256 delete status_icon; |
255 | 257 |
256 // We have to destroy the profiles now because we created them with real | 258 // We have to destroy the profiles now because we created them with real |
257 // thread state. This causes a lot of machinery to spin up that stops | 259 // thread state. This causes a lot of machinery to spin up that stops |
258 // working when we tear down our thread state at the end of the test. | 260 // working when we tear down our thread state at the end of the test. |
259 // Deleting our testing profile may have the side-effect of disabling | 261 // Deleting our testing profile may have the side-effect of disabling |
260 // background mode if it was enabled for that profile (explicitly note that | 262 // background mode if it was enabled for that profile (explicitly note that |
261 // here to satisfy StrictMock requirements. | 263 // here to satisfy StrictMock requirements. |
262 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1)); | 264 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1)); |
263 profile_manager_->DeleteAllTestingProfiles(); | 265 profile_manager_->DeleteAllTestingProfiles(); |
264 Mock::VerifyAndClearExpectations(manager_.get()); | 266 Mock::VerifyAndClearExpectations(manager_.get()); |
265 | 267 |
266 // We're getting ready to shutdown the message loop. Clear everything out! | 268 // We're getting ready to shutdown the message loop. Clear everything out! |
267 base::MessageLoop::current()->RunUntilIdle(); | 269 base::MessageLoop::current()->RunUntilIdle(); |
268 // Matching the call to IncrementKeepAliveCount in SetUp(). | 270 // Matching the keep_alive_.reset(...) in SetUp(). |
269 chrome::DecrementKeepAliveCount(); | 271 keep_alive_.reset(); |
270 | 272 |
271 // TestBackgroundModeManager has dependencies on the infrastructure. | 273 // TestBackgroundModeManager has dependencies on the infrastructure. |
272 // It should get cleared first. | 274 // It should get cleared first. |
273 manager_.reset(); | 275 manager_.reset(); |
274 | 276 |
275 // The Profile Manager references the Browser Process. | 277 // The Profile Manager references the Browser Process. |
276 // The Browser Process references the Notification UI Manager. | 278 // The Browser Process references the Notification UI Manager. |
277 // The Notification UI Manager references the Message Center. | 279 // The Notification UI Manager references the Message Center. |
278 // As a result, we have to clear the browser process state here | 280 // As a result, we have to clear the browser process state here |
279 // before tearing down the Message Center. | 281 // before tearing down the Message Center. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // Required for extension service. | 336 // Required for extension service. |
335 content::TestBrowserThreadBundle thread_bundle_; | 337 content::TestBrowserThreadBundle thread_bundle_; |
336 | 338 |
337 #if defined(OS_CHROMEOS) | 339 #if defined(OS_CHROMEOS) |
338 // ChromeOS needs extra services to run in the following order. | 340 // ChromeOS needs extra services to run in the following order. |
339 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 341 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
340 chromeos::ScopedTestCrosSettings test_cros_settings_; | 342 chromeos::ScopedTestCrosSettings test_cros_settings_; |
341 chromeos::ScopedTestUserManager test_user_manager_; | 343 chromeos::ScopedTestUserManager test_user_manager_; |
342 #endif | 344 #endif |
343 | 345 |
| 346 scoped_ptr<browser_lifetime::ScopedKeepAlive> keep_alive_; |
| 347 |
344 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); | 348 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); |
345 }; | 349 }; |
346 | 350 |
347 | 351 |
348 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 352 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
349 AdvancedTestBackgroundModeManager manager( | 353 AdvancedTestBackgroundModeManager manager( |
350 *command_line_, profile_manager_->profile_info_cache(), true); | 354 *command_line_, profile_manager_->profile_info_cache(), true); |
351 manager.RegisterProfile(profile_); | 355 manager.RegisterProfile(profile_); |
352 EXPECT_FALSE(chrome::WillKeepAlive()); | 356 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
353 | 357 |
354 // Mimic app load. | 358 // Mimic app load. |
355 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 359 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
356 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 360 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
357 manager.SetBackgroundClientCountForProfile(profile_, 1); | 361 manager.SetBackgroundClientCountForProfile(profile_, 1); |
358 manager.OnApplicationListChanged(profile_); | 362 manager.OnApplicationListChanged(profile_); |
359 Mock::VerifyAndClearExpectations(&manager); | 363 Mock::VerifyAndClearExpectations(&manager); |
360 AssertBackgroundModeActive(manager); | 364 AssertBackgroundModeActive(manager); |
361 | 365 |
362 manager.SuspendBackgroundMode(); | 366 manager.SuspendBackgroundMode(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 Mock::VerifyAndClearExpectations(&manager); | 479 Mock::VerifyAndClearExpectations(&manager); |
476 AssertBackgroundModeInactive(manager); | 480 AssertBackgroundModeInactive(manager); |
477 } | 481 } |
478 | 482 |
479 TEST_F(BackgroundModeManagerTest, MultiProfile) { | 483 TEST_F(BackgroundModeManagerTest, MultiProfile) { |
480 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 484 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
481 AdvancedTestBackgroundModeManager manager( | 485 AdvancedTestBackgroundModeManager manager( |
482 *command_line_, profile_manager_->profile_info_cache(), true); | 486 *command_line_, profile_manager_->profile_info_cache(), true); |
483 manager.RegisterProfile(profile_); | 487 manager.RegisterProfile(profile_); |
484 manager.RegisterProfile(profile2); | 488 manager.RegisterProfile(profile2); |
485 EXPECT_FALSE(chrome::WillKeepAlive()); | 489 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
486 | 490 |
487 // Install app, should show status tray icon. | 491 // Install app, should show status tray icon. |
488 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 492 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
489 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 493 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
490 manager.SetBackgroundClientCountForProfile(profile_, 1); | 494 manager.SetBackgroundClientCountForProfile(profile_, 1); |
491 manager.OnApplicationListChanged(profile_); | 495 manager.OnApplicationListChanged(profile_); |
492 Mock::VerifyAndClearExpectations(&manager); | 496 Mock::VerifyAndClearExpectations(&manager); |
493 AssertBackgroundModeActive(manager); | 497 AssertBackgroundModeActive(manager); |
494 | 498 |
495 // Install app for other profile, should show other status tray icon. | 499 // Install app for other profile, should show other status tray icon. |
(...skipping 29 matching lines...) Expand all Loading... |
525 Mock::VerifyAndClearExpectations(&manager); | 529 Mock::VerifyAndClearExpectations(&manager); |
526 AssertBackgroundModeInactive(manager); | 530 AssertBackgroundModeInactive(manager); |
527 } | 531 } |
528 | 532 |
529 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { | 533 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { |
530 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 534 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
531 AdvancedTestBackgroundModeManager manager( | 535 AdvancedTestBackgroundModeManager manager( |
532 *command_line_, profile_manager_->profile_info_cache(), true); | 536 *command_line_, profile_manager_->profile_info_cache(), true); |
533 manager.RegisterProfile(profile_); | 537 manager.RegisterProfile(profile_); |
534 manager.RegisterProfile(profile2); | 538 manager.RegisterProfile(profile2); |
535 EXPECT_FALSE(chrome::WillKeepAlive()); | 539 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
536 | 540 |
537 ProfileInfoCache* cache = profile_manager_->profile_info_cache(); | 541 ProfileInfoCache* cache = profile_manager_->profile_info_cache(); |
538 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 542 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
539 | 543 |
540 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); | 544 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); |
541 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); | 545 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); |
542 | 546 |
543 // Install app, should show status tray icon. | 547 // Install app, should show status tray icon. |
544 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 548 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
545 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 549 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
(...skipping 25 matching lines...) Expand all Loading... |
571 | 575 |
572 // Even though neither has background status on, there should still be two | 576 // Even though neither has background status on, there should still be two |
573 // profiles in the cache. | 577 // profiles in the cache. |
574 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 578 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
575 } | 579 } |
576 | 580 |
577 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { | 581 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
578 AdvancedTestBackgroundModeManager manager( | 582 AdvancedTestBackgroundModeManager manager( |
579 *command_line_, profile_manager_->profile_info_cache(), true); | 583 *command_line_, profile_manager_->profile_info_cache(), true); |
580 manager.RegisterProfile(profile_); | 584 manager.RegisterProfile(profile_); |
581 EXPECT_FALSE(chrome::WillKeepAlive()); | 585 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
582 | 586 |
583 // Install app, should show status tray icon. | 587 // Install app, should show status tray icon. |
584 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 588 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
585 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 589 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
586 manager.SetBackgroundClientCountForProfile(profile_, 1); | 590 manager.SetBackgroundClientCountForProfile(profile_, 1); |
587 manager.OnApplicationListChanged(profile_); | 591 manager.OnApplicationListChanged(profile_); |
588 Mock::VerifyAndClearExpectations(&manager); | 592 Mock::VerifyAndClearExpectations(&manager); |
589 | 593 |
590 // Background mode should remain active for the remainder of this test. | 594 // Background mode should remain active for the remainder of this test. |
591 | 595 |
592 manager.OnProfileNameChanged( | 596 manager.OnProfileNameChanged( |
593 profile_->GetPath(), | 597 profile_->GetPath(), |
594 manager.GetBackgroundModeData(profile_)->name()); | 598 manager.GetBackgroundModeData(profile_)->name()); |
595 | 599 |
596 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 600 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
597 manager.GetBackgroundModeData(profile_)->name()); | 601 manager.GetBackgroundModeData(profile_)->name()); |
598 | 602 |
599 EXPECT_TRUE(chrome::WillKeepAlive()); | 603 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
600 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 604 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
601 manager.RegisterProfile(profile2); | 605 manager.RegisterProfile(profile2); |
602 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); | 606 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
603 | 607 |
604 manager.OnProfileAdded(profile2->GetPath()); | 608 manager.OnProfileAdded(profile2->GetPath()); |
605 EXPECT_EQ(base::UTF8ToUTF16("p2"), | 609 EXPECT_EQ(base::UTF8ToUTF16("p2"), |
606 manager.GetBackgroundModeData(profile2)->name()); | 610 manager.GetBackgroundModeData(profile2)->name()); |
607 | 611 |
608 manager.OnProfileWillBeRemoved(profile2->GetPath()); | 612 manager.OnProfileWillBeRemoved(profile2->GetPath()); |
609 // Should still be in background mode after deleting profile. | 613 // Should still be in background mode after deleting profile. |
610 EXPECT_TRUE(chrome::WillKeepAlive()); | 614 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
611 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); | 615 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
612 | 616 |
613 // Check that the background mode data we think is in the map actually is. | 617 // Check that the background mode data we think is in the map actually is. |
614 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 618 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
615 manager.GetBackgroundModeData(profile_)->name()); | 619 manager.GetBackgroundModeData(profile_)->name()); |
616 } | 620 } |
617 | 621 |
618 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { | 622 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
619 // Tests whether deleting the only profile when it is a BG profile works | 623 // Tests whether deleting the only profile when it is a BG profile works |
620 // or not (http://crbug.com/346214). | 624 // or not (http://crbug.com/346214). |
621 AdvancedTestBackgroundModeManager manager( | 625 AdvancedTestBackgroundModeManager manager( |
622 *command_line_, profile_manager_->profile_info_cache(), true); | 626 *command_line_, profile_manager_->profile_info_cache(), true); |
623 manager.RegisterProfile(profile_); | 627 manager.RegisterProfile(profile_); |
624 EXPECT_FALSE(chrome::WillKeepAlive()); | 628 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
625 | 629 |
626 // Install app, should show status tray icon. | 630 // Install app, should show status tray icon. |
627 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 631 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
628 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 632 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
629 manager.SetBackgroundClientCountForProfile(profile_, 1); | 633 manager.SetBackgroundClientCountForProfile(profile_, 1); |
630 manager.OnApplicationListChanged(profile_); | 634 manager.OnApplicationListChanged(profile_); |
631 Mock::VerifyAndClearExpectations(&manager); | 635 Mock::VerifyAndClearExpectations(&manager); |
632 | 636 |
633 manager.OnProfileNameChanged( | 637 manager.OnProfileNameChanged( |
634 profile_->GetPath(), | 638 profile_->GetPath(), |
635 manager.GetBackgroundModeData(profile_)->name()); | 639 manager.GetBackgroundModeData(profile_)->name()); |
636 | 640 |
637 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 641 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
638 EXPECT_TRUE(chrome::WillKeepAlive()); | 642 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
639 manager.SetBackgroundClientCountForProfile(profile_, 0); | 643 manager.SetBackgroundClientCountForProfile(profile_, 0); |
640 manager.OnProfileWillBeRemoved(profile_->GetPath()); | 644 manager.OnProfileWillBeRemoved(profile_->GetPath()); |
641 Mock::VerifyAndClearExpectations(&manager); | 645 Mock::VerifyAndClearExpectations(&manager); |
642 EXPECT_FALSE(chrome::WillKeepAlive()); | 646 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
643 } | 647 } |
644 | 648 |
645 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { | 649 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { |
646 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 650 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
647 AdvancedTestBackgroundModeManager manager( | 651 AdvancedTestBackgroundModeManager manager( |
648 *command_line_, profile_manager_->profile_info_cache(), true); | 652 *command_line_, profile_manager_->profile_info_cache(), true); |
649 manager.RegisterProfile(profile_); | 653 manager.RegisterProfile(profile_); |
650 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); | 654 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); |
651 | 655 |
652 // No enable-launch-on-startup calls expected yet. | 656 // No enable-launch-on-startup calls expected yet. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 service2->AddExtension(regular_extension_with_options.get()); | 815 service2->AddExtension(regular_extension_with_options.get()); |
812 | 816 |
813 manager_->RegisterProfile(profile2); | 817 manager_->RegisterProfile(profile2); |
814 | 818 |
815 manager_->status_icon_ = new TestStatusIcon(); | 819 manager_->status_icon_ = new TestStatusIcon(); |
816 manager_->UpdateStatusTrayIconContextMenu(); | 820 manager_->UpdateStatusTrayIconContextMenu(); |
817 StatusIconMenuModel* context_menu = manager_->context_menu_; | 821 StatusIconMenuModel* context_menu = manager_->context_menu_; |
818 EXPECT_TRUE(context_menu != NULL); | 822 EXPECT_TRUE(context_menu != NULL); |
819 | 823 |
820 // Background Profile Enable Checks | 824 // Background Profile Enable Checks |
821 EXPECT_TRUE(context_menu->GetLabelAt(3) == base::UTF8ToUTF16("p1")); | 825 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
| 826 context_menu->GetLabelAt(3)); |
822 EXPECT_TRUE( | 827 EXPECT_TRUE( |
823 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(3))); | 828 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(3))); |
824 EXPECT_TRUE(context_menu->GetCommandIdAt(3) == 4); | 829 EXPECT_EQ(4, context_menu->GetCommandIdAt(3)); |
825 | 830 |
826 EXPECT_TRUE(context_menu->GetLabelAt(4) == base::UTF8ToUTF16("p2")); | 831 EXPECT_EQ(base::UTF8ToUTF16("p2"), context_menu->GetLabelAt(4)); |
827 EXPECT_TRUE( | 832 EXPECT_TRUE( |
828 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(4))); | 833 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(4))); |
829 EXPECT_TRUE(context_menu->GetCommandIdAt(4) == 8); | 834 EXPECT_EQ(8, context_menu->GetCommandIdAt(4)); |
830 | 835 |
831 // Profile 1 Submenu Checks | 836 // Profile 1 Submenu Checks |
832 StatusIconMenuModel* profile1_submenu = | 837 StatusIconMenuModel* profile1_submenu = |
833 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(3)); | 838 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(3)); |
834 EXPECT_TRUE( | 839 EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
835 profile1_submenu->GetLabelAt(0) == | 840 profile1_submenu->GetLabelAt(0)); |
836 base::UTF8ToUTF16("Component Extension")); | |
837 EXPECT_FALSE( | 841 EXPECT_FALSE( |
838 profile1_submenu->IsCommandIdEnabled( | 842 profile1_submenu->IsCommandIdEnabled( |
839 profile1_submenu->GetCommandIdAt(0))); | 843 profile1_submenu->GetCommandIdAt(0))); |
840 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(0) == 0); | 844 EXPECT_EQ(0, profile1_submenu->GetCommandIdAt(0)); |
841 EXPECT_TRUE( | 845 EXPECT_EQ(base::UTF8ToUTF16("Component Extension with Options"), |
842 profile1_submenu->GetLabelAt(1) == | 846 profile1_submenu->GetLabelAt(1)); |
843 base::UTF8ToUTF16("Component Extension with Options")); | |
844 EXPECT_TRUE( | 847 EXPECT_TRUE( |
845 profile1_submenu->IsCommandIdEnabled( | 848 profile1_submenu->IsCommandIdEnabled( |
846 profile1_submenu->GetCommandIdAt(1))); | 849 profile1_submenu->GetCommandIdAt(1))); |
847 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(1) == 1); | 850 EXPECT_EQ(1, profile1_submenu->GetCommandIdAt(1)); |
848 EXPECT_TRUE( | 851 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
849 profile1_submenu->GetLabelAt(2) == | 852 profile1_submenu->GetLabelAt(2)); |
850 base::UTF8ToUTF16("Regular Extension")); | |
851 EXPECT_TRUE( | 853 EXPECT_TRUE( |
852 profile1_submenu->IsCommandIdEnabled( | 854 profile1_submenu->IsCommandIdEnabled( |
853 profile1_submenu->GetCommandIdAt(2))); | 855 profile1_submenu->GetCommandIdAt(2))); |
854 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(2) == 2); | 856 EXPECT_EQ(2, profile1_submenu->GetCommandIdAt(2)); |
855 EXPECT_TRUE( | 857 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
856 profile1_submenu->GetLabelAt(3) == | 858 profile1_submenu->GetLabelAt(3)); |
857 base::UTF8ToUTF16("Regular Extension with Options")); | |
858 EXPECT_TRUE( | 859 EXPECT_TRUE( |
859 profile1_submenu->IsCommandIdEnabled( | 860 profile1_submenu->IsCommandIdEnabled( |
860 profile1_submenu->GetCommandIdAt(3))); | 861 profile1_submenu->GetCommandIdAt(3))); |
861 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(3) == 3); | 862 EXPECT_EQ(3, profile1_submenu->GetCommandIdAt(3)); |
862 | 863 |
863 // Profile 2 Submenu Checks | 864 // Profile 2 Submenu Checks |
864 StatusIconMenuModel* profile2_submenu = | 865 StatusIconMenuModel* profile2_submenu = |
865 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(4)); | 866 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(4)); |
866 EXPECT_TRUE( | 867 EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
867 profile2_submenu->GetLabelAt(0) == | 868 profile2_submenu->GetLabelAt(0)); |
868 base::UTF8ToUTF16("Component Extension")); | |
869 EXPECT_FALSE( | 869 EXPECT_FALSE( |
870 profile2_submenu->IsCommandIdEnabled( | 870 profile2_submenu->IsCommandIdEnabled( |
871 profile2_submenu->GetCommandIdAt(0))); | 871 profile2_submenu->GetCommandIdAt(0))); |
872 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(0) == 5); | 872 EXPECT_EQ(5, profile2_submenu->GetCommandIdAt(0)); |
873 EXPECT_TRUE( | 873 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
874 profile2_submenu->GetLabelAt(1) == | 874 profile2_submenu->GetLabelAt(1)); |
875 base::UTF8ToUTF16("Regular Extension")); | |
876 EXPECT_TRUE( | 875 EXPECT_TRUE( |
877 profile2_submenu->IsCommandIdEnabled( | 876 profile2_submenu->IsCommandIdEnabled( |
878 profile2_submenu->GetCommandIdAt(1))); | 877 profile2_submenu->GetCommandIdAt(1))); |
879 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(1) == 6); | 878 EXPECT_EQ(6, profile2_submenu->GetCommandIdAt(1)); |
880 EXPECT_TRUE( | 879 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
881 profile2_submenu->GetLabelAt(2) == | 880 profile2_submenu->GetLabelAt(2)); |
882 base::UTF8ToUTF16("Regular Extension with Options")); | |
883 EXPECT_TRUE( | 881 EXPECT_TRUE( |
884 profile2_submenu->IsCommandIdEnabled( | 882 profile2_submenu->IsCommandIdEnabled( |
885 profile2_submenu->GetCommandIdAt(2))); | 883 profile2_submenu->GetCommandIdAt(2))); |
886 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(2) == 7); | 884 EXPECT_EQ(7, profile2_submenu->GetCommandIdAt(2)); |
887 | 885 |
888 // Model Adapter Checks for crbug.com/315164 | 886 // Model Adapter Checks for crbug.com/315164 |
889 // P1: Profile 1 Menu Item | 887 // P1: Profile 1 Menu Item |
890 // P2: Profile 2 Menu Item | 888 // P2: Profile 2 Menu Item |
891 // CE: Component Extension Menu Item | 889 // CE: Component Extension Menu Item |
892 // CEO: Component Extenison with Options Menu Item | 890 // CEO: Component Extenison with Options Menu Item |
893 // RE: Regular Extension Menu Item | 891 // RE: Regular Extension Menu Item |
894 // REO: Regular Extension with Options Menu Item | 892 // REO: Regular Extension with Options Menu Item |
895 EXPECT_FALSE(IsCommandEnabled(context_menu, 0)); // P1 - CE | 893 EXPECT_FALSE(IsCommandEnabled(context_menu, 0)); // P1 - CE |
896 EXPECT_TRUE(IsCommandEnabled(context_menu, 1)); // P1 - CEO | 894 EXPECT_TRUE(IsCommandEnabled(context_menu, 1)); // P1 - CEO |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 // When the background mode pref is enabled and there are pending triggers | 1027 // When the background mode pref is enabled and there are pending triggers |
1030 // they will be registered and the user will be notified. | 1028 // they will be registered and the user will be notified. |
1031 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); | 1029 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); |
1032 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, | 1030 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, |
1033 true); | 1031 true); |
1034 Mock::VerifyAndClearExpectations(&manager); | 1032 Mock::VerifyAndClearExpectations(&manager); |
1035 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); | 1033 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); |
1036 AssertBackgroundModeActive(manager); | 1034 AssertBackgroundModeActive(manager); |
1037 ASSERT_TRUE(manager.HasShownBalloon()); | 1035 ASSERT_TRUE(manager.HasShownBalloon()); |
1038 } | 1036 } |
OLD | NEW |