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 2344a25b2183f54df740a45d7952620329e6516e..4c37163015b40abd849cc685f902cca302b6f21d 100644 |
--- a/chrome/browser/background/background_mode_manager_unittest.cc |
+++ b/chrome/browser/background/background_mode_manager_unittest.cc |
@@ -16,6 +16,7 @@ |
#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/browser_keep_alive.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/status_icons/status_icon_menu_model.h" |
#include "chrome/common/chrome_switches.h" |
@@ -130,12 +131,12 @@ class TestStatusIcon : public StatusIcon { |
}; |
void AssertBackgroundModeActive(const TestBackgroundModeManager& manager) { |
- EXPECT_TRUE(chrome::WillKeepAlive()); |
+ EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
EXPECT_TRUE(manager.HaveStatusTray()); |
} |
void AssertBackgroundModeInactive(const TestBackgroundModeManager& manager) { |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
EXPECT_FALSE(manager.HaveStatusTray()); |
} |
@@ -191,14 +192,14 @@ class BackgroundModeManagerTest : public testing::Test { |
command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
profile_manager_ = CreateTestingProfileManager(); |
profile_ = profile_manager_->CreateTestingProfile("p1"); |
- chrome::DisableShutdownForTesting(true); |
+ browser_lifetime::DisableShutdownForTesting(true); |
} |
void TearDown() override { |
// Don't allow the browser to be closed because the shutdown procedure will |
// attempt to access objects that we haven't created (e.g., MessageCenter). |
browser_shutdown::SetTryingToQuit(true); |
- chrome::DisableShutdownForTesting(false); |
+ browser_lifetime::DisableShutdownForTesting(false); |
browser_shutdown::SetTryingToQuit(false); |
} |
@@ -231,13 +232,14 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
// 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(); |
+ keep_alive_.reset(new browser_lifetime::ScopedKeepAlive); |
#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(); |
+ // On ChromeOS shutdown, HandleAppExitingForPlatform() will call |
+ // browser_lifetime::DecrementKeepAliveCount() because it assumes the aura |
+ // shell called browser_lifetime::IncrementKeepAliveCount(). Simulate the |
+ // call here. |
+ browser_lifetime::IncrementKeepAliveCount(); |
#endif |
// Create our test BackgroundModeManager. |
@@ -265,8 +267,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(); |
+ // Matching the keep_alive_.reset(...) in SetUp(). |
+ keep_alive_.reset(); |
// TestBackgroundModeManager has dependencies on the infrastructure. |
// It should get cleared first. |
@@ -341,6 +343,8 @@ class BackgroundModeManagerWithExtensionsTest : public testing::Test { |
chromeos::ScopedTestUserManager test_user_manager_; |
#endif |
+ scoped_ptr<browser_lifetime::ScopedKeepAlive> keep_alive_; |
+ |
DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); |
}; |
@@ -349,7 +353,7 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
AdvancedTestBackgroundModeManager manager( |
*command_line_, profile_manager_->profile_info_cache(), true); |
manager.RegisterProfile(profile_); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
// Mimic app load. |
EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
@@ -482,7 +486,7 @@ TEST_F(BackgroundModeManagerTest, MultiProfile) { |
*command_line_, profile_manager_->profile_info_cache(), true); |
manager.RegisterProfile(profile_); |
manager.RegisterProfile(profile2); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
// Install app, should show status tray icon. |
EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
@@ -532,7 +536,7 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { |
*command_line_, profile_manager_->profile_info_cache(), true); |
manager.RegisterProfile(profile_); |
manager.RegisterProfile(profile2); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
ProfileInfoCache* cache = profile_manager_->profile_info_cache(); |
EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
@@ -578,7 +582,7 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
AdvancedTestBackgroundModeManager manager( |
*command_line_, profile_manager_->profile_info_cache(), true); |
manager.RegisterProfile(profile_); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
// Install app, should show status tray icon. |
EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
@@ -596,7 +600,7 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
EXPECT_EQ(base::UTF8ToUTF16("p1"), |
manager.GetBackgroundModeData(profile_)->name()); |
- EXPECT_TRUE(chrome::WillKeepAlive()); |
+ EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
manager.RegisterProfile(profile2); |
EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
@@ -607,7 +611,7 @@ TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
manager.OnProfileWillBeRemoved(profile2->GetPath()); |
// Should still be in background mode after deleting profile. |
- EXPECT_TRUE(chrome::WillKeepAlive()); |
+ EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
// Check that the background mode data we think is in the map actually is. |
@@ -621,7 +625,7 @@ TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
AdvancedTestBackgroundModeManager manager( |
*command_line_, profile_manager_->profile_info_cache(), true); |
manager.RegisterProfile(profile_); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
// Install app, should show status tray icon. |
EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
@@ -635,11 +639,11 @@ TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
manager.GetBackgroundModeData(profile_)->name()); |
EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
- EXPECT_TRUE(chrome::WillKeepAlive()); |
+ EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
manager.SetBackgroundClientCountForProfile(profile_, 0); |
manager.OnProfileWillBeRemoved(profile_->GetPath()); |
Mock::VerifyAndClearExpectations(&manager); |
- EXPECT_FALSE(chrome::WillKeepAlive()); |
+ EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
} |
TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { |
@@ -818,72 +822,66 @@ TEST_F(BackgroundModeManagerWithExtensionsTest, |
EXPECT_TRUE(context_menu != NULL); |
// Background Profile Enable Checks |
- EXPECT_TRUE(context_menu->GetLabelAt(3) == base::UTF8ToUTF16("p1")); |
+ EXPECT_EQ(base::UTF8ToUTF16("p1"), |
+ context_menu->GetLabelAt(3)); |
EXPECT_TRUE( |
context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(3))); |
- EXPECT_TRUE(context_menu->GetCommandIdAt(3) == 4); |
+ EXPECT_EQ(4, context_menu->GetCommandIdAt(3)); |
- EXPECT_TRUE(context_menu->GetLabelAt(4) == base::UTF8ToUTF16("p2")); |
+ EXPECT_EQ(base::UTF8ToUTF16("p2"), context_menu->GetLabelAt(4)); |
EXPECT_TRUE( |
context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(4))); |
- EXPECT_TRUE(context_menu->GetCommandIdAt(4) == 8); |
+ EXPECT_EQ(8, context_menu->GetCommandIdAt(4)); |
// Profile 1 Submenu Checks |
StatusIconMenuModel* profile1_submenu = |
static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(3)); |
- EXPECT_TRUE( |
- profile1_submenu->GetLabelAt(0) == |
- base::UTF8ToUTF16("Component Extension")); |
+ EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
+ profile1_submenu->GetLabelAt(0)); |
EXPECT_FALSE( |
profile1_submenu->IsCommandIdEnabled( |
profile1_submenu->GetCommandIdAt(0))); |
- EXPECT_TRUE(profile1_submenu->GetCommandIdAt(0) == 0); |
- EXPECT_TRUE( |
- profile1_submenu->GetLabelAt(1) == |
- base::UTF8ToUTF16("Component Extension with Options")); |
+ EXPECT_EQ(0, profile1_submenu->GetCommandIdAt(0)); |
+ EXPECT_EQ(base::UTF8ToUTF16("Component Extension with Options"), |
+ profile1_submenu->GetLabelAt(1)); |
EXPECT_TRUE( |
profile1_submenu->IsCommandIdEnabled( |
profile1_submenu->GetCommandIdAt(1))); |
- EXPECT_TRUE(profile1_submenu->GetCommandIdAt(1) == 1); |
- EXPECT_TRUE( |
- profile1_submenu->GetLabelAt(2) == |
- base::UTF8ToUTF16("Regular Extension")); |
+ EXPECT_EQ(1, profile1_submenu->GetCommandIdAt(1)); |
+ EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
+ profile1_submenu->GetLabelAt(2)); |
EXPECT_TRUE( |
profile1_submenu->IsCommandIdEnabled( |
profile1_submenu->GetCommandIdAt(2))); |
- EXPECT_TRUE(profile1_submenu->GetCommandIdAt(2) == 2); |
- EXPECT_TRUE( |
- profile1_submenu->GetLabelAt(3) == |
- base::UTF8ToUTF16("Regular Extension with Options")); |
+ EXPECT_EQ(2, profile1_submenu->GetCommandIdAt(2)); |
+ EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
+ profile1_submenu->GetLabelAt(3)); |
EXPECT_TRUE( |
profile1_submenu->IsCommandIdEnabled( |
profile1_submenu->GetCommandIdAt(3))); |
- EXPECT_TRUE(profile1_submenu->GetCommandIdAt(3) == 3); |
+ EXPECT_EQ(3, profile1_submenu->GetCommandIdAt(3)); |
// Profile 2 Submenu Checks |
StatusIconMenuModel* profile2_submenu = |
static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(4)); |
- EXPECT_TRUE( |
- profile2_submenu->GetLabelAt(0) == |
- base::UTF8ToUTF16("Component Extension")); |
+ EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
+ profile2_submenu->GetLabelAt(0)); |
EXPECT_FALSE( |
profile2_submenu->IsCommandIdEnabled( |
profile2_submenu->GetCommandIdAt(0))); |
- EXPECT_TRUE(profile2_submenu->GetCommandIdAt(0) == 5); |
- EXPECT_TRUE( |
- profile2_submenu->GetLabelAt(1) == |
- base::UTF8ToUTF16("Regular Extension")); |
+ EXPECT_EQ(5, profile2_submenu->GetCommandIdAt(0)); |
+ EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
+ profile2_submenu->GetLabelAt(1)); |
EXPECT_TRUE( |
profile2_submenu->IsCommandIdEnabled( |
profile2_submenu->GetCommandIdAt(1))); |
- EXPECT_TRUE(profile2_submenu->GetCommandIdAt(1) == 6); |
- EXPECT_TRUE( |
- profile2_submenu->GetLabelAt(2) == |
- base::UTF8ToUTF16("Regular Extension with Options")); |
+ EXPECT_EQ(6, profile2_submenu->GetCommandIdAt(1)); |
+ EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
+ profile2_submenu->GetLabelAt(2)); |
EXPECT_TRUE( |
profile2_submenu->IsCommandIdEnabled( |
profile2_submenu->GetCommandIdAt(2))); |
- EXPECT_TRUE(profile2_submenu->GetCommandIdAt(2) == 7); |
+ EXPECT_EQ(7, profile2_submenu->GetCommandIdAt(2)); |
// Model Adapter Checks for crbug.com/315164 |
// P1: Profile 1 Menu Item |