| 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" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 // App installs while background mode is disabled should do nothing. | 357 // App installs while background mode is disabled should do nothing. |
| 358 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { | 358 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { |
| 359 AdvancedTestBackgroundModeManager manager( | 359 AdvancedTestBackgroundModeManager manager( |
| 360 *command_line_, profile_manager_->profile_info_cache(), true); | 360 *command_line_, profile_manager_->profile_info_cache(), true); |
| 361 manager.RegisterProfile(profile_); | 361 manager.RegisterProfile(profile_); |
| 362 | 362 |
| 363 // Turn off background mode (shouldn't explicitly disable launch-on-startup as | 363 // Turn off background mode (shouldn't explicitly disable launch-on-startup as |
| 364 // the app-count is zero and launch-on-startup shouldn't be considered on). | 364 // the app-count is zero and launch-on-startup shouldn't be considered on). |
| 365 manager.SetEnabled(false); | 365 manager.SetEnabled(false); |
| 366 manager.DisableBackgroundMode(); | |
| 367 AssertBackgroundModeInactive(manager); | 366 AssertBackgroundModeInactive(manager); |
| 368 | 367 |
| 369 // Status tray icons will not be created, launch on startup status will not | 368 // Status tray icons will not be created, launch on startup status will not |
| 370 // be modified. | 369 // be modified. |
| 371 manager.OnBackgroundAppInstalled(NULL); | 370 manager.OnBackgroundAppInstalled(NULL); |
| 372 manager.SetBackgroundAppCountForProfile(profile_, 1); | 371 manager.SetBackgroundAppCountForProfile(profile_, 1); |
| 373 manager.OnApplicationListChanged(profile_); | 372 manager.OnApplicationListChanged(profile_); |
| 374 AssertBackgroundModeInactive(manager); | 373 AssertBackgroundModeInactive(manager); |
| 375 | 374 |
| 376 manager.SetBackgroundAppCountForProfile(profile_, 0); | 375 manager.SetBackgroundAppCountForProfile(profile_, 0); |
| 377 manager.OnApplicationListChanged(profile_); | 376 manager.OnApplicationListChanged(profile_); |
| 378 AssertBackgroundModeInactive(manager); | 377 AssertBackgroundModeInactive(manager); |
| 379 | 378 |
| 380 // Re-enable background mode (shouldn't actually enable launch-on-startup as | 379 // Re-enable background mode (shouldn't actually enable launch-on-startup as |
| 381 // the app-count is zero). | 380 // the app-count is zero). |
| 382 manager.SetEnabled(true); | 381 manager.SetEnabled(true); |
| 383 manager.EnableBackgroundMode(); | |
| 384 AssertBackgroundModeInactive(manager); | 382 AssertBackgroundModeInactive(manager); |
| 385 } | 383 } |
| 386 | 384 |
| 387 | 385 |
| 388 // App installs while disabled should do nothing until background mode is | 386 // App installs while disabled should do nothing until background mode is |
| 389 // enabled.. | 387 // enabled.. |
| 390 TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) { | 388 TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) { |
| 391 AdvancedTestBackgroundModeManager manager( | 389 AdvancedTestBackgroundModeManager manager( |
| 392 *command_line_, profile_manager_->profile_info_cache(), true); | 390 *command_line_, profile_manager_->profile_info_cache(), true); |
| 393 manager.RegisterProfile(profile_); | 391 manager.RegisterProfile(profile_); |
| 394 | 392 |
| 395 // Install app, should show status tray icon. | 393 // Install app, should show status tray icon. |
| 396 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 394 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 397 manager.OnBackgroundAppInstalled(NULL); | 395 manager.OnBackgroundAppInstalled(NULL); |
| 398 // OnBackgroundAppInstalled does not actually add an app to the | 396 // OnBackgroundAppInstalled does not actually add an app to the |
| 399 // BackgroundApplicationListModel which would result in another | 397 // BackgroundApplicationListModel which would result in another |
| 400 // call to CreateStatusTray. | 398 // call to CreateStatusTray. |
| 401 manager.SetBackgroundAppCountForProfile(profile_, 1); | 399 manager.SetBackgroundAppCountForProfile(profile_, 1); |
| 402 manager.OnApplicationListChanged(profile_); | 400 manager.OnApplicationListChanged(profile_); |
| 403 AssertBackgroundModeActive(manager); | 401 AssertBackgroundModeActive(manager); |
| 404 Mock::VerifyAndClearExpectations(&manager); | 402 Mock::VerifyAndClearExpectations(&manager); |
| 405 | 403 |
| 406 // Turn off background mode - should hide status tray icon. | 404 // Turn off background mode - should hide status tray icon. |
| 407 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 405 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
| 408 manager.SetEnabled(false); | 406 manager.SetEnabled(false); |
| 409 manager.DisableBackgroundMode(); | |
| 410 Mock::VerifyAndClearExpectations(&manager); | 407 Mock::VerifyAndClearExpectations(&manager); |
| 411 AssertBackgroundModeInactive(manager); | 408 AssertBackgroundModeInactive(manager); |
| 412 | 409 |
| 413 // Turn back on background mode - again, no status tray icon | 410 // Turn back on background mode - again, no status tray icon |
| 414 // will show up since we didn't actually add anything to the list. | 411 // will show up since we didn't actually add anything to the list. |
| 415 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 412 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 416 manager.SetEnabled(true); | 413 manager.SetEnabled(true); |
| 417 manager.EnableBackgroundMode(); | |
| 418 Mock::VerifyAndClearExpectations(&manager); | 414 Mock::VerifyAndClearExpectations(&manager); |
| 419 AssertBackgroundModeActive(manager); | 415 AssertBackgroundModeActive(manager); |
| 420 | 416 |
| 421 // Uninstall app, should hide status tray icon again. | 417 // Uninstall app, should hide status tray icon again. |
| 422 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 418 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
| 423 manager.SetBackgroundAppCountForProfile(profile_, 0); | 419 manager.SetBackgroundAppCountForProfile(profile_, 0); |
| 424 manager.OnApplicationListChanged(profile_); | 420 manager.OnApplicationListChanged(profile_); |
| 425 Mock::VerifyAndClearExpectations(&manager); | 421 Mock::VerifyAndClearExpectations(&manager); |
| 426 AssertBackgroundModeInactive(manager); | 422 AssertBackgroundModeInactive(manager); |
| 427 } | 423 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 444 | 440 |
| 445 // Install app for other profile, should show other status tray icon. | 441 // Install app for other profile, should show other status tray icon. |
| 446 manager.OnBackgroundAppInstalled(NULL); | 442 manager.OnBackgroundAppInstalled(NULL); |
| 447 manager.SetBackgroundAppCountForProfile(profile2, 2); | 443 manager.SetBackgroundAppCountForProfile(profile2, 2); |
| 448 manager.OnApplicationListChanged(profile2); | 444 manager.OnApplicationListChanged(profile2); |
| 449 AssertBackgroundModeActive(manager); | 445 AssertBackgroundModeActive(manager); |
| 450 | 446 |
| 451 // Should hide both status tray icons. | 447 // Should hide both status tray icons. |
| 452 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); | 448 EXPECT_CALL(manager, EnableLaunchOnStartup(false)).Times(Exactly(1)); |
| 453 manager.SetEnabled(false); | 449 manager.SetEnabled(false); |
| 454 manager.DisableBackgroundMode(); | |
| 455 Mock::VerifyAndClearExpectations(&manager); | 450 Mock::VerifyAndClearExpectations(&manager); |
| 456 AssertBackgroundModeInactive(manager); | 451 AssertBackgroundModeInactive(manager); |
| 457 | 452 |
| 458 // Turn back on background mode - should show both status tray icons. | 453 // Turn back on background mode - should show both status tray icons. |
| 459 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); | 454 EXPECT_CALL(manager, EnableLaunchOnStartup(true)).Times(Exactly(1)); |
| 460 manager.SetEnabled(true); | 455 manager.SetEnabled(true); |
| 461 manager.EnableBackgroundMode(); | |
| 462 Mock::VerifyAndClearExpectations(&manager); | 456 Mock::VerifyAndClearExpectations(&manager); |
| 463 AssertBackgroundModeActive(manager); | 457 AssertBackgroundModeActive(manager); |
| 464 | 458 |
| 465 manager.SetBackgroundAppCountForProfile(profile_, 0); | 459 manager.SetBackgroundAppCountForProfile(profile_, 0); |
| 466 manager.OnApplicationListChanged(profile_); | 460 manager.OnApplicationListChanged(profile_); |
| 467 manager.SetBackgroundAppCountForProfile(profile2, 1); | 461 manager.SetBackgroundAppCountForProfile(profile2, 1); |
| 468 manager.OnApplicationListChanged(profile2); | 462 manager.OnApplicationListChanged(profile2); |
| 469 // There is still one background app alive | 463 // There is still one background app alive |
| 470 AssertBackgroundModeActive(manager); | 464 AssertBackgroundModeActive(manager); |
| 471 // Verify the implicit expectations of no calls on this StrictMock. | 465 // Verify the implicit expectations of no calls on this StrictMock. |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 } | 921 } |
| 928 service->AddExtension(upgraded_bg_ext.get()); | 922 service->AddExtension(upgraded_bg_ext.get()); |
| 929 Mock::VerifyAndClearExpectations(manager_.get()); | 923 Mock::VerifyAndClearExpectations(manager_.get()); |
| 930 EXPECT_FALSE(manager_->HasShownBalloon()); | 924 EXPECT_FALSE(manager_->HasShownBalloon()); |
| 931 | 925 |
| 932 // Upgrading an extension that didn't have background to one that does should | 926 // Upgrading an extension that didn't have background to one that does should |
| 933 // show the balloon. | 927 // show the balloon. |
| 934 service->AddExtension(upgraded_no_bg_ext_has_bg.get()); | 928 service->AddExtension(upgraded_no_bg_ext_has_bg.get()); |
| 935 EXPECT_TRUE(manager_->HasShownBalloon()); | 929 EXPECT_TRUE(manager_->HasShownBalloon()); |
| 936 } | 930 } |
| OLD | NEW |