Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/background/background_mode_manager_unittest.cc

Issue 1778873002: Replace Increment/DecrementKeepAliveCount by ScopedKeepAlives (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@KAObserver
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 #if defined(OS_CHROMEOS)
246 // On ChromeOS shutdown, HandleAppExitingForPlatform will call
247 // chrome::DecrementKeepAliveCount because it assumes the aura shell
248 // called chrome::IncrementKeepAliveCount. Simulate the call here.
249 chrome::IncrementKeepAliveCount();
sky 2016/03/10 04:18:20 Why don't you need this anymore?
dgn 2016/03/10 18:31:51 As explained by the comment, the count is decremen
250 #endif
251 245
252 // Create our test BackgroundModeManager. 246 // Create our test BackgroundModeManager.
253 manager_.reset(new TestBackgroundModeManager( 247 manager_.reset(new TestBackgroundModeManager(
254 *command_line_, profile_manager_->profile_attributes_storage())); 248 *command_line_, profile_manager_->profile_attributes_storage()));
255 manager_->RegisterProfile(profile_); 249 manager_->RegisterProfile(profile_);
256 } 250 }
257 251
258 void TearDown() override { 252 void TearDown() override {
259 // Clean up the status icon. If this is not done before profile deletes, 253 // 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. 254 // the context menu updates will DCHECK with the now deleted profiles.
261 StatusIcon* status_icon = manager_->status_icon_; 255 StatusIcon* status_icon = manager_->status_icon_;
262 manager_->status_icon_ = NULL; 256 manager_->status_icon_ = NULL;
263 delete status_icon; 257 delete status_icon;
264 258
265 // We have to destroy the profiles now because we created them with real 259 // 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 260 // 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. 261 // 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 262 // Deleting our testing profile may have the side-effect of disabling
269 // background mode if it was enabled for that profile (explicitly note that 263 // background mode if it was enabled for that profile (explicitly note that
270 // here to satisfy StrictMock requirements. 264 // here to satisfy StrictMock requirements.
271 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1)); 265 EXPECT_CALL(*manager_, EnableLaunchOnStartup(false)).Times(AtMost(1));
272 profile_manager_->DeleteAllTestingProfiles(); 266 profile_manager_->DeleteAllTestingProfiles();
273 Mock::VerifyAndClearExpectations(manager_.get()); 267 Mock::VerifyAndClearExpectations(manager_.get());
274 268
275 // We're getting ready to shutdown the message loop. Clear everything out! 269 // We're getting ready to shutdown the message loop. Clear everything out!
276 base::MessageLoop::current()->RunUntilIdle(); 270 base::MessageLoop::current()->RunUntilIdle();
277 // Matching the call to IncrementKeepAliveCount in SetUp(). 271
278 chrome::DecrementKeepAliveCount(); 272 test_keep_alive_.reset();
279 273
280 // TestBackgroundModeManager has dependencies on the infrastructure. 274 // TestBackgroundModeManager has dependencies on the infrastructure.
281 // It should get cleared first. 275 // It should get cleared first.
282 manager_.reset(); 276 manager_.reset();
283 277
284 // The Profile Manager references the Browser Process. 278 // The Profile Manager references the Browser Process.
285 // The Browser Process references the Notification UI Manager. 279 // The Browser Process references the Notification UI Manager.
286 // The Notification UI Manager references the Message Center. 280 // The Notification UI Manager references the Message Center.
287 // As a result, we have to clear the browser process state here 281 // As a result, we have to clear the browser process state here
288 // before tearing down the Message Center. 282 // before tearing down the Message Center.
289 profile_manager_.reset(); 283 profile_manager_.reset();
290 284
291 // Message Center shutdown must occur after the DecrementKeepAliveCount 285 // Message Center shutdown must occur after the KeepAlive is released
292 // because DecrementKeepAliveCount will end up referencing the message 286 // because clearing it will end up referencing the message center.
293 // center during cleanup.
294 message_center::MessageCenter::Shutdown(); 287 message_center::MessageCenter::Shutdown();
295 288
296 // Clear the shutdown flag to isolate the remaining effect of this test. 289 // Clear the shutdown flag to isolate the remaining effect of this test.
297 browser_shutdown::SetTryingToQuit(false); 290 browser_shutdown::SetTryingToQuit(false);
298 } 291 }
299 292
300 protected: 293 protected:
301 scoped_refptr<extensions::Extension> CreateExtension( 294 scoped_refptr<extensions::Extension> CreateExtension(
302 extensions::Manifest::Location location, 295 extensions::Manifest::Location location,
303 const std::string& data, 296 const std::string& data,
(...skipping 18 matching lines...) Expand all
322 scoped_ptr<base::CommandLine> command_line_; 315 scoped_ptr<base::CommandLine> command_line_;
323 316
324 scoped_ptr<TestingProfileManager> profile_manager_; 317 scoped_ptr<TestingProfileManager> profile_manager_;
325 // Test profile used by all tests - this is owned by profile_manager_. 318 // Test profile used by all tests - this is owned by profile_manager_.
326 TestingProfile* profile_; 319 TestingProfile* profile_;
327 320
328 private: 321 private:
329 // Required for extension service. 322 // Required for extension service.
330 content::TestBrowserThreadBundle thread_bundle_; 323 content::TestBrowserThreadBundle thread_bundle_;
331 324
325 // BackgroundModeManager actually affects Chrome start/stop state,
326 // tearing down our thread bundle before we've had chance to clean
327 // everything up. Keeping Chrome alive prevents this.
328 // We aren't interested in if the keep alive works correctly in this test.
329 scoped_ptr<ScopedKeepAlive> test_keep_alive_;
330
332 #if defined(OS_CHROMEOS) 331 #if defined(OS_CHROMEOS)
333 // ChromeOS needs extra services to run in the following order. 332 // ChromeOS needs extra services to run in the following order.
334 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 333 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
335 chromeos::ScopedTestCrosSettings test_cros_settings_; 334 chromeos::ScopedTestCrosSettings test_cros_settings_;
336 chromeos::ScopedTestUserManager test_user_manager_; 335 chromeos::ScopedTestUserManager test_user_manager_;
337 #endif 336 #endif
338 337
339 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); 338 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest);
340 }; 339 };
341 340
342 341
343 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { 342 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) {
344 AdvancedTestBackgroundModeManager manager( 343 AdvancedTestBackgroundModeManager manager(
345 *command_line_, profile_manager_->profile_attributes_storage(), true); 344 *command_line_, profile_manager_->profile_attributes_storage(), true);
346 manager.RegisterProfile(profile_); 345 manager.RegisterProfile(profile_);
347 EXPECT_FALSE(chrome::WillKeepAlive()); 346 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
348 347
349 // Mimic app load. 348 // Mimic app load.
350 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); 349 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1));
351 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); 350 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name"));
352 manager.SetBackgroundClientCountForProfile(profile_, 1); 351 manager.SetBackgroundClientCountForProfile(profile_, 1);
353 manager.OnApplicationListChanged(profile_); 352 manager.OnApplicationListChanged(profile_);
354 Mock::VerifyAndClearExpectations(&manager); 353 Mock::VerifyAndClearExpectations(&manager);
355 AssertBackgroundModeActive(manager); 354 AssertBackgroundModeActive(manager);
356 355
357 manager.SuspendBackgroundMode(); 356 manager.SuspendBackgroundMode();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 Mock::VerifyAndClearExpectations(&manager); 469 Mock::VerifyAndClearExpectations(&manager);
471 AssertBackgroundModeInactive(manager); 470 AssertBackgroundModeInactive(manager);
472 } 471 }
473 472
474 TEST_F(BackgroundModeManagerTest, MultiProfile) { 473 TEST_F(BackgroundModeManagerTest, MultiProfile) {
475 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); 474 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2");
476 AdvancedTestBackgroundModeManager manager( 475 AdvancedTestBackgroundModeManager manager(
477 *command_line_, profile_manager_->profile_attributes_storage(), true); 476 *command_line_, profile_manager_->profile_attributes_storage(), true);
478 manager.RegisterProfile(profile_); 477 manager.RegisterProfile(profile_);
479 manager.RegisterProfile(profile2); 478 manager.RegisterProfile(profile2);
480 EXPECT_FALSE(chrome::WillKeepAlive()); 479 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
481 480
482 // Install app, should show status tray icon. 481 // Install app, should show status tray icon.
483 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); 482 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1));
484 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); 483 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name"));
485 manager.SetBackgroundClientCountForProfile(profile_, 1); 484 manager.SetBackgroundClientCountForProfile(profile_, 1);
486 manager.OnApplicationListChanged(profile_); 485 manager.OnApplicationListChanged(profile_);
487 Mock::VerifyAndClearExpectations(&manager); 486 Mock::VerifyAndClearExpectations(&manager);
488 AssertBackgroundModeActive(manager); 487 AssertBackgroundModeActive(manager);
489 488
490 // Install app for other profile, should show other status tray icon. 489 // Install app for other profile, should show other status tray icon.
(...skipping 30 matching lines...) Expand all
521 AssertBackgroundModeInactive(manager); 520 AssertBackgroundModeInactive(manager);
522 } 521 }
523 522
524 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorage) { 523 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorage) {
525 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); 524 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2");
526 ProfileAttributesStorage* storage = 525 ProfileAttributesStorage* storage =
527 profile_manager_->profile_attributes_storage(); 526 profile_manager_->profile_attributes_storage();
528 AdvancedTestBackgroundModeManager manager(*command_line_, storage, true); 527 AdvancedTestBackgroundModeManager manager(*command_line_, storage, true);
529 manager.RegisterProfile(profile_); 528 manager.RegisterProfile(profile_);
530 manager.RegisterProfile(profile2); 529 manager.RegisterProfile(profile2);
531 EXPECT_FALSE(chrome::WillKeepAlive()); 530 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
532 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); 531 EXPECT_EQ(2u, storage->GetNumberOfProfiles());
533 532
534 ProfileAttributesEntry* entry1; 533 ProfileAttributesEntry* entry1;
535 ProfileAttributesEntry* entry2; 534 ProfileAttributesEntry* entry2;
536 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile_->GetPath(), 535 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile_->GetPath(),
537 &entry1)); 536 &entry1));
538 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile2->GetPath(), 537 ASSERT_TRUE(storage->GetProfileAttributesWithPath(profile2->GetPath(),
539 &entry2)); 538 &entry2));
540 539
541 EXPECT_FALSE(entry1->GetBackgroundStatus()); 540 EXPECT_FALSE(entry1->GetBackgroundStatus());
(...skipping 28 matching lines...) Expand all
570 569
571 // Even though neither has background status on, there should still be two 570 // Even though neither has background status on, there should still be two
572 // profiles in the ProfileAttributesStorage. 571 // profiles in the ProfileAttributesStorage.
573 EXPECT_EQ(2u, storage->GetNumberOfProfiles()); 572 EXPECT_EQ(2u, storage->GetNumberOfProfiles());
574 } 573 }
575 574
576 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { 575 TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) {
577 AdvancedTestBackgroundModeManager manager( 576 AdvancedTestBackgroundModeManager manager(
578 *command_line_, profile_manager_->profile_attributes_storage(), true); 577 *command_line_, profile_manager_->profile_attributes_storage(), true);
579 manager.RegisterProfile(profile_); 578 manager.RegisterProfile(profile_);
580 EXPECT_FALSE(chrome::WillKeepAlive()); 579 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
581 580
582 // Install app, should show status tray icon. 581 // Install app, should show status tray icon.
583 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); 582 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1));
584 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); 583 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name"));
585 manager.SetBackgroundClientCountForProfile(profile_, 1); 584 manager.SetBackgroundClientCountForProfile(profile_, 1);
586 manager.OnApplicationListChanged(profile_); 585 manager.OnApplicationListChanged(profile_);
587 Mock::VerifyAndClearExpectations(&manager); 586 Mock::VerifyAndClearExpectations(&manager);
588 587
589 // Background mode should remain active for the remainder of this test. 588 // Background mode should remain active for the remainder of this test.
590 589
591 manager.OnProfileNameChanged( 590 manager.OnProfileNameChanged(
592 profile_->GetPath(), 591 profile_->GetPath(),
593 manager.GetBackgroundModeData(profile_)->name()); 592 manager.GetBackgroundModeData(profile_)->name());
594 593
595 EXPECT_EQ(base::UTF8ToUTF16("p1"), 594 EXPECT_EQ(base::UTF8ToUTF16("p1"),
596 manager.GetBackgroundModeData(profile_)->name()); 595 manager.GetBackgroundModeData(profile_)->name());
597 596
598 EXPECT_TRUE(chrome::WillKeepAlive()); 597 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
599 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); 598 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2");
600 manager.RegisterProfile(profile2); 599 manager.RegisterProfile(profile2);
601 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); 600 EXPECT_EQ(2, manager.NumberOfBackgroundModeData());
602 601
603 manager.OnProfileAdded(profile2->GetPath()); 602 manager.OnProfileAdded(profile2->GetPath());
604 EXPECT_EQ(base::UTF8ToUTF16("p2"), 603 EXPECT_EQ(base::UTF8ToUTF16("p2"),
605 manager.GetBackgroundModeData(profile2)->name()); 604 manager.GetBackgroundModeData(profile2)->name());
606 605
607 manager.OnProfileWillBeRemoved(profile2->GetPath()); 606 manager.OnProfileWillBeRemoved(profile2->GetPath());
608 // Should still be in background mode after deleting profile. 607 // Should still be in background mode after deleting profile.
609 EXPECT_TRUE(chrome::WillKeepAlive()); 608 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
610 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); 609 EXPECT_EQ(1, manager.NumberOfBackgroundModeData());
611 610
612 // Check that the background mode data we think is in the map actually is. 611 // Check that the background mode data we think is in the map actually is.
613 EXPECT_EQ(base::UTF8ToUTF16("p1"), 612 EXPECT_EQ(base::UTF8ToUTF16("p1"),
614 manager.GetBackgroundModeData(profile_)->name()); 613 manager.GetBackgroundModeData(profile_)->name());
615 } 614 }
616 615
617 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { 616 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) {
618 // Tests whether deleting the only profile when it is a BG profile works 617 // Tests whether deleting the only profile when it is a BG profile works
619 // or not (http://crbug.com/346214). 618 // or not (http://crbug.com/346214).
620 AdvancedTestBackgroundModeManager manager( 619 AdvancedTestBackgroundModeManager manager(
621 *command_line_, profile_manager_->profile_attributes_storage(), true); 620 *command_line_, profile_manager_->profile_attributes_storage(), true);
622 manager.RegisterProfile(profile_); 621 manager.RegisterProfile(profile_);
623 EXPECT_FALSE(chrome::WillKeepAlive()); 622 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
624 623
625 // Install app, should show status tray icon. 624 // Install app, should show status tray icon.
626 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); 625 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1));
627 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); 626 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name"));
628 manager.SetBackgroundClientCountForProfile(profile_, 1); 627 manager.SetBackgroundClientCountForProfile(profile_, 1);
629 manager.OnApplicationListChanged(profile_); 628 manager.OnApplicationListChanged(profile_);
630 Mock::VerifyAndClearExpectations(&manager); 629 Mock::VerifyAndClearExpectations(&manager);
631 630
632 manager.OnProfileNameChanged( 631 manager.OnProfileNameChanged(
633 profile_->GetPath(), 632 profile_->GetPath(),
634 manager.GetBackgroundModeData(profile_)->name()); 633 manager.GetBackgroundModeData(profile_)->name());
635 634
636 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); 635 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1));
637 EXPECT_TRUE(chrome::WillKeepAlive()); 636 EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
638 manager.SetBackgroundClientCountForProfile(profile_, 0); 637 manager.SetBackgroundClientCountForProfile(profile_, 0);
639 manager.OnProfileWillBeRemoved(profile_->GetPath()); 638 manager.OnProfileWillBeRemoved(profile_->GetPath());
640 Mock::VerifyAndClearExpectations(&manager); 639 Mock::VerifyAndClearExpectations(&manager);
641 EXPECT_FALSE(chrome::WillKeepAlive()); 640 EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive());
642 } 641 }
643 642
644 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { 643 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) {
645 command_line_->AppendSwitch(switches::kKeepAliveForTest); 644 command_line_->AppendSwitch(switches::kKeepAliveForTest);
646 AdvancedTestBackgroundModeManager manager( 645 AdvancedTestBackgroundModeManager manager(
647 *command_line_, profile_manager_->profile_attributes_storage(), true); 646 *command_line_, profile_manager_->profile_attributes_storage(), true);
648 manager.RegisterProfile(profile_); 647 manager.RegisterProfile(profile_);
649 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); 648 EXPECT_TRUE(manager.ShouldBeInBackgroundMode());
650 649
651 // No enable-launch-on-startup calls expected yet. 650 // No enable-launch-on-startup calls expected yet.
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 // 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
1029 // they will be registered and the user will be notified. 1028 // they will be registered and the user will be notified.
1030 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); 1029 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
1031 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, 1030 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled,
1032 true); 1031 true);
1033 Mock::VerifyAndClearExpectations(&manager); 1032 Mock::VerifyAndClearExpectations(&manager);
1034 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); 1033 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_));
1035 AssertBackgroundModeActive(manager); 1034 AssertBackgroundModeActive(manager);
1036 ASSERT_TRUE(manager.HasShownBalloon()); 1035 ASSERT_TRUE(manager.HasShownBalloon());
1037 } 1036 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698