Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: components/proximity_auth/unlock_manager_unittest.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: fix msan tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/proximity_auth/unlock_manager.h" 5 #include "components/proximity_auth/unlock_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 ON_CALL(*this, IsInRssiRange()).WillByDefault(Return(false)); 82 ON_CALL(*this, IsInRssiRange()).WillByDefault(Return(false));
83 } 83 }
84 ~MockProximityMonitor() override {} 84 ~MockProximityMonitor() override {}
85 85
86 MOCK_METHOD0(Start, void()); 86 MOCK_METHOD0(Start, void());
87 MOCK_METHOD0(Stop, void()); 87 MOCK_METHOD0(Stop, void());
88 MOCK_CONST_METHOD0(GetStrategy, Strategy()); 88 MOCK_CONST_METHOD0(GetStrategy, Strategy());
89 MOCK_CONST_METHOD0(IsUnlockAllowed, bool()); 89 MOCK_CONST_METHOD0(IsUnlockAllowed, bool());
90 MOCK_CONST_METHOD0(IsInRssiRange, bool()); 90 MOCK_CONST_METHOD0(IsInRssiRange, bool());
91 MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void()); 91 MOCK_METHOD0(RecordProximityMetricsOnAuthSuccess, void());
92 MOCK_METHOD1(AddObserver, void(ProximityMonitorObserver*));
93 MOCK_METHOD1(RemoveObserver, void(ProximityMonitorObserver*));
92 94
93 private: 95 private:
94 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor); 96 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor);
95 }; 97 };
96 98
97 class FakeLockHandler : public ScreenlockBridge::LockHandler { 99 class FakeLockHandler : public ScreenlockBridge::LockHandler {
98 public: 100 public:
99 FakeLockHandler() {} 101 FakeLockHandler() {}
100 ~FakeLockHandler() override {} 102 ~FakeLockHandler() override {}
101 103
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1)); 458 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1));
457 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 459 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
458 } 460 }
459 461
460 TEST_F( 462 TEST_F(
461 ProximityAuthUnlockManagerTest, 463 ProximityAuthUnlockManagerTest,
462 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) { 464 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) {
463 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 465 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
464 SimulateUserPresentState(); 466 SimulateUserPresentState();
465 467
466 NiceMock<MockRemoteDeviceLifeCycle> life_cycle; 468 ON_CALL(life_cycle_, GetState())
467 ON_CALL(life_cycle, GetState())
468 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); 469 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
469 470
470 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1)); 471 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1));
471 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle); 472 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
472 } 473 }
473 474
474 TEST_F( 475 TEST_F(
475 ProximityAuthUnlockManagerTest, 476 ProximityAuthUnlockManagerTest,
476 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) { 477 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) {
477 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 478 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
478 SimulateUserPresentState(); 479 SimulateUserPresentState();
479 480
480 NiceMock<MockRemoteDeviceLifeCycle> life_cycle; 481 ON_CALL(life_cycle_, GetState())
481 ON_CALL(life_cycle, GetState())
482 .WillByDefault( 482 .WillByDefault(
483 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED)); 483 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
484 484
485 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1)); 485 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1));
486 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle); 486 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_);
487 } 487 }
488 488
489 TEST_F(ProximityAuthUnlockManagerTest, 489 TEST_F(ProximityAuthUnlockManagerTest,
490 OnLifeCycleStateChanged_SecureChannelEstablished_RegistersAsObserver) { 490 OnLifeCycleStateChanged_SecureChannelEstablished_RegistersAsObserver) {
491 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 491 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
492 SimulateUserPresentState(); 492 SimulateUserPresentState();
493
494 NiceMock<MockRemoteDeviceLifeCycle> life_cycle;
495 ON_CALL(life_cycle, GetState())
496 .WillByDefault(
497 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
498
499 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get())); 493 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get()));
500 unlock_manager_->OnLifeCycleStateChanged(); 494 unlock_manager_->OnLifeCycleStateChanged();
501 } 495 }
502 496
503 TEST_F(ProximityAuthUnlockManagerTest, 497 TEST_F(ProximityAuthUnlockManagerTest,
504 OnLifeCycleStateChanged_StartsProximityMonitor) { 498 OnLifeCycleStateChanged_StartsProximityMonitor) {
505 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 499 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
506 SimulateUserPresentState(); 500 SimulateUserPresentState();
507
508 NiceMock<MockRemoteDeviceLifeCycle> life_cycle;
509 ON_CALL(life_cycle, GetState())
510 .WillByDefault(
511 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
512
513 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1)); 501 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1));
514 unlock_manager_->OnLifeCycleStateChanged(); 502 unlock_manager_->OnLifeCycleStateChanged();
515 } 503 }
516 504
517 TEST_F(ProximityAuthUnlockManagerTest, 505 TEST_F(ProximityAuthUnlockManagerTest,
518 OnLifeCycleStateChanged_StopsProximityMonitor) { 506 OnLifeCycleStateChanged_StopsProximityMonitor) {
519 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 507 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
520 SimulateUserPresentState(); 508 SimulateUserPresentState();
521 509
522 ON_CALL(life_cycle_, GetState()) 510 ON_CALL(life_cycle_, GetState())
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 593 }
606 594
607 TEST_F(ProximityAuthUnlockManagerTest, OnDisconnected_UnregistersAsObserver) { 595 TEST_F(ProximityAuthUnlockManagerTest, OnDisconnected_UnregistersAsObserver) {
608 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 596 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
609 SimulateUserPresentState(); 597 SimulateUserPresentState();
610 598
611 ON_CALL(life_cycle_, GetState()) 599 ON_CALL(life_cycle_, GetState())
612 .WillByDefault( 600 .WillByDefault(
613 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); 601 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
614 602
615 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get())); 603 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get()))
604 .Times(testing::AtLeast(1));
616 unlock_manager_.get()->OnDisconnected(); 605 unlock_manager_.get()->OnDisconnected();
606 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
617 } 607 }
618 608
619 TEST_F(ProximityAuthUnlockManagerTest, 609 TEST_F(ProximityAuthUnlockManagerTest,
620 OnScreenDidUnlock_StopsProximityMonitor) { 610 OnScreenDidUnlock_StopsProximityMonitor) {
621 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 611 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
622 SimulateUserPresentState(); 612 SimulateUserPresentState();
623 613
624 EXPECT_CALL(*proximity_monitor_, Stop()); 614 EXPECT_CALL(*proximity_monitor_, Stop());
625 unlock_manager_.get()->OnScreenDidUnlock( 615 unlock_manager_.get()->OnScreenDidUnlock(
626 ScreenlockBridge::LockHandler::LOCK_SCREEN); 616 ScreenlockBridge::LockHandler::LOCK_SCREEN);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 SimulateUserPresentState(); 809 SimulateUserPresentState();
820 810
821 EXPECT_CALL(messenger_, DispatchUnlockEvent()); 811 EXPECT_CALL(messenger_, DispatchUnlockEvent());
822 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); 812 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK);
823 813
824 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); 814 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true));
825 unlock_manager_->OnUnlockEventSent(true); 815 unlock_manager_->OnUnlockEventSent(true);
826 } 816 }
827 817
828 } // namespace proximity_auth 818 } // namespace proximity_auth
OLDNEW
« components/proximity_auth/unlock_manager.cc ('K') | « components/proximity_auth/unlock_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698