Chromium Code Reviews| Index: chrome/browser/background/background_mode_manager_unittest.cc |
| diff --git a/chrome/browser/background/background_mode_manager_unittest.cc b/chrome/browser/background/background_mode_manager_unittest.cc |
| index c1f3de763fbabbc919f1676cb7d5c8b54264461c..9c9fe871b4eb268e9ea5244d8b9abe7beb571721 100644 |
| --- a/chrome/browser/background/background_mode_manager_unittest.cc |
| +++ b/chrome/browser/background/background_mode_manager_unittest.cc |
| @@ -22,6 +22,9 @@ |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/test_extension_system.h" |
| #include "chrome/browser/lifetime/application_lifetime.h" |
| +#include "chrome/browser/lifetime/keep_alive_registry.h" |
| +#include "chrome/browser/lifetime/keep_alive_types.h" |
| +#include "chrome/browser/lifetime/scoped_keep_alive.h" |
| #include "chrome/browser/profiles/profile_attributes_entry.h" |
| #include "chrome/browser/profiles/profile_attributes_storage.h" |
| #include "chrome/browser/status_icons/status_icon_menu_model.h" |
| @@ -139,12 +142,12 @@ class TestStatusIcon : public StatusIcon { |
| }; |
| void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { |
| - EXPECT_TRUE(chrome::WillKeepAlive()); |
| + EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| EXPECT_TRUE(manager.HaveStatusTray()); |
| } |
| void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| EXPECT_FALSE(manager.HaveStatusTray()); |
| } |
| @@ -236,18 +239,9 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
| // Aura clears notifications from the message center at shutdown. |
| message_center::MessageCenter::Initialize(); |
| - // BackgroundModeManager actually affects Chrome start/stop state, |
| - // tearing down our thread bundle before we've had chance to clean |
| - // everything up. Keeping Chrome alive prevents this. |
| - // We aren't interested in if the keep alive works correctly in this test. |
| - chrome::IncrementKeepAliveCount(); |
| - |
| -#if defined(OS_CHROMEOS) |
| - // On ChromeOS shutdown, HandleAppExitingForPlatform will call |
| - // chrome::DecrementKeepAliveCount because it assumes the aura shell |
| - // called chrome::IncrementKeepAliveCount. Simulate the call here. |
| - 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
|
| -#endif |
| + test_keep_alive_.reset( |
| + new ScopedKeepAlive(KeepAliveOrigin::BACKGROUND_MODE_MANAGER, |
| + KeepAliveRestartOption::DISABLED)); |
| // Create our test BackgroundModeManager. |
| manager_.reset(new TestBackgroundModeManager( |
| @@ -274,8 +268,8 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
| // We're getting ready to shutdown the message loop. Clear everything out! |
| base::MessageLoop::current()->RunUntilIdle(); |
| - // Matching the call to IncrementKeepAliveCount in SetUp(). |
| - chrome::DecrementKeepAliveCount(); |
| + |
| + test_keep_alive_.reset(); |
| // TestBackgroundModeManager has dependencies on the infrastructure. |
| // It should get cleared first. |
| @@ -288,9 +282,8 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
| // before tearing down the Message Center. |
| profile_manager_.reset(); |
| - // Message Center shutdown must occur after the DecrementKeepAliveCount |
| - // because DecrementKeepAliveCount will end up referencing the message |
| - // center during cleanup. |
| + // Message Center shutdown must occur after the KeepAlive is released |
| + // because clearing it will end up referencing the message center. |
| message_center::MessageCenter::Shutdown(); |
| // Clear the shutdown flag to isolate the remaining effect of this test. |
| @@ -329,6 +322,12 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
| // Required for extension service. |
| content::TestBrowserThreadBundle thread_bundle_; |
| + // BackgroundModeManager actually affects Chrome start/stop state, |
| + // tearing down our thread bundle before we've had chance to clean |
| + // everything up. Keeping Chrome alive prevents this. |
| + // We aren't interested in if the keep alive works correctly in this test. |
| + scoped_ptr<ScopedKeepAlive> test_keep_alive_; |
| + |
| #if defined(OS_CHROMEOS) |
| // ChromeOS needs extra services to run in the following order. |
| chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| @@ -344,7 +343,7 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
| AdvancedTestBackgroundModeManager manager( |
| *command_line_, profile_manager_->profile_attributes_storage(), true); |
| manager.RegisterProfile(profile_); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| // Mimic app load. |
| EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| @@ -477,7 +476,7 @@ TEST_F(BackgroundModeManagerTest, MultiProfile) { |
| *command_line_, profile_manager_->profile_attributes_storage(), true); |
| manager.RegisterProfile(profile_); |
| manager.RegisterProfile(profile2); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| // Install app, should show status tray icon. |
| EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| @@ -528,7 +527,7 @@ TEST_F(BackgroundModeManagerTest, ProfileAttributesStorage) { |
| AdvancedTestBackgroundModeManager manager(*command_line_, storage, true); |
| manager.RegisterProfile(profile_); |
| manager.RegisterProfile(profile2); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| EXPECT_EQ(2u, storage->GetNumberOfProfiles()); |
| ProfileAttributesEntry* entry1; |
| @@ -577,7 +576,7 @@ TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { |
| AdvancedTestBackgroundModeManager manager( |
| *command_line_, profile_manager_->profile_attributes_storage(), true); |
| manager.RegisterProfile(profile_); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| // Install app, should show status tray icon. |
| EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| @@ -595,7 +594,7 @@ TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { |
| EXPECT_EQ(base::UTF8ToUTF16("p1"), |
| manager.GetBackgroundModeData(profile_)->name()); |
| - EXPECT_TRUE(chrome::WillKeepAlive()); |
| + EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
| manager.RegisterProfile(profile2); |
| EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
| @@ -606,7 +605,7 @@ TEST_F(BackgroundModeManagerTest, ProfileAttributesStorageObserver) { |
| manager.OnProfileWillBeRemoved(profile2->GetPath()); |
| // Should still be in background mode after deleting profile. |
| - EXPECT_TRUE(chrome::WillKeepAlive()); |
| + EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
| // Check that the background mode data we think is in the map actually is. |
| @@ -620,7 +619,7 @@ TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
| AdvancedTestBackgroundModeManager manager( |
| *command_line_, profile_manager_->profile_attributes_storage(), true); |
| manager.RegisterProfile(profile_); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| // Install app, should show status tray icon. |
| EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| @@ -634,11 +633,11 @@ TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
| manager.GetBackgroundModeData(profile_)->name()); |
| EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
| - EXPECT_TRUE(chrome::WillKeepAlive()); |
| + EXPECT_TRUE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| manager.SetBackgroundClientCountForProfile(profile_, 0); |
| manager.OnProfileWillBeRemoved(profile_->GetPath()); |
| Mock::VerifyAndClearExpectations(&manager); |
| - EXPECT_FALSE(chrome::WillKeepAlive()); |
| + EXPECT_FALSE(KeepAliveRegistry::GetInstance()->IsKeepingAlive()); |
| } |
| TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { |