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

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

Issue 1377313002: Revert of Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: 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
« no previous file with comments | « components/proximity_auth/unlock_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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*));
94 92
95 private: 93 private:
96 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor); 94 DISALLOW_COPY_AND_ASSIGN(MockProximityMonitor);
97 }; 95 };
98 96
99 class FakeLockHandler : public ScreenlockBridge::LockHandler { 97 class FakeLockHandler : public ScreenlockBridge::LockHandler {
100 public: 98 public:
101 FakeLockHandler() {} 99 FakeLockHandler() {}
102 ~FakeLockHandler() override {} 100 ~FakeLockHandler() override {}
103 101
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1)); 456 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1));
459 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr); 457 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
460 } 458 }
461 459
462 TEST_F( 460 TEST_F(
463 ProximityAuthUnlockManagerTest, 461 ProximityAuthUnlockManagerTest,
464 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) { 462 SetRemoteDeviceLifeCycle_ConnectingRemoteDeviceLifeCycle_StopsProximityMonit or) {
465 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 463 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
466 SimulateUserPresentState(); 464 SimulateUserPresentState();
467 465
468 ON_CALL(life_cycle_, GetState()) 466 NiceMock<MockRemoteDeviceLifeCycle> life_cycle;
467 ON_CALL(life_cycle, GetState())
469 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION)); 468 .WillByDefault(Return(RemoteDeviceLifeCycle::State::FINDING_CONNECTION));
470 469
471 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1)); 470 EXPECT_CALL(*proximity_monitor_, Stop()).Times(AtLeast(1));
472 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle_); 471 unlock_manager_->SetRemoteDeviceLifeCycle(&life_cycle);
473 } 472 }
474 473
475 TEST_F( 474 TEST_F(
476 ProximityAuthUnlockManagerTest, 475 ProximityAuthUnlockManagerTest,
477 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) { 476 SetRemoteDeviceLifeCycle_ConnectedRemoteDeviceLifeCycle_StartsProximityMonit or) {
478 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 477 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
479 SimulateUserPresentState(); 478 SimulateUserPresentState();
480 479
481 ON_CALL(life_cycle_, GetState()) 480 NiceMock<MockRemoteDeviceLifeCycle> life_cycle;
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
493 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get())); 499 EXPECT_CALL(messenger_, AddObserver(unlock_manager_.get()));
494 unlock_manager_->OnLifeCycleStateChanged(); 500 unlock_manager_->OnLifeCycleStateChanged();
495 } 501 }
496 502
497 TEST_F(ProximityAuthUnlockManagerTest, 503 TEST_F(ProximityAuthUnlockManagerTest,
498 OnLifeCycleStateChanged_StartsProximityMonitor) { 504 OnLifeCycleStateChanged_StartsProximityMonitor) {
499 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 505 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
500 SimulateUserPresentState(); 506 SimulateUserPresentState();
507
508 NiceMock<MockRemoteDeviceLifeCycle> life_cycle;
509 ON_CALL(life_cycle, GetState())
510 .WillByDefault(
511 Return(RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED));
512
501 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1)); 513 EXPECT_CALL(*proximity_monitor_, Start()).Times(AtLeast(1));
502 unlock_manager_->OnLifeCycleStateChanged(); 514 unlock_manager_->OnLifeCycleStateChanged();
503 } 515 }
504 516
505 TEST_F(ProximityAuthUnlockManagerTest, 517 TEST_F(ProximityAuthUnlockManagerTest,
506 OnLifeCycleStateChanged_StopsProximityMonitor) { 518 OnLifeCycleStateChanged_StopsProximityMonitor) {
507 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 519 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
508 SimulateUserPresentState(); 520 SimulateUserPresentState();
509 521
510 ON_CALL(life_cycle_, GetState()) 522 ON_CALL(life_cycle_, GetState())
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 } 605 }
594 606
595 TEST_F(ProximityAuthUnlockManagerTest, OnDisconnected_UnregistersAsObserver) { 607 TEST_F(ProximityAuthUnlockManagerTest, OnDisconnected_UnregistersAsObserver) {
596 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 608 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
597 SimulateUserPresentState(); 609 SimulateUserPresentState();
598 610
599 ON_CALL(life_cycle_, GetState()) 611 ON_CALL(life_cycle_, GetState())
600 .WillByDefault( 612 .WillByDefault(
601 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED)); 613 Return(RemoteDeviceLifeCycle::State::AUTHENTICATION_FAILED));
602 614
603 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get())) 615 EXPECT_CALL(messenger_, RemoveObserver(unlock_manager_.get()));
604 .Times(testing::AtLeast(1));
605 unlock_manager_.get()->OnDisconnected(); 616 unlock_manager_.get()->OnDisconnected();
606 unlock_manager_->SetRemoteDeviceLifeCycle(nullptr);
607 } 617 }
608 618
609 TEST_F(ProximityAuthUnlockManagerTest, 619 TEST_F(ProximityAuthUnlockManagerTest,
610 OnScreenDidUnlock_StopsProximityMonitor) { 620 OnScreenDidUnlock_StopsProximityMonitor) {
611 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK); 621 CreateUnlockManager(UnlockManager::ScreenlockType::SESSION_LOCK);
612 SimulateUserPresentState(); 622 SimulateUserPresentState();
613 623
614 EXPECT_CALL(*proximity_monitor_, Stop()); 624 EXPECT_CALL(*proximity_monitor_, Stop());
615 unlock_manager_.get()->OnScreenDidUnlock( 625 unlock_manager_.get()->OnScreenDidUnlock(
616 ScreenlockBridge::LockHandler::LOCK_SCREEN); 626 ScreenlockBridge::LockHandler::LOCK_SCREEN);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 SimulateUserPresentState(); 819 SimulateUserPresentState();
810 820
811 EXPECT_CALL(messenger_, DispatchUnlockEvent()); 821 EXPECT_CALL(messenger_, DispatchUnlockEvent());
812 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); 822 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK);
813 823
814 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true)); 824 EXPECT_CALL(proximity_auth_client_, FinalizeUnlock(true));
815 unlock_manager_->OnUnlockEventSent(true); 825 unlock_manager_->OnUnlockEventSent(true);
816 } 826 }
817 827
818 } // namespace proximity_auth 828 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/unlock_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698