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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "chrome/browser/background/background_mode_manager.h" | 18 #include "chrome/browser/background/background_mode_manager.h" |
19 #include "chrome/browser/background/background_trigger.h" | 19 #include "chrome/browser/background/background_trigger.h" |
20 #include "chrome/browser/browser_shutdown.h" | 20 #include "chrome/browser/browser_shutdown.h" |
21 #include "chrome/browser/extensions/extension_function_test_utils.h" | 21 #include "chrome/browser/extensions/extension_function_test_utils.h" |
22 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/browser/extensions/test_extension_system.h" | 23 #include "chrome/browser/extensions/test_extension_system.h" |
24 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
25 #include "chrome/browser/lifetime/keep_alive_registry.h" | |
26 #include "chrome/browser/lifetime/keep_alive_types.h" | |
27 #include "chrome/browser/lifetime/scoped_keep_alive.h" | |
25 #include "chrome/browser/profiles/profile_attributes_entry.h" | 28 #include "chrome/browser/profiles/profile_attributes_entry.h" |
26 #include "chrome/browser/profiles/profile_attributes_storage.h" | 29 #include "chrome/browser/profiles/profile_attributes_storage.h" |
27 #include "chrome/browser/status_icons/status_icon_menu_model.h" | 30 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
28 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
29 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
30 #include "chrome/test/base/testing_browser_process.h" | 33 #include "chrome/test/base/testing_browser_process.h" |
31 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
32 #include "chrome/test/base/testing_profile_manager.h" | 35 #include "chrome/test/base/testing_profile_manager.h" |
33 #include "content/public/test/test_browser_thread_bundle.h" | 36 #include "content/public/test/test_browser_thread_bundle.h" |
34 #include "extensions/browser/api_test_utils.h" | 37 #include "extensions/browser/api_test_utils.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 const base::string16& title, | 135 const base::string16& title, |
133 const base::string16& contents, | 136 const base::string16& contents, |
134 const message_center::NotifierId& notifier_id) override {} | 137 const message_center::NotifierId& notifier_id) override {} |
135 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} | 138 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
136 | 139 |
137 private: | 140 private: |
138 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); | 141 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); |
139 }; | 142 }; |
140 | 143 |
141 void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { | 144 void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { |
142 EXPECT_TRUE(chrome::WillKeepAlive()); | 145 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
143 EXPECT_TRUE(manager.HaveStatusTray()); | 146 EXPECT_TRUE(manager.HaveStatusTray()); |
144 } | 147 } |
145 | 148 |
146 void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { | 149 void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { |
147 EXPECT_FALSE(chrome::WillKeepAlive()); | 150 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
148 EXPECT_FALSE(manager.HaveStatusTray()); | 151 EXPECT_FALSE(manager.HaveStatusTray()); |
149 } | 152 } |
150 | 153 |
151 } // namespace | 154 } // namespace |
152 | 155 |
153 // More complex test helper that exposes APIs for fine grained control of | 156 // More complex test helper that exposes APIs for fine grained control of |
154 // things like the number of background applications. This allows writing | 157 // things like the number of background applications. This allows writing |
155 // smaller tests that don't have to install/uninstall extensions. | 158 // smaller tests that don't have to install/uninstall extensions. |
156 class AdvancedTestBackgroundModeManager : public TestBackgroundModeManager { | 159 class AdvancedTestBackgroundModeManager : public TestBackgroundModeManager { |
157 public: | 160 public: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 ~BackgroundModeManagerWithExtensionsTest() override {} | 232 ~BackgroundModeManagerWithExtensionsTest() override {} |
230 | 233 |
231 void SetUp() override { | 234 void SetUp() override { |
232 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); | 235 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
233 profile_manager_ = CreateTestingProfileManager(); | 236 profile_manager_ = CreateTestingProfileManager(); |
234 profile_ = profile_manager_->CreateTestingProfile("p1"); | 237 profile_ = profile_manager_->CreateTestingProfile("p1"); |
235 | 238 |
236 // Aura clears notifications from the message center at shutdown. | 239 // Aura clears notifications from the message center at shutdown. |
237 message_center::MessageCenter::Initialize(); | 240 message_center::MessageCenter::Initialize(); |
238 | 241 |
239 // BackgroundModeManager actually affects Chrome start/stop state, | 242 test_keep_alive_.reset( |
240 // tearing down our thread bundle before we've had chance to clean | 243 new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER, |
241 // everything up. Keeping Chrome alive prevents this. | 244 KeepAliveRestartOption::DISABLED)); |
242 // We aren't interested in if the keep alive works correctly in this test. | |
243 chrome::IncrementKeepAliveCount(); | |
244 | 245 |
245 #if defined(OS_CHROMEOS) | 246 #if defined(OS_CHROMEOS) |
246 // On ChromeOS shutdown, HandleAppExitingForPlatform will call | 247 // TODO(dgn): reset() on the empty keep alive would do nothing, is it |
247 // chrome::DecrementKeepAliveCount because it assumes the aura shell | 248 // ok to just skip? |
248 // called chrome::IncrementKeepAliveCount. Simulate the call here. | |
249 chrome::IncrementKeepAliveCount(); | |
dgn
2016/03/09 23:49:23
This is not needed anymore because the reset() cal
| |
250 #endif | 249 #endif |
251 | 250 |
252 // Create our test BackgroundModeManager. | 251 // Create our test BackgroundModeManager. |
253 manager_.reset(new TestBackgroundModeManager( | 252 manager_.reset(new TestBackgroundModeManager( |
254 *command_line_, profile_manager_->profile_attributes_storage())); | 253 *command_line_, profile_manager_->profile_attributes_storage())); |
255 manager_->RegisterProfile(profile_); | 254 manager_->RegisterProfile(profile_); |
256 } | 255 } |
257 | 256 |
258 void TearDown() override { | 257 void TearDown() override { |
259 // Clean up the status icon. If this is not done before profile deletes, | 258 // Clean up the status icon. If this is not done before profile deletes, |
260 // the context menu updates will DCHECK with the now deleted profiles. | 259 // the context menu updates will DCHECK with the now deleted profiles. |
261 StatusIcon* status_icon = manager_->status_icon_; | 260 StatusIcon* status_icon = manager_->status_icon_; |
262 manager_->status_icon_ = NULL; | 261 manager_->status_icon_ = NULL; |
263 delete status_icon; | 262 delete status_icon; |
264 | 263 |
265 // We have to destroy the profiles now because we created them with real | 264 // We have to destroy the profiles now because we created them with real |
266 // thread state. This causes a lot of machinery to spin up that stops | 265 // thread state. This causes a lot of machinery to spin up that stops |
267 // working when we tear down our thread state at the end of the test. | 266 // working when we tear down our thread state at the end of the test. |
268 // Deleting our testing profile may have the side-effect of disabling | 267 // Deleting our testing profile may have the side-effect of disabling |
269 // background mode if it was enabled for that profile (explicitly note that | 268 // background mode if it was enabled for that profile (explicitly note that |
270 // here to satisfy StrictMock requirements. | 269 // here to satisfy StrictMock requirements. |
271 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1)); | 270 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1)); |
272 profile_manager_->DeleteAllTestingProfiles(); | 271 profile_manager_->DeleteAllTestingProfiles(); |
273 Mock::VerifyAndClearExpectations(manager_.get()); | 272 Mock::VerifyAndClearExpectations(manager_.get()); |
274 | 273 |
275 // We're getting ready to shutdown the message loop. Clear everything out! | 274 // We're getting ready to shutdown the message loop. Clear everything out! |
276 base::MessageLoop::current()->RunUntilIdle(); | 275 base::MessageLoop::current()->RunUntilIdle(); |
277 // Matching the call to IncrementKeepAliveCount in SetUp(). | 276 |
278 chrome::DecrementKeepAliveCount(); | 277 test_keep_alive_.reset(); |
279 | 278 |
280 // TestBackgroundModeManager has dependencies on the infrastructure. | 279 // TestBackgroundModeManager has dependencies on the infrastructure. |
281 // It should get cleared first. | 280 // It should get cleared first. |
282 manager_.reset(); | 281 manager_.reset(); |
283 | 282 |
284 // The Profile Manager references the Browser Process. | 283 // The Profile Manager references the Browser Process. |
285 // The Browser Process references the Notification UI Manager. | 284 // The Browser Process references the Notification UI Manager. |
286 // The Notification UI Manager references the Message Center. | 285 // The Notification UI Manager references the Message Center. |
287 // As a result, we have to clear the browser process state here | 286 // As a result, we have to clear the browser process state here |
288 // before tearing down the Message Center. | 287 // before tearing down the Message Center. |
289 profile_manager_.reset(); | 288 profile_manager_.reset(); |
290 | 289 |
291 // Message Center shutdown must occur after the DecrementKeepAliveCount | 290 // Message Center shutdown must occur after the KeepAlive is released |
292 // because DecrementKeepAliveCount will end up referencing the message | 291 // because clearing them will end up referencing the message center. |
293 // center during cleanup. | |
294 message_center::MessageCenter::Shutdown(); | 292 message_center::MessageCenter::Shutdown(); |
295 | 293 |
296 // Clear the shutdown flag to isolate the remaining effect of this test. | 294 // Clear the shutdown flag to isolate the remaining effect of this test. |
297 browser_shutdown::SetTryingToQuit(false); | 295 browser_shutdown::SetTryingToQuit(false); |
298 } | 296 } |
299 | 297 |
300 protected: | 298 protected: |
301 scoped_refptr<extensions::Extension> CreateExtension( | 299 scoped_refptr<extensions::Extension> CreateExtension( |
302 extensions::Manifest::Location location, | 300 extensions::Manifest::Location location, |
303 const std::string& data, | 301 const std::string& data, |
(...skipping 18 matching lines...) Expand all Loading... | |
322 scoped_ptr<base::CommandLine> command_line_; | 320 scoped_ptr<base::CommandLine> command_line_; |
323 | 321 |
324 scoped_ptr<TestingProfileManager> profile_manager_; | 322 scoped_ptr<TestingProfileManager> profile_manager_; |
325 // Test profile used by all tests - this is owned by profile_manager_. | 323 // Test profile used by all tests - this is owned by profile_manager_. |
326 TestingProfile* profile_; | 324 TestingProfile* profile_; |
327 | 325 |
328 private: | 326 private: |
329 // Required for extension service. | 327 // Required for extension service. |
330 content::TestBrowserThreadBundle thread_bundle_; | 328 content::TestBrowserThreadBundle thread_bundle_; |
331 | 329 |
330 // BackgroundModeManager actually affects Chrome start/stop state, | |
331 // tearing down our thread bundle before we've had chance to clean | |
332 // everything up. Keeping Chrome alive prevents this. | |
333 // We aren't interested in if the keep alive works correctly in this test. | |
334 scoped_ptr<ScopedKeepAlive> test_keep_alive_; | |
335 | |
332 #if defined(OS_CHROMEOS) | 336 #if defined(OS_CHROMEOS) |
333 // ChromeOS needs extra services to run in the following order. | 337 // ChromeOS needs extra services to run in the following order. |
334 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 338 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
335 chromeos::ScopedTestCrosSettings test_cros_settings_; | 339 chromeos::ScopedTestCrosSettings test_cros_settings_; |
336 chromeos::ScopedTestUserManager test_user_manager_; | 340 chromeos::ScopedTestUserManager test_user_manager_; |
337 #endif | 341 #endif |
338 | 342 |
339 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); | 343 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); |
340 }; | 344 }; |
341 | 345 |
342 | 346 |
343 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 347 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
344 AdvancedTestBackgroundModeManager manager( | 348 AdvancedTestBackgroundModeManager manager( |
345 *command_line_, profile_manager_->profile_attributes_storage(), true); | 349 *command_line_, profile_manager_->profile_attributes_storage(), true); |
346 manager.RegisterProfile(profile_); | 350 manager.RegisterProfile(profile_); |
347 EXPECT_FALSE(chrome::WillKeepAlive()); | 351 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
348 | 352 |
349 // Mimic app load. | 353 // Mimic app load. |
350 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 354 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
351 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 355 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
352 manager.SetBackgroundClientCountForProfile(profile_, 1); | 356 manager.SetBackgroundClientCountForProfile(profile_, 1); |
353 manager.OnApplicationListChanged(profile_); | 357 manager.OnApplicationListChanged(profile_); |
354 Mock::VerifyAndClearExpectations(&manager); | 358 Mock::VerifyAndClearExpectations(&manager); |
355 AssertBackgroundModeActive(manager); | 359 AssertBackgroundModeActive(manager); |
356 | 360 |
357 manager.SuspendBackgroundMode(); | 361 manager.SuspendBackgroundMode(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 Mock::VerifyAndClearExpectations(&manager); | 474 Mock::VerifyAndClearExpectations(&manager); |
471 AssertBackgroundModeInactive(manager); | 475 AssertBackgroundModeInactive(manager); |
472 } | 476 } |
473 | 477 |
474 TEST_F(BackgroundModeManagerTest, MultiProfile) { | 478 TEST_F(BackgroundModeManagerTest, MultiProfile) { |
475 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 479 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
476 AdvancedTestBackgroundModeManager manager( | 480 AdvancedTestBackgroundModeManager manager( |
477 *command_line_, profile_manager_->profile_attributes_storage(), true); | 481 *command_line_, profile_manager_->profile_attributes_storage(), true); |
478 manager.RegisterProfile(profile_); | 482 manager.RegisterProfile(profile_); |
479 manager.RegisterProfile(profile2); | 483 manager.RegisterProfile(profile2); |
480 EXPECT_FALSE(chrome::WillKeepAlive()); | 484 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
481 | 485 |
482 // Install app, should show status tray icon. | 486 // Install app, should show status tray icon. |
483 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 487 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
484 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 488 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
485 manager.SetBackgroundClientCountForProfile(profile_, 1); | 489 manager.SetBackgroundClientCountForProfile(profile_, 1); |
486 manager.OnApplicationListChanged(profile_); | 490 manager.OnApplicationListChanged(profile_); |
487 Mock::VerifyAndClearExpectations(&manager); | 491 Mock::VerifyAndClearExpectations(&manager); |
488 AssertBackgroundModeActive(manager); | 492 AssertBackgroundModeActive(manager); |
489 | 493 |
490 // Install app for other profile, should show other status tray icon. | 494 // Install app for other profile, should show other status tray icon. |
(...skipping 30 matching lines...) Expand all Loading... | |
521 AssertBackgroundModeInactive(manager); | 525 AssertBackgroundModeInactive(manager); |
522 } | 526 } |
523 | 527 |
524 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorage) { | 528 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorage) { |
525 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 529 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
526 ProfileAttributesStorage* storage = | 530 ProfileAttributesStorage* storage = |
527 profile_manager_->profile_attributes_storage(); | 531 profile_manager_->profile_attributes_storage(); |
528 AdvancedTestBackgroundModeManager manager(*command_line_, storage, true); | 532 AdvancedTestBackgroundModeManager manager(*command_line_, storage, true); |
529 manager.RegisterProfile(profile_); | 533 manager.RegisterProfile(profile_); |
530 manager.RegisterProfile(profile2); | 534 manager.RegisterProfile(profile2); |
531 EXPECT_FALSE(chrome::WillKeepAlive()); | 535 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
532 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); | 536 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); |
533 | 537 |
534 ProfileAttributesEntry* entry1; | 538 ProfileAttributesEntry* entry1; |
535 ProfileAttributesEntry* entry2; | 539 ProfileAttributesEntry* entry2; |
536 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile_->GetPath(), | 540 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile_->GetPath(), |
537 &entry1)); | 541 &entry1)); |
538 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile2->GetPath(), | 542 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile2->GetPath(), |
539 &entry2)); | 543 &entry2)); |
540 | 544 |
541 EXPECT_FALSE(entry1->GetBackgroundStatus()); | 545 EXPECT_FALSE(entry1->GetBackgroundStatus()); |
(...skipping 28 matching lines...) Expand all Loading... | |
570 | 574 |
571 // Even though neither has background status on, there should still be two | 575 // Even though neither has background status on, there should still be two |
572 // profiles in the ProfileAttributesStorage. | 576 // profiles in the ProfileAttributesStorage. |
573 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); | 577 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); |
574 } | 578 } |
575 | 579 |
576 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { | 580 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { |
577 AdvancedTestBackgroundModeManager manager( | 581 AdvancedTestBackgroundModeManager manager( |
578 *command_line_, profile_manager_->profile_attributes_storage(), true); | 582 *command_line_, profile_manager_->profile_attributes_storage(), true); |
579 manager.RegisterProfile(profile_); | 583 manager.RegisterProfile(profile_); |
580 EXPECT_FALSE(chrome::WillKeepAlive()); | 584 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
581 | 585 |
582 // Install app, should show status tray icon. | 586 // Install app, should show status tray icon. |
583 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 587 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
584 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 588 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
585 manager.SetBackgroundClientCountForProfile(profile_, 1); | 589 manager.SetBackgroundClientCountForProfile(profile_, 1); |
586 manager.OnApplicationListChanged(profile_); | 590 manager.OnApplicationListChanged(profile_); |
587 Mock::VerifyAndClearExpectations(&manager); | 591 Mock::VerifyAndClearExpectations(&manager); |
588 | 592 |
589 // Background mode should remain active for the remainder of this test. | 593 // Background mode should remain active for the remainder of this test. |
590 | 594 |
591 manager.OnProfileNameChanged( | 595 manager.OnProfileNameChanged( |
592 profile_->GetPath(), | 596 profile_->GetPath(), |
593 manager.GetBackgroundModeData(profile_)->name()); | 597 manager.GetBackgroundModeData(profile_)->name()); |
594 | 598 |
595 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 599 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
596 manager.GetBackgroundModeData(profile_)->name()); | 600 manager.GetBackgroundModeData(profile_)->name()); |
597 | 601 |
598 EXPECT_TRUE(chrome::WillKeepAlive()); | 602 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
599 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 603 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
600 manager.RegisterProfile(profile2); | 604 manager.RegisterProfile(profile2); |
601 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); | 605 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
602 | 606 |
603 manager.OnProfileAdded(profile2->GetPath()); | 607 manager.OnProfileAdded(profile2->GetPath()); |
604 EXPECT_EQ(base::UTF8ToUTF16("p2"), | 608 EXPECT_EQ(base::UTF8ToUTF16("p2"), |
605 manager.GetBackgroundModeData(profile2)->name()); | 609 manager.GetBackgroundModeData(profile2)->name()); |
606 | 610 |
607 manager.OnProfileWillBeRemoved(profile2->GetPath()); | 611 manager.OnProfileWillBeRemoved(profile2->GetPath()); |
608 // Should still be in background mode after deleting profile. | 612 // Should still be in background mode after deleting profile. |
609 EXPECT_TRUE(chrome::WillKeepAlive()); | 613 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
610 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); | 614 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
611 | 615 |
612 // Check that the background mode data we think is in the map actually is. | 616 // Check that the background mode data we think is in the map actually is. |
613 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 617 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
614 manager.GetBackgroundModeData(profile_)->name()); | 618 manager.GetBackgroundModeData(profile_)->name()); |
615 } | 619 } |
616 | 620 |
617 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { | 621 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
618 // Tests whether deleting the only profile when it is a BG profile works | 622 // Tests whether deleting the only profile when it is a BG profile works |
619 // or not (http://crbug.com/346214). | 623 // or not (http://crbug.com/346214). |
620 AdvancedTestBackgroundModeManager manager( | 624 AdvancedTestBackgroundModeManager manager( |
621 *command_line_, profile_manager_->profile_attributes_storage(), true); | 625 *command_line_, profile_manager_->profile_attributes_storage(), true); |
622 manager.RegisterProfile(profile_); | 626 manager.RegisterProfile(profile_); |
623 EXPECT_FALSE(chrome::WillKeepAlive()); | 627 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
624 | 628 |
625 // Install app, should show status tray icon. | 629 // Install app, should show status tray icon. |
626 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 630 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
627 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 631 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
628 manager.SetBackgroundClientCountForProfile(profile_, 1); | 632 manager.SetBackgroundClientCountForProfile(profile_, 1); |
629 manager.OnApplicationListChanged(profile_); | 633 manager.OnApplicationListChanged(profile_); |
630 Mock::VerifyAndClearExpectations(&manager); | 634 Mock::VerifyAndClearExpectations(&manager); |
631 | 635 |
632 manager.OnProfileNameChanged( | 636 manager.OnProfileNameChanged( |
633 profile_->GetPath(), | 637 profile_->GetPath(), |
634 manager.GetBackgroundModeData(profile_)->name()); | 638 manager.GetBackgroundModeData(profile_)->name()); |
635 | 639 |
636 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 640 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
637 EXPECT_TRUE(chrome::WillKeepAlive()); | 641 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
638 manager.SetBackgroundClientCountForProfile(profile_, 0); | 642 manager.SetBackgroundClientCountForProfile(profile_, 0); |
639 manager.OnProfileWillBeRemoved(profile_->GetPath()); | 643 manager.OnProfileWillBeRemoved(profile_->GetPath()); |
640 Mock::VerifyAndClearExpectations(&manager); | 644 Mock::VerifyAndClearExpectations(&manager); |
641 EXPECT_FALSE(chrome::WillKeepAlive()); | 645 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
642 } | 646 } |
643 | 647 |
644 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { | 648 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { |
645 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 649 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
646 AdvancedTestBackgroundModeManager manager( | 650 AdvancedTestBackgroundModeManager manager( |
647 *command_line_, profile_manager_->profile_attributes_storage(), true); | 651 *command_line_, profile_manager_->profile_attributes_storage(), true); |
648 manager.RegisterProfile(profile_); | 652 manager.RegisterProfile(profile_); |
649 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); | 653 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); |
650 | 654 |
651 // No enable-launch-on-startup calls expected yet. | 655 // No enable-launch-on-startup calls expected yet. |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 // When the background mode pref is enabled and there are pending triggers | 1032 // When the background mode pref is enabled and there are pending triggers |
1029 // they will be registered and the user will be notified. | 1033 // they will be registered and the user will be notified. |
1030 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); | 1034 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); |
1031 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, | 1035 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, |
1032 true); | 1036 true); |
1033 Mock::VerifyAndClearExpectations(&manager); | 1037 Mock::VerifyAndClearExpectations(&manager); |
1034 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); | 1038 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); |
1035 AssertBackgroundModeActive(manager); | 1039 AssertBackgroundModeActive(manager); |
1036 ASSERT_TRUE(manager.HasShownBalloon()); | 1040 ASSERT_TRUE(manager.HasShownBalloon()); |
1037 } | 1041 } |
OLD | NEW |