| 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 browser_lifetime::IncrementKeepAliveCount(); |
| 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 call to IncrementKeepAliveCount in SetUp(). |
| 269 chrome::DecrementKeepAliveCount(); | 271 browser_lifetime::DecrementKeepAliveCount(); |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 #endif | 344 #endif |
| 343 | 345 |
| 344 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); | 346 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerWithExtensionsTest); |
| 345 }; | 347 }; |
| 346 | 348 |
| 347 | 349 |
| 348 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 350 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
| 349 AdvancedTestBackgroundModeManager manager( | 351 AdvancedTestBackgroundModeManager manager( |
| 350 *command_line_, profile_manager_->profile_info_cache(), true); | 352 *command_line_, profile_manager_->profile_info_cache(), true); |
| 351 manager.RegisterProfile(profile_); | 353 manager.RegisterProfile(profile_); |
| 352 EXPECT_FALSE(chrome::WillKeepAlive()); | 354 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 353 | 355 |
| 354 // Mimic app load. | 356 // Mimic app load. |
| 355 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 357 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 356 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 358 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
| 357 manager.SetBackgroundClientCountForProfile(profile_, 1); | 359 manager.SetBackgroundClientCountForProfile(profile_, 1); |
| 358 manager.OnApplicationListChanged(profile_); | 360 manager.OnApplicationListChanged(profile_); |
| 359 Mock::VerifyAndClearExpectations(&manager); | 361 Mock::VerifyAndClearExpectations(&manager); |
| 360 AssertBackgroundModeActive(manager); | 362 AssertBackgroundModeActive(manager); |
| 361 | 363 |
| 362 manager.SuspendBackgroundMode(); | 364 manager.SuspendBackgroundMode(); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 Mock::VerifyAndClearExpectations(&manager); | 477 Mock::VerifyAndClearExpectations(&manager); |
| 476 AssertBackgroundModeInactive(manager); | 478 AssertBackgroundModeInactive(manager); |
| 477 } | 479 } |
| 478 | 480 |
| 479 TEST_F(BackgroundModeManagerTest, MultiProfile) { | 481 TEST_F(BackgroundModeManagerTest, MultiProfile) { |
| 480 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 482 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
| 481 AdvancedTestBackgroundModeManager manager( | 483 AdvancedTestBackgroundModeManager manager( |
| 482 *command_line_, profile_manager_->profile_info_cache(), true); | 484 *command_line_, profile_manager_->profile_info_cache(), true); |
| 483 manager.RegisterProfile(profile_); | 485 manager.RegisterProfile(profile_); |
| 484 manager.RegisterProfile(profile2); | 486 manager.RegisterProfile(profile2); |
| 485 EXPECT_FALSE(chrome::WillKeepAlive()); | 487 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 486 | 488 |
| 487 // Install app, should show status tray icon. | 489 // Install app, should show status tray icon. |
| 488 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 490 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 489 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 491 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
| 490 manager.SetBackgroundClientCountForProfile(profile_, 1); | 492 manager.SetBackgroundClientCountForProfile(profile_, 1); |
| 491 manager.OnApplicationListChanged(profile_); | 493 manager.OnApplicationListChanged(profile_); |
| 492 Mock::VerifyAndClearExpectations(&manager); | 494 Mock::VerifyAndClearExpectations(&manager); |
| 493 AssertBackgroundModeActive(manager); | 495 AssertBackgroundModeActive(manager); |
| 494 | 496 |
| 495 // Install app for other profile, should show other status tray icon. | 497 // Install app for other profile, should show other status tray icon. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 525 Mock::VerifyAndClearExpectations(&manager); | 527 Mock::VerifyAndClearExpectations(&manager); |
| 526 AssertBackgroundModeInactive(manager); | 528 AssertBackgroundModeInactive(manager); |
| 527 } | 529 } |
| 528 | 530 |
| 529 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { | 531 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheStorage) { |
| 530 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 532 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
| 531 AdvancedTestBackgroundModeManager manager( | 533 AdvancedTestBackgroundModeManager manager( |
| 532 *command_line_, profile_manager_->profile_info_cache(), true); | 534 *command_line_, profile_manager_->profile_info_cache(), true); |
| 533 manager.RegisterProfile(profile_); | 535 manager.RegisterProfile(profile_); |
| 534 manager.RegisterProfile(profile2); | 536 manager.RegisterProfile(profile2); |
| 535 EXPECT_FALSE(chrome::WillKeepAlive()); | 537 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 536 | 538 |
| 537 ProfileInfoCache* cache = profile_manager_->profile_info_cache(); | 539 ProfileInfoCache* cache = profile_manager_->profile_info_cache(); |
| 538 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 540 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
| 539 | 541 |
| 540 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); | 542 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(0)); |
| 541 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); | 543 EXPECT_FALSE(cache->GetBackgroundStatusOfProfileAtIndex(1)); |
| 542 | 544 |
| 543 // Install app, should show status tray icon. | 545 // Install app, should show status tray icon. |
| 544 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 546 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 545 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 547 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 571 | 573 |
| 572 // Even though neither has background status on, there should still be two | 574 // Even though neither has background status on, there should still be two |
| 573 // profiles in the cache. | 575 // profiles in the cache. |
| 574 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); | 576 EXPECT_EQ(2u, cache->GetNumberOfProfiles()); |
| 575 } | 577 } |
| 576 | 578 |
| 577 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { | 579 TEST_F(BackgroundModeManagerTest, ProfileInfoCacheObserver) { |
| 578 AdvancedTestBackgroundModeManager manager( | 580 AdvancedTestBackgroundModeManager manager( |
| 579 *command_line_, profile_manager_->profile_info_cache(), true); | 581 *command_line_, profile_manager_->profile_info_cache(), true); |
| 580 manager.RegisterProfile(profile_); | 582 manager.RegisterProfile(profile_); |
| 581 EXPECT_FALSE(chrome::WillKeepAlive()); | 583 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 582 | 584 |
| 583 // Install app, should show status tray icon. | 585 // Install app, should show status tray icon. |
| 584 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 586 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 585 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 587 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
| 586 manager.SetBackgroundClientCountForProfile(profile_, 1); | 588 manager.SetBackgroundClientCountForProfile(profile_, 1); |
| 587 manager.OnApplicationListChanged(profile_); | 589 manager.OnApplicationListChanged(profile_); |
| 588 Mock::VerifyAndClearExpectations(&manager); | 590 Mock::VerifyAndClearExpectations(&manager); |
| 589 | 591 |
| 590 // Background mode should remain active for the remainder of this test. | 592 // Background mode should remain active for the remainder of this test. |
| 591 | 593 |
| 592 manager.OnProfileNameChanged( | 594 manager.OnProfileNameChanged( |
| 593 profile_->GetPath(), | 595 profile_->GetPath(), |
| 594 manager.GetBackgroundModeData(profile_)->name()); | 596 manager.GetBackgroundModeData(profile_)->name()); |
| 595 | 597 |
| 596 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 598 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
| 597 manager.GetBackgroundModeData(profile_)->name()); | 599 manager.GetBackgroundModeData(profile_)->name()); |
| 598 | 600 |
| 599 EXPECT_TRUE(chrome::WillKeepAlive()); | 601 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
| 600 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); | 602 TestingProfile* profile2 = profile_manager_->CreateTestingProfile("p2"); |
| 601 manager.RegisterProfile(profile2); | 603 manager.RegisterProfile(profile2); |
| 602 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); | 604 EXPECT_EQ(2, manager.NumberOfBackgroundModeData()); |
| 603 | 605 |
| 604 manager.OnProfileAdded(profile2->GetPath()); | 606 manager.OnProfileAdded(profile2->GetPath()); |
| 605 EXPECT_EQ(base::UTF8ToUTF16("p2"), | 607 EXPECT_EQ(base::UTF8ToUTF16("p2"), |
| 606 manager.GetBackgroundModeData(profile2)->name()); | 608 manager.GetBackgroundModeData(profile2)->name()); |
| 607 | 609 |
| 608 manager.OnProfileWillBeRemoved(profile2->GetPath()); | 610 manager.OnProfileWillBeRemoved(profile2->GetPath()); |
| 609 // Should still be in background mode after deleting profile. | 611 // Should still be in background mode after deleting profile. |
| 610 EXPECT_TRUE(chrome::WillKeepAlive()); | 612 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
| 611 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); | 613 EXPECT_EQ(1, manager.NumberOfBackgroundModeData()); |
| 612 | 614 |
| 613 // Check that the background mode data we think is in the map actually is. | 615 // Check that the background mode data we think is in the map actually is. |
| 614 EXPECT_EQ(base::UTF8ToUTF16("p1"), | 616 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
| 615 manager.GetBackgroundModeData(profile_)->name()); | 617 manager.GetBackgroundModeData(profile_)->name()); |
| 616 } | 618 } |
| 617 | 619 |
| 618 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { | 620 TEST_F(BackgroundModeManagerTest, DeleteBackgroundProfile) { |
| 619 // Tests whether deleting the only profile when it is a BG profile works | 621 // Tests whether deleting the only profile when it is a BG profile works |
| 620 // or not (http://crbug.com/346214). | 622 // or not (http://crbug.com/346214). |
| 621 AdvancedTestBackgroundModeManager manager( | 623 AdvancedTestBackgroundModeManager manager( |
| 622 *command_line_, profile_manager_->profile_info_cache(), true); | 624 *command_line_, profile_manager_->profile_info_cache(), true); |
| 623 manager.RegisterProfile(profile_); | 625 manager.RegisterProfile(profile_); |
| 624 EXPECT_FALSE(chrome::WillKeepAlive()); | 626 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 625 | 627 |
| 626 // Install app, should show status tray icon. | 628 // Install app, should show status tray icon. |
| 627 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 629 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 628 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); | 630 manager.OnBackgroundClientInstalled(base::UTF8ToUTF16("name")); |
| 629 manager.SetBackgroundClientCountForProfile(profile_, 1); | 631 manager.SetBackgroundClientCountForProfile(profile_, 1); |
| 630 manager.OnApplicationListChanged(profile_); | 632 manager.OnApplicationListChanged(profile_); |
| 631 Mock::VerifyAndClearExpectations(&manager); | 633 Mock::VerifyAndClearExpectations(&manager); |
| 632 | 634 |
| 633 manager.OnProfileNameChanged( | 635 manager.OnProfileNameChanged( |
| 634 profile_->GetPath(), | 636 profile_->GetPath(), |
| 635 manager.GetBackgroundModeData(profile_)->name()); | 637 manager.GetBackgroundModeData(profile_)->name()); |
| 636 | 638 |
| 637 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 639 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
| 638 EXPECT_TRUE(chrome::WillKeepAlive()); | 640 EXPECT_TRUE(browser_lifetime::WillKeepAlive()); |
| 639 manager.SetBackgroundClientCountForProfile(profile_, 0); | 641 manager.SetBackgroundClientCountForProfile(profile_, 0); |
| 640 manager.OnProfileWillBeRemoved(profile_->GetPath()); | 642 manager.OnProfileWillBeRemoved(profile_->GetPath()); |
| 641 Mock::VerifyAndClearExpectations(&manager); | 643 Mock::VerifyAndClearExpectations(&manager); |
| 642 EXPECT_FALSE(chrome::WillKeepAlive()); | 644 EXPECT_FALSE(browser_lifetime::WillKeepAlive()); |
| 643 } | 645 } |
| 644 | 646 |
| 645 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { | 647 TEST_F(BackgroundModeManagerTest, DisableBackgroundModeUnderTestFlag) { |
| 646 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 648 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
| 647 AdvancedTestBackgroundModeManager manager( | 649 AdvancedTestBackgroundModeManager manager( |
| 648 *command_line_, profile_manager_->profile_info_cache(), true); | 650 *command_line_, profile_manager_->profile_info_cache(), true); |
| 649 manager.RegisterProfile(profile_); | 651 manager.RegisterProfile(profile_); |
| 650 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); | 652 EXPECT_TRUE(manager.ShouldBeInBackgroundMode()); |
| 651 | 653 |
| 652 // No enable-launch-on-startup calls expected yet. | 654 // 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()); | 813 service2->AddExtension(regular_extension_with_options.get()); |
| 812 | 814 |
| 813 manager_->RegisterProfile(profile2); | 815 manager_->RegisterProfile(profile2); |
| 814 | 816 |
| 815 manager_->status_icon_ = new TestStatusIcon(); | 817 manager_->status_icon_ = new TestStatusIcon(); |
| 816 manager_->UpdateStatusTrayIconContextMenu(); | 818 manager_->UpdateStatusTrayIconContextMenu(); |
| 817 StatusIconMenuModel* context_menu = manager_->context_menu_; | 819 StatusIconMenuModel* context_menu = manager_->context_menu_; |
| 818 EXPECT_TRUE(context_menu != NULL); | 820 EXPECT_TRUE(context_menu != NULL); |
| 819 | 821 |
| 820 // Background Profile Enable Checks | 822 // Background Profile Enable Checks |
| 821 EXPECT_TRUE(context_menu->GetLabelAt(3) == base::UTF8ToUTF16("p1")); | 823 EXPECT_EQ(base::UTF8ToUTF16("p1"), |
| 824 context_menu->GetLabelAt(3)); |
| 822 EXPECT_TRUE( | 825 EXPECT_TRUE( |
| 823 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(3))); | 826 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(3))); |
| 824 EXPECT_TRUE(context_menu->GetCommandIdAt(3) == 4); | 827 EXPECT_EQ(4, context_menu->GetCommandIdAt(3)); |
| 825 | 828 |
| 826 EXPECT_TRUE(context_menu->GetLabelAt(4) == base::UTF8ToUTF16("p2")); | 829 EXPECT_EQ(base::UTF8ToUTF16("p2"), context_menu->GetLabelAt(4)); |
| 827 EXPECT_TRUE( | 830 EXPECT_TRUE( |
| 828 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(4))); | 831 context_menu->IsCommandIdEnabled(context_menu->GetCommandIdAt(4))); |
| 829 EXPECT_TRUE(context_menu->GetCommandIdAt(4) == 8); | 832 EXPECT_EQ(8, context_menu->GetCommandIdAt(4)); |
| 830 | 833 |
| 831 // Profile 1 Submenu Checks | 834 // Profile 1 Submenu Checks |
| 832 StatusIconMenuModel* profile1_submenu = | 835 StatusIconMenuModel* profile1_submenu = |
| 833 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(3)); | 836 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(3)); |
| 834 EXPECT_TRUE( | 837 EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
| 835 profile1_submenu->GetLabelAt(0) == | 838 profile1_submenu->GetLabelAt(0)); |
| 836 base::UTF8ToUTF16("Component Extension")); | |
| 837 EXPECT_FALSE( | 839 EXPECT_FALSE( |
| 838 profile1_submenu->IsCommandIdEnabled( | 840 profile1_submenu->IsCommandIdEnabled( |
| 839 profile1_submenu->GetCommandIdAt(0))); | 841 profile1_submenu->GetCommandIdAt(0))); |
| 840 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(0) == 0); | 842 EXPECT_EQ(0, profile1_submenu->GetCommandIdAt(0)); |
| 841 EXPECT_TRUE( | 843 EXPECT_EQ(base::UTF8ToUTF16("Component Extension with Options"), |
| 842 profile1_submenu->GetLabelAt(1) == | 844 profile1_submenu->GetLabelAt(1)); |
| 843 base::UTF8ToUTF16("Component Extension with Options")); | |
| 844 EXPECT_TRUE( | 845 EXPECT_TRUE( |
| 845 profile1_submenu->IsCommandIdEnabled( | 846 profile1_submenu->IsCommandIdEnabled( |
| 846 profile1_submenu->GetCommandIdAt(1))); | 847 profile1_submenu->GetCommandIdAt(1))); |
| 847 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(1) == 1); | 848 EXPECT_EQ(1, profile1_submenu->GetCommandIdAt(1)); |
| 848 EXPECT_TRUE( | 849 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
| 849 profile1_submenu->GetLabelAt(2) == | 850 profile1_submenu->GetLabelAt(2)); |
| 850 base::UTF8ToUTF16("Regular Extension")); | |
| 851 EXPECT_TRUE( | 851 EXPECT_TRUE( |
| 852 profile1_submenu->IsCommandIdEnabled( | 852 profile1_submenu->IsCommandIdEnabled( |
| 853 profile1_submenu->GetCommandIdAt(2))); | 853 profile1_submenu->GetCommandIdAt(2))); |
| 854 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(2) == 2); | 854 EXPECT_EQ(2, profile1_submenu->GetCommandIdAt(2)); |
| 855 EXPECT_TRUE( | 855 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
| 856 profile1_submenu->GetLabelAt(3) == | 856 profile1_submenu->GetLabelAt(3)); |
| 857 base::UTF8ToUTF16("Regular Extension with Options")); | |
| 858 EXPECT_TRUE( | 857 EXPECT_TRUE( |
| 859 profile1_submenu->IsCommandIdEnabled( | 858 profile1_submenu->IsCommandIdEnabled( |
| 860 profile1_submenu->GetCommandIdAt(3))); | 859 profile1_submenu->GetCommandIdAt(3))); |
| 861 EXPECT_TRUE(profile1_submenu->GetCommandIdAt(3) == 3); | 860 EXPECT_EQ(3, profile1_submenu->GetCommandIdAt(3)); |
| 862 | 861 |
| 863 // Profile 2 Submenu Checks | 862 // Profile 2 Submenu Checks |
| 864 StatusIconMenuModel* profile2_submenu = | 863 StatusIconMenuModel* profile2_submenu = |
| 865 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(4)); | 864 static_cast<StatusIconMenuModel*>(context_menu->GetSubmenuModelAt(4)); |
| 866 EXPECT_TRUE( | 865 EXPECT_EQ(base::UTF8ToUTF16("Component Extension"), |
| 867 profile2_submenu->GetLabelAt(0) == | 866 profile2_submenu->GetLabelAt(0)); |
| 868 base::UTF8ToUTF16("Component Extension")); | |
| 869 EXPECT_FALSE( | 867 EXPECT_FALSE( |
| 870 profile2_submenu->IsCommandIdEnabled( | 868 profile2_submenu->IsCommandIdEnabled( |
| 871 profile2_submenu->GetCommandIdAt(0))); | 869 profile2_submenu->GetCommandIdAt(0))); |
| 872 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(0) == 5); | 870 EXPECT_EQ(5, profile2_submenu->GetCommandIdAt(0)); |
| 873 EXPECT_TRUE( | 871 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension"), |
| 874 profile2_submenu->GetLabelAt(1) == | 872 profile2_submenu->GetLabelAt(1)); |
| 875 base::UTF8ToUTF16("Regular Extension")); | |
| 876 EXPECT_TRUE( | 873 EXPECT_TRUE( |
| 877 profile2_submenu->IsCommandIdEnabled( | 874 profile2_submenu->IsCommandIdEnabled( |
| 878 profile2_submenu->GetCommandIdAt(1))); | 875 profile2_submenu->GetCommandIdAt(1))); |
| 879 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(1) == 6); | 876 EXPECT_EQ(6, profile2_submenu->GetCommandIdAt(1)); |
| 880 EXPECT_TRUE( | 877 EXPECT_EQ(base::UTF8ToUTF16("Regular Extension with Options"), |
| 881 profile2_submenu->GetLabelAt(2) == | 878 profile2_submenu->GetLabelAt(2)); |
| 882 base::UTF8ToUTF16("Regular Extension with Options")); | |
| 883 EXPECT_TRUE( | 879 EXPECT_TRUE( |
| 884 profile2_submenu->IsCommandIdEnabled( | 880 profile2_submenu->IsCommandIdEnabled( |
| 885 profile2_submenu->GetCommandIdAt(2))); | 881 profile2_submenu->GetCommandIdAt(2))); |
| 886 EXPECT_TRUE(profile2_submenu->GetCommandIdAt(2) == 7); | 882 EXPECT_EQ(7, profile2_submenu->GetCommandIdAt(2)); |
| 887 | 883 |
| 888 // Model Adapter Checks for crbug.com/315164 | 884 // Model Adapter Checks for crbug.com/315164 |
| 889 // P1: Profile 1 Menu Item | 885 // P1: Profile 1 Menu Item |
| 890 // P2: Profile 2 Menu Item | 886 // P2: Profile 2 Menu Item |
| 891 // CE: Component Extension Menu Item | 887 // CE: Component Extension Menu Item |
| 892 // CEO: Component Extenison with Options Menu Item | 888 // CEO: Component Extenison with Options Menu Item |
| 893 // RE: Regular Extension Menu Item | 889 // RE: Regular Extension Menu Item |
| 894 // REO: Regular Extension with Options Menu Item | 890 // REO: Regular Extension with Options Menu Item |
| 895 EXPECT_FALSE(IsCommandEnabled(context_menu, 0)); // P1 - CE | 891 EXPECT_FALSE(IsCommandEnabled(context_menu, 0)); // P1 - CE |
| 896 EXPECT_TRUE(IsCommandEnabled(context_menu, 1)); // P1 - CEO | 892 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 | 1025 // When the background mode pref is enabled and there are pending triggers |
| 1030 // they will be registered and the user will be notified. | 1026 // they will be registered and the user will be notified. |
| 1031 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); | 1027 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); |
| 1032 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, | 1028 g_browser_process->local_state()->SetBoolean(prefs::kBackgroundModeEnabled, |
| 1033 true); | 1029 true); |
| 1034 Mock::VerifyAndClearExpectations(&manager); | 1030 Mock::VerifyAndClearExpectations(&manager); |
| 1035 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); | 1031 ASSERT_EQ(1, manager.GetBackgroundClientCountForProfile(profile_)); |
| 1036 AssertBackgroundModeActive(manager); | 1032 AssertBackgroundModeActive(manager); |
| 1037 ASSERT_TRUE(manager.HasShownBalloon()); | 1033 ASSERT_TRUE(manager.HasShownBalloon()); |
| 1038 } | 1034 } |
| OLD | NEW |