OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/lock_screen_apps/state_controller.h" | 5 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/public/interfaces/tray_action.mojom.h" | 12 #include "ash/public/interfaces/tray_action.mojom.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/test/scoped_command_line.h" | 15 #include "base/test/scoped_command_line.h" |
16 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" | 16 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" |
17 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" | 17 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
20 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 21 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/test/base/browser_with_test_window_test.h" | 23 #include "chrome/test/base/browser_with_test_window_test.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 "components/session_manager/core/session_manager.h" | 27 #include "components/session_manager/core/session_manager.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 ASSERT_TRUE(profile_manager_.SetUp()); | 322 ASSERT_TRUE(profile_manager_.SetUp()); |
322 | 323 |
323 BrowserWithTestWindowTest::SetUp(); | 324 BrowserWithTestWindowTest::SetUp(); |
324 | 325 |
325 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); | 326 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); |
326 session_manager_->SetSessionState( | 327 session_manager_->SetSessionState( |
327 session_manager::SessionState::LOGIN_PRIMARY); | 328 session_manager::SessionState::LOGIN_PRIMARY); |
328 | 329 |
329 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); | 330 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); |
330 | 331 |
| 332 // Create fake lock screen app profile. |
| 333 lock_screen_profile_ = profile_manager_.CreateTestingProfile( |
| 334 chromeos::ProfileHelper::GetLockScreenAppProfileName()); |
| 335 |
| 336 InitExtensionSystem(profile()); |
| 337 InitExtensionSystem(lock_screen_profile()); |
| 338 |
| 339 std::unique_ptr<TestAppManager> app_manager = |
| 340 base::MakeUnique<TestAppManager>( |
| 341 &profile_, lock_screen_profile_->GetOriginalProfile()); |
| 342 app_manager_ = app_manager.get(); |
| 343 |
331 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); | 344 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); |
332 state_controller_->SetTrayActionPtrForTesting( | 345 state_controller_->SetTrayActionPtrForTesting( |
333 tray_action_.CreateInterfacePtrAndBind()); | 346 tray_action_.CreateInterfacePtrAndBind()); |
| 347 state_controller_->SetAppManagerForTesting(std::move(app_manager)); |
| 348 state_controller_->SetReadyCallbackForTesting(ready_waiter_.QuitClosure()); |
334 state_controller_->Initialize(); | 349 state_controller_->Initialize(); |
335 state_controller_->FlushTrayActionForTesting(); | 350 state_controller_->FlushTrayActionForTesting(); |
336 | 351 |
337 state_controller_->AddObserver(&observer_); | 352 state_controller_->AddObserver(&observer_); |
338 | |
339 // Create fake sign-in profile. | |
340 TestingProfile::Builder builder; | |
341 builder.SetPath( | |
342 profile_manager_.profiles_dir().AppendASCII(chrome::kInitialProfile)); | |
343 signin_profile_ = builder.BuildIncognito( | |
344 profile_manager_.CreateTestingProfile(chrome::kInitialProfile)); | |
345 | |
346 InitExtensionSystem(profile()); | |
347 InitExtensionSystem(signin_profile()); | |
348 | |
349 std::unique_ptr<TestAppManager> app_manager = | |
350 base::MakeUnique<TestAppManager>(&profile_, | |
351 signin_profile_->GetOriginalProfile()); | |
352 app_manager_ = app_manager.get(); | |
353 state_controller_->SetAppManagerForTesting(std::move(app_manager)); | |
354 } | 353 } |
355 | 354 |
356 void TearDown() override { | 355 void TearDown() override { |
357 extensions::ExtensionSystem::Get(profile())->Shutdown(); | 356 extensions::ExtensionSystem::Get(profile())->Shutdown(); |
358 extensions::ExtensionSystem::Get(signin_profile())->Shutdown(); | 357 extensions::ExtensionSystem::Get(lock_screen_profile())->Shutdown(); |
359 | 358 |
360 state_controller_->RemoveObserver(&observer_); | 359 state_controller_->RemoveObserver(&observer_); |
361 state_controller_.reset(); | 360 state_controller_.reset(); |
362 session_manager_.reset(); | 361 session_manager_.reset(); |
363 app_manager_ = nullptr; | 362 app_manager_ = nullptr; |
364 BrowserWithTestWindowTest::TearDown(); | 363 BrowserWithTestWindowTest::TearDown(); |
365 } | 364 } |
366 | 365 |
367 void InitExtensionSystem(Profile* profile) { | 366 void InitExtensionSystem(Profile* profile) { |
368 extensions::TestExtensionSystem* extension_system = | 367 extensions::TestExtensionSystem* extension_system = |
(...skipping 26 matching lines...) Expand all Loading... |
395 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE, | 394 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE, |
396 base::MakeUnique<ChromeAppDelegate>(true))); | 395 base::MakeUnique<ChromeAppDelegate>(true))); |
397 } | 396 } |
398 | 397 |
399 void ClearObservedStates() { | 398 void ClearObservedStates() { |
400 state_controller_->FlushTrayActionForTesting(); | 399 state_controller_->FlushTrayActionForTesting(); |
401 observer_.ClearObservedStates(); | 400 observer_.ClearObservedStates(); |
402 tray_action_.ClearObservedStates(); | 401 tray_action_.ClearObservedStates(); |
403 } | 402 } |
404 | 403 |
| 404 void SetPrimaryProfileAndWaitUntilReady() { |
| 405 state_controller_->SetPrimaryProfile(&profile_); |
| 406 ready_waiter_.Run(); |
| 407 } |
| 408 |
405 // Helper method to move state controller to the specified state. | 409 // Helper method to move state controller to the specified state. |
406 // Should be called at the begining of tests, at most once. | 410 // Should be called at the begining of tests, at most once. |
407 bool InitializeNoteTakingApp(TrayActionState target_state, | 411 bool InitializeNoteTakingApp(TrayActionState target_state, |
408 bool enable_app_launch) { | 412 bool enable_app_launch) { |
409 app_ = CreateTestNoteTakingApp(kTestAppId); | 413 app_ = CreateTestNoteTakingApp(kTestAppId); |
410 extensions::ExtensionSystem::Get(signin_profile()) | 414 extensions::ExtensionSystem::Get(lock_screen_profile()) |
411 ->extension_service() | 415 ->extension_service() |
412 ->AddExtension(app_.get()); | 416 ->AddExtension(app_.get()); |
413 | 417 |
414 app_manager_->SetInitialAppState(kTestAppId, enable_app_launch); | 418 app_manager_->SetInitialAppState(kTestAppId, enable_app_launch); |
415 state_controller_->SetPrimaryProfile(&profile_); | 419 SetPrimaryProfileAndWaitUntilReady(); |
416 | 420 |
417 if (target_state == TrayActionState::kNotAvailable) | 421 if (target_state == TrayActionState::kNotAvailable) |
418 return true; | 422 return true; |
419 | 423 |
420 session_manager_->SetSessionState(session_manager::SessionState::LOCKED); | 424 session_manager_->SetSessionState(session_manager::SessionState::LOCKED); |
421 if (app_manager_->state() != TestAppManager::State::kStarted) { | 425 if (app_manager_->state() != TestAppManager::State::kStarted) { |
422 ADD_FAILURE() << "Lock app manager Start not invoked."; | 426 ADD_FAILURE() << "Lock app manager Start not invoked."; |
423 return false; | 427 return false; |
424 } | 428 } |
425 | 429 |
(...skipping 13 matching lines...) Expand all Loading... |
439 ClearObservedStates(); | 443 ClearObservedStates(); |
440 | 444 |
441 if (state_controller_->GetLockScreenNoteState() != | 445 if (state_controller_->GetLockScreenNoteState() != |
442 TrayActionState::kLaunching) { | 446 TrayActionState::kLaunching) { |
443 ADD_FAILURE() << "Unable to move to launching state."; | 447 ADD_FAILURE() << "Unable to move to launching state."; |
444 return false; | 448 return false; |
445 } | 449 } |
446 if (target_state == TrayActionState::kLaunching) | 450 if (target_state == TrayActionState::kLaunching) |
447 return true; | 451 return true; |
448 | 452 |
449 app_window_ = CreateNoteTakingWindow(signin_profile(), app()); | 453 app_window_ = CreateNoteTakingWindow(lock_screen_profile(), app()); |
450 if (!app_window_->window()) { | 454 if (!app_window_->window()) { |
451 ADD_FAILURE() << "Not allowed to create app window."; | 455 ADD_FAILURE() << "Not allowed to create app window."; |
452 return false; | 456 return false; |
453 } | 457 } |
454 | 458 |
455 app_window()->Initialize(true /* shown */); | 459 app_window()->Initialize(true /* shown */); |
456 | 460 |
457 ClearObservedStates(); | 461 ClearObservedStates(); |
458 | 462 |
459 return state_controller()->GetLockScreenNoteState() == | 463 return state_controller()->GetLockScreenNoteState() == |
460 TrayActionState::kActive; | 464 TrayActionState::kActive; |
461 } | 465 } |
462 | 466 |
463 TestingProfile* profile() { return &profile_; } | 467 TestingProfile* profile() { return &profile_; } |
464 TestingProfile* signin_profile() { return signin_profile_; } | 468 TestingProfile* lock_screen_profile() { return lock_screen_profile_; } |
465 | 469 |
466 session_manager::SessionManager* session_manager() { | 470 session_manager::SessionManager* session_manager() { |
467 return session_manager_.get(); | 471 return session_manager_.get(); |
468 } | 472 } |
469 | 473 |
470 TestStateObserver* observer() { return &observer_; } | 474 TestStateObserver* observer() { return &observer_; } |
471 | 475 |
472 TestTrayAction* tray_action() { return &tray_action_; } | 476 TestTrayAction* tray_action() { return &tray_action_; } |
473 | 477 |
474 lock_screen_apps::StateController* state_controller() { | 478 lock_screen_apps::StateController* state_controller() { |
475 return state_controller_.get(); | 479 return state_controller_.get(); |
476 } | 480 } |
477 | 481 |
478 TestAppManager* app_manager() { return app_manager_; } | 482 TestAppManager* app_manager() { return app_manager_; } |
479 | 483 |
480 TestAppWindow* app_window() { return app_window_.get(); } | 484 TestAppWindow* app_window() { return app_window_.get(); } |
481 const extensions::Extension* app() { return app_.get(); } | 485 const extensions::Extension* app() { return app_.get(); } |
482 | 486 |
483 private: | 487 private: |
484 std::unique_ptr<base::test::ScopedCommandLine> command_line_; | 488 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
485 TestingProfileManager profile_manager_; | 489 TestingProfileManager profile_manager_; |
486 TestingProfile profile_; | 490 TestingProfile profile_; |
487 TestingProfile* signin_profile_ = nullptr; | 491 TestingProfile* lock_screen_profile_ = nullptr; |
| 492 |
| 493 // Run loop used to throttle test until async state controller initialization |
| 494 // is fully complete. The quit closure for this run loop will be passed to |
| 495 // |state_controller_| as the callback to be run when the state controller is |
| 496 // ready for action. |
| 497 // NOTE: Tests should call |state_controller_->SetPrimaryProfile(Profile*)| |
| 498 // before running the loop, as that is the method that starts the state |
| 499 // controller. |
| 500 base::RunLoop ready_waiter_; |
488 | 501 |
489 std::unique_ptr<session_manager::SessionManager> session_manager_; | 502 std::unique_ptr<session_manager::SessionManager> session_manager_; |
490 | 503 |
491 std::unique_ptr<lock_screen_apps::StateController> state_controller_; | 504 std::unique_ptr<lock_screen_apps::StateController> state_controller_; |
492 | 505 |
493 TestStateObserver observer_; | 506 TestStateObserver observer_; |
494 TestTrayAction tray_action_; | 507 TestTrayAction tray_action_; |
495 TestAppManager* app_manager_ = nullptr; | 508 TestAppManager* app_manager_ = nullptr; |
496 | 509 |
497 std::unique_ptr<TestAppWindow> app_window_; | 510 std::unique_ptr<TestAppWindow> app_window_; |
(...skipping 17 matching lines...) Expand all Loading... |
515 | 528 |
516 EXPECT_EQ(TrayActionState::kNotAvailable, | 529 EXPECT_EQ(TrayActionState::kNotAvailable, |
517 state_controller()->GetLockScreenNoteState()); | 530 state_controller()->GetLockScreenNoteState()); |
518 | 531 |
519 EXPECT_EQ(0u, observer()->observed_states().size()); | 532 EXPECT_EQ(0u, observer()->observed_states().size()); |
520 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 533 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
521 } | 534 } |
522 | 535 |
523 TEST_F(LockScreenAppStateTest, SetPrimaryProfile) { | 536 TEST_F(LockScreenAppStateTest, SetPrimaryProfile) { |
524 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | 537 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); |
525 state_controller()->SetPrimaryProfile(profile()); | 538 SetPrimaryProfileAndWaitUntilReady(); |
526 | 539 |
527 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 540 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
528 EXPECT_EQ(TrayActionState::kNotAvailable, | 541 EXPECT_EQ(TrayActionState::kNotAvailable, |
529 state_controller()->GetLockScreenNoteState()); | 542 state_controller()->GetLockScreenNoteState()); |
530 EXPECT_EQ(0u, observer()->observed_states().size()); | 543 EXPECT_EQ(0u, observer()->observed_states().size()); |
531 } | 544 } |
532 | 545 |
533 TEST_F(LockScreenAppStateTest, SetPrimaryProfileWhenSessionLocked) { | 546 TEST_F(LockScreenAppStateTest, SetPrimaryProfileWhenSessionLocked) { |
534 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 547 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
535 EXPECT_EQ(TrayActionState::kNotAvailable, | 548 EXPECT_EQ(TrayActionState::kNotAvailable, |
536 state_controller()->GetLockScreenNoteState()); | 549 state_controller()->GetLockScreenNoteState()); |
537 | 550 |
538 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | 551 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); |
539 | 552 |
540 app_manager()->SetInitialAppState(kTestAppId, true); | 553 app_manager()->SetInitialAppState(kTestAppId, true); |
541 state_controller()->SetPrimaryProfile(profile()); | 554 SetPrimaryProfileAndWaitUntilReady(); |
542 | 555 |
543 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 556 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
544 | 557 |
545 EXPECT_EQ(TrayActionState::kAvailable, | 558 EXPECT_EQ(TrayActionState::kAvailable, |
546 state_controller()->GetLockScreenNoteState()); | 559 state_controller()->GetLockScreenNoteState()); |
547 | 560 |
548 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); | 561 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
549 } | 562 } |
550 | 563 |
551 TEST_F(LockScreenAppStateTest, SessionLock) { | 564 TEST_F(LockScreenAppStateTest, SessionLock) { |
552 app_manager()->SetInitialAppState(kTestAppId, true); | 565 app_manager()->SetInitialAppState(kTestAppId, true); |
553 state_controller()->SetPrimaryProfile(profile()); | 566 SetPrimaryProfileAndWaitUntilReady(); |
554 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 567 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
555 | 568 |
556 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 569 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
557 | 570 |
558 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 571 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
559 | 572 |
560 EXPECT_EQ(TrayActionState::kAvailable, | 573 EXPECT_EQ(TrayActionState::kAvailable, |
561 state_controller()->GetLockScreenNoteState()); | 574 state_controller()->GetLockScreenNoteState()); |
562 | 575 |
563 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); | 576 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
(...skipping 13 matching lines...) Expand all Loading... |
577 ClearObservedStates(); | 590 ClearObservedStates(); |
578 | 591 |
579 // Test that subsequent session lock works as expected. | 592 // Test that subsequent session lock works as expected. |
580 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 593 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
581 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 594 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
582 ExpectObservedStatesMatch({TrayActionState::kAvailable}, | 595 ExpectObservedStatesMatch({TrayActionState::kAvailable}, |
583 "Available on second lock"); | 596 "Available on second lock"); |
584 } | 597 } |
585 | 598 |
586 TEST_F(LockScreenAppStateTest, SessionUnlockedWhileStartingAppManager) { | 599 TEST_F(LockScreenAppStateTest, SessionUnlockedWhileStartingAppManager) { |
587 state_controller()->SetPrimaryProfile(profile()); | 600 SetPrimaryProfileAndWaitUntilReady(); |
588 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 601 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
589 | 602 |
590 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 603 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
591 | 604 |
592 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 605 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
593 | 606 |
594 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | 607 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); |
595 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 608 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
596 | 609 |
597 EXPECT_EQ(TrayActionState::kNotAvailable, | 610 EXPECT_EQ(TrayActionState::kNotAvailable, |
598 state_controller()->GetLockScreenNoteState()); | 611 state_controller()->GetLockScreenNoteState()); |
599 state_controller()->FlushTrayActionForTesting(); | 612 state_controller()->FlushTrayActionForTesting(); |
600 EXPECT_EQ(0u, observer()->observed_states().size()); | 613 EXPECT_EQ(0u, observer()->observed_states().size()); |
601 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 614 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
602 | 615 |
603 // Test that subsequent session lock works as expected. | 616 // Test that subsequent session lock works as expected. |
604 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 617 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
605 | 618 |
606 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 619 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
607 app_manager()->UpdateApp(kTestAppId, true); | 620 app_manager()->UpdateApp(kTestAppId, true); |
608 | 621 |
609 EXPECT_EQ(TrayActionState::kAvailable, | 622 EXPECT_EQ(TrayActionState::kAvailable, |
610 state_controller()->GetLockScreenNoteState()); | 623 state_controller()->GetLockScreenNoteState()); |
611 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); | 624 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
612 } | 625 } |
613 | 626 |
614 TEST_F(LockScreenAppStateTest, AppManagerNoApp) { | 627 TEST_F(LockScreenAppStateTest, AppManagerNoApp) { |
615 state_controller()->SetPrimaryProfile(profile()); | 628 SetPrimaryProfileAndWaitUntilReady(); |
616 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 629 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
617 | 630 |
618 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 631 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
619 | 632 |
620 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 633 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
621 | 634 |
622 EXPECT_EQ(TrayActionState::kNotAvailable, | 635 EXPECT_EQ(TrayActionState::kNotAvailable, |
623 state_controller()->GetLockScreenNoteState()); | 636 state_controller()->GetLockScreenNoteState()); |
624 state_controller()->FlushTrayActionForTesting(); | 637 state_controller()->FlushTrayActionForTesting(); |
625 EXPECT_EQ(0u, observer()->observed_states().size()); | 638 EXPECT_EQ(0u, observer()->observed_states().size()); |
(...skipping 13 matching lines...) Expand all Loading... |
639 app_manager()->SetInitialAppState(kTestAppId, false); | 652 app_manager()->SetInitialAppState(kTestAppId, false); |
640 | 653 |
641 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 654 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
642 | 655 |
643 EXPECT_EQ(TrayActionState::kAvailable, | 656 EXPECT_EQ(TrayActionState::kAvailable, |
644 state_controller()->GetLockScreenNoteState()); | 657 state_controller()->GetLockScreenNoteState()); |
645 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); | 658 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
646 } | 659 } |
647 | 660 |
648 TEST_F(LockScreenAppStateTest, AppAvailabilityChanges) { | 661 TEST_F(LockScreenAppStateTest, AppAvailabilityChanges) { |
649 state_controller()->SetPrimaryProfile(profile()); | 662 SetPrimaryProfileAndWaitUntilReady(); |
650 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 663 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
651 | 664 |
652 app_manager()->SetInitialAppState(kTestAppId, false); | 665 app_manager()->SetInitialAppState(kTestAppId, false); |
653 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 666 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
654 | 667 |
655 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 668 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
656 | 669 |
657 EXPECT_EQ(TrayActionState::kAvailable, | 670 EXPECT_EQ(TrayActionState::kAvailable, |
658 state_controller()->GetLockScreenNoteState()); | 671 state_controller()->GetLockScreenNoteState()); |
659 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); | 672 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 {TrayActionState::kLaunching, TrayActionState::kAvailable}, | 790 {TrayActionState::kLaunching, TrayActionState::kAvailable}, |
778 "Second failed launch on new note request"); | 791 "Second failed launch on new note request"); |
779 EXPECT_EQ(2, app_manager()->launch_count()); | 792 EXPECT_EQ(2, app_manager()->launch_count()); |
780 } | 793 } |
781 | 794 |
782 TEST_F(LockScreenAppStateTest, AppWindowRegistration) { | 795 TEST_F(LockScreenAppStateTest, AppWindowRegistration) { |
783 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, | 796 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, |
784 true /* enable_app_launch */)); | 797 true /* enable_app_launch */)); |
785 | 798 |
786 std::unique_ptr<TestAppWindow> app_window = | 799 std::unique_ptr<TestAppWindow> app_window = |
787 CreateNoteTakingWindow(signin_profile(), app()); | 800 CreateNoteTakingWindow(lock_screen_profile(), app()); |
788 EXPECT_FALSE(app_window->window()); | 801 EXPECT_FALSE(app_window->window()); |
789 | 802 |
790 tray_action()->SendNewNoteRequest(); | 803 tray_action()->SendNewNoteRequest(); |
791 state_controller()->FlushTrayActionForTesting(); | 804 state_controller()->FlushTrayActionForTesting(); |
792 | 805 |
793 EXPECT_EQ(TrayActionState::kLaunching, | 806 EXPECT_EQ(TrayActionState::kLaunching, |
794 state_controller()->GetLockScreenNoteState()); | 807 state_controller()->GetLockScreenNoteState()); |
795 observer()->ClearObservedStates(); | 808 observer()->ClearObservedStates(); |
796 tray_action()->ClearObservedStates(); | 809 tray_action()->ClearObservedStates(); |
797 | 810 |
798 std::unique_ptr<TestAppWindow> non_eligible_app_window = | 811 std::unique_ptr<TestAppWindow> non_eligible_app_window = |
799 CreateNoteTakingWindow(profile(), app()); | 812 CreateNoteTakingWindow(profile(), app()); |
800 EXPECT_FALSE(non_eligible_app_window->window()); | 813 EXPECT_FALSE(non_eligible_app_window->window()); |
801 | 814 |
802 EXPECT_FALSE(state_controller()->CreateAppWindowForLockScreenAction( | 815 EXPECT_FALSE(state_controller()->CreateAppWindowForLockScreenAction( |
803 signin_profile(), app(), extensions::api::app_runtime::ACTION_TYPE_NONE, | 816 lock_screen_profile(), app(), |
| 817 extensions::api::app_runtime::ACTION_TYPE_NONE, |
804 base::MakeUnique<ChromeAppDelegate>(true))); | 818 base::MakeUnique<ChromeAppDelegate>(true))); |
805 | 819 |
806 app_window = CreateNoteTakingWindow(signin_profile(), app()); | 820 app_window = CreateNoteTakingWindow(lock_screen_profile(), app()); |
807 ASSERT_TRUE(app_window->window()); | 821 ASSERT_TRUE(app_window->window()); |
808 | 822 |
809 app_window->Initialize(true /* shown */); | 823 app_window->Initialize(true /* shown */); |
810 EXPECT_EQ(TrayActionState::kActive, | 824 EXPECT_EQ(TrayActionState::kActive, |
811 state_controller()->GetLockScreenNoteState()); | 825 state_controller()->GetLockScreenNoteState()); |
812 | 826 |
813 // Test that second app window cannot be registered. | 827 // Test that second app window cannot be registered. |
814 std::unique_ptr<TestAppWindow> second_app_window = | 828 std::unique_ptr<TestAppWindow> second_app_window = |
815 CreateNoteTakingWindow(signin_profile(), app()); | 829 CreateNoteTakingWindow(lock_screen_profile(), app()); |
816 EXPECT_FALSE(second_app_window->window()); | 830 EXPECT_FALSE(second_app_window->window()); |
817 | 831 |
818 // Test the app window does not get closed by itself. | 832 // Test the app window does not get closed by itself. |
819 base::RunLoop().RunUntilIdle(); | 833 base::RunLoop().RunUntilIdle(); |
820 EXPECT_FALSE(app_window->closed()); | 834 EXPECT_FALSE(app_window->closed()); |
821 | 835 |
822 EXPECT_EQ(TrayActionState::kActive, | 836 EXPECT_EQ(TrayActionState::kActive, |
823 state_controller()->GetLockScreenNoteState()); | 837 state_controller()->GetLockScreenNoteState()); |
824 | 838 |
825 // Closing the second app window, will not change the state. | 839 // Closing the second app window, will not change the state. |
826 second_app_window->Close(); | 840 second_app_window->Close(); |
827 EXPECT_EQ(TrayActionState::kActive, | 841 EXPECT_EQ(TrayActionState::kActive, |
828 state_controller()->GetLockScreenNoteState()); | 842 state_controller()->GetLockScreenNoteState()); |
829 | 843 |
830 app_window->Close(); | 844 app_window->Close(); |
831 EXPECT_EQ(TrayActionState::kAvailable, | 845 EXPECT_EQ(TrayActionState::kAvailable, |
832 state_controller()->GetLockScreenNoteState()); | 846 state_controller()->GetLockScreenNoteState()); |
833 } | 847 } |
834 | 848 |
835 TEST_F(LockScreenAppStateTest, AppWindowClosedBeforeBeingShown) { | 849 TEST_F(LockScreenAppStateTest, AppWindowClosedBeforeBeingShown) { |
836 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kLaunching, | 850 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kLaunching, |
837 true /* enable_app_launch */)); | 851 true /* enable_app_launch */)); |
838 | 852 |
839 std::unique_ptr<TestAppWindow> app_window = | 853 std::unique_ptr<TestAppWindow> app_window = |
840 CreateNoteTakingWindow(signin_profile(), app()); | 854 CreateNoteTakingWindow(lock_screen_profile(), app()); |
841 ASSERT_TRUE(app_window->window()); | 855 ASSERT_TRUE(app_window->window()); |
842 app_window->Initialize(false /* shown */); | 856 app_window->Initialize(false /* shown */); |
843 | 857 |
844 app_window->Close(); | 858 app_window->Close(); |
845 EXPECT_EQ(TrayActionState::kAvailable, | 859 EXPECT_EQ(TrayActionState::kAvailable, |
846 state_controller()->GetLockScreenNoteState()); | 860 state_controller()->GetLockScreenNoteState()); |
847 } | 861 } |
848 | 862 |
849 TEST_F(LockScreenAppStateTest, AppWindowClosedOnSessionUnlock) { | 863 TEST_F(LockScreenAppStateTest, AppWindowClosedOnSessionUnlock) { |
850 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | 864 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, |
851 true /* enable_app_launch */)); | 865 true /* enable_app_launch */)); |
852 | 866 |
853 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | 867 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); |
854 EXPECT_EQ(TrayActionState::kNotAvailable, | 868 EXPECT_EQ(TrayActionState::kNotAvailable, |
855 state_controller()->GetLockScreenNoteState()); | 869 state_controller()->GetLockScreenNoteState()); |
856 | 870 |
857 base::RunLoop().RunUntilIdle(); | 871 base::RunLoop().RunUntilIdle(); |
858 EXPECT_TRUE(app_window()->closed()); | 872 EXPECT_TRUE(app_window()->closed()); |
859 } | 873 } |
860 | 874 |
861 TEST_F(LockScreenAppStateTest, AppWindowClosedOnAppUnload) { | 875 TEST_F(LockScreenAppStateTest, AppWindowClosedOnAppUnload) { |
862 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | 876 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, |
863 true /* enable_app_launch */)); | 877 true /* enable_app_launch */)); |
864 | 878 |
865 extensions::ExtensionSystem::Get(signin_profile()) | 879 extensions::ExtensionSystem::Get(lock_screen_profile()) |
866 ->extension_service() | 880 ->extension_service() |
867 ->UnloadExtension(app()->id(), | 881 ->UnloadExtension(app()->id(), |
868 extensions::UnloadedExtensionReason::UNINSTALL); | 882 extensions::UnloadedExtensionReason::UNINSTALL); |
869 app_manager()->UpdateApp("", false); | 883 app_manager()->UpdateApp("", false); |
870 | 884 |
871 EXPECT_EQ(TrayActionState::kNotAvailable, | 885 EXPECT_EQ(TrayActionState::kNotAvailable, |
872 state_controller()->GetLockScreenNoteState()); | 886 state_controller()->GetLockScreenNoteState()); |
873 | 887 |
874 base::RunLoop().RunUntilIdle(); | 888 base::RunLoop().RunUntilIdle(); |
875 EXPECT_TRUE(app_window()->closed()); | 889 EXPECT_TRUE(app_window()->closed()); |
876 } | 890 } |
877 | 891 |
878 TEST_F(LockScreenAppStateTest, AppWindowClosedOnNoteTakingAppChange) { | 892 TEST_F(LockScreenAppStateTest, AppWindowClosedOnNoteTakingAppChange) { |
879 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | 893 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, |
880 true /* enable_app_launch */)); | 894 true /* enable_app_launch */)); |
881 | 895 |
882 scoped_refptr<extensions::Extension> secondary_app = | 896 scoped_refptr<extensions::Extension> secondary_app = |
883 CreateTestNoteTakingApp(kSecondaryTestAppId); | 897 CreateTestNoteTakingApp(kSecondaryTestAppId); |
884 extensions::ExtensionSystem::Get(signin_profile()) | 898 extensions::ExtensionSystem::Get(lock_screen_profile()) |
885 ->extension_service() | 899 ->extension_service() |
886 ->AddExtension(secondary_app.get()); | 900 ->AddExtension(secondary_app.get()); |
887 | 901 |
888 app_manager()->UpdateApp(secondary_app->id(), true); | 902 app_manager()->UpdateApp(secondary_app->id(), true); |
889 | 903 |
890 EXPECT_EQ(TrayActionState::kAvailable, | 904 EXPECT_EQ(TrayActionState::kAvailable, |
891 state_controller()->GetLockScreenNoteState()); | 905 state_controller()->GetLockScreenNoteState()); |
892 | 906 |
893 base::RunLoop().RunUntilIdle(); | 907 base::RunLoop().RunUntilIdle(); |
894 EXPECT_TRUE(app_window()->closed()); | 908 EXPECT_TRUE(app_window()->closed()); |
895 | 909 |
896 tray_action()->SendNewNoteRequest(); | 910 tray_action()->SendNewNoteRequest(); |
897 state_controller()->FlushTrayActionForTesting(); | 911 state_controller()->FlushTrayActionForTesting(); |
898 | 912 |
899 std::unique_ptr<TestAppWindow> app_window = | 913 std::unique_ptr<TestAppWindow> app_window = |
900 CreateNoteTakingWindow(signin_profile(), app()); | 914 CreateNoteTakingWindow(lock_screen_profile(), app()); |
901 EXPECT_FALSE(app_window->window()); | 915 EXPECT_FALSE(app_window->window()); |
902 ASSERT_EQ(TrayActionState::kLaunching, | 916 ASSERT_EQ(TrayActionState::kLaunching, |
903 state_controller()->GetLockScreenNoteState()); | 917 state_controller()->GetLockScreenNoteState()); |
904 | 918 |
905 std::unique_ptr<TestAppWindow> secondary_app_window = | 919 std::unique_ptr<TestAppWindow> secondary_app_window = |
906 CreateNoteTakingWindow(signin_profile(), secondary_app.get()); | 920 CreateNoteTakingWindow(lock_screen_profile(), secondary_app.get()); |
907 ASSERT_TRUE(secondary_app_window->window()); | 921 ASSERT_TRUE(secondary_app_window->window()); |
908 | 922 |
909 secondary_app_window->Initialize(true /* shown*/); | 923 secondary_app_window->Initialize(true /* shown*/); |
910 EXPECT_EQ(TrayActionState::kActive, | 924 EXPECT_EQ(TrayActionState::kActive, |
911 state_controller()->GetLockScreenNoteState()); | 925 state_controller()->GetLockScreenNoteState()); |
912 | 926 |
913 base::RunLoop().RunUntilIdle(); | 927 base::RunLoop().RunUntilIdle(); |
914 EXPECT_FALSE(secondary_app_window->closed()); | 928 EXPECT_FALSE(secondary_app_window->closed()); |
915 | 929 |
916 // Uninstall the app and test the secondary app window is closed. | 930 // Uninstall the app and test the secondary app window is closed. |
917 extensions::ExtensionSystem::Get(signin_profile()) | 931 extensions::ExtensionSystem::Get(lock_screen_profile()) |
918 ->extension_service() | 932 ->extension_service() |
919 ->UnloadExtension(secondary_app->id(), | 933 ->UnloadExtension(secondary_app->id(), |
920 extensions::UnloadedExtensionReason::UNINSTALL); | 934 extensions::UnloadedExtensionReason::UNINSTALL); |
921 base::RunLoop().RunUntilIdle(); | 935 base::RunLoop().RunUntilIdle(); |
922 EXPECT_TRUE(secondary_app_window->closed()); | 936 EXPECT_TRUE(secondary_app_window->closed()); |
923 } | 937 } |
OLD | NEW |