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
3 // found in the LICENSE file.
5 #include "components/proximity_auth/ble/proximity_auth_ble_system.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "components/proximity_auth/connection_finder.h"
10 #include "components/proximity_auth/proximity_auth_client.h"
11 #include "components/proximity_auth/screenlock_bridge.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
16 using testing::NiceMock
;
17 using testing::Return
;
19 namespace proximity_auth
{
21 class MockConnectionFinder
: public ConnectionFinder
{
23 MockConnectionFinder() {}
24 ~MockConnectionFinder() {}
26 MOCK_METHOD1(Find
, void(const ConnectionCallback
&));
31 class ProximityAuthBleSystemTestable
: public ProximityAuthBleSystem
{
33 class MockScreenlockBridgeAdapter
34 : public ProximityAuthBleSystem::ScreenlockBridgeAdapter
{
36 MockScreenlockBridgeAdapter() {}
37 ~MockScreenlockBridgeAdapter() {}
39 MOCK_METHOD1(AddObserver
, void(ScreenlockBridge::Observer
*));
40 MOCK_METHOD1(RemoveObserver
, void(ScreenlockBridge::Observer
*));
41 MOCK_METHOD1(Unlock
, void(ProximityAuthClient
*));
44 ProximityAuthBleSystemTestable(ScreenlockBridgeAdapter
* screenlock_bridge
)
45 : ProximityAuthBleSystem(make_scoped_ptr(screenlock_bridge
), nullptr) {}
47 ConnectionFinder
* CreateConnectionFinder() override
{
48 return new NiceMock
<MockConnectionFinder
>();
52 class ProximityAuthBleSystemTest
: public testing::Test
{
54 ProximityAuthBleSystemTest()
55 : screenlock_bridge_(new NiceMock
<
56 ProximityAuthBleSystemTestable::MockScreenlockBridgeAdapter
>) {}
58 void SetExpectations() {
59 EXPECT_CALL(*screenlock_bridge_
, AddObserver(_
));
60 EXPECT_CALL(*screenlock_bridge_
, RemoveObserver(_
));
63 ProximityAuthBleSystemTestable::MockScreenlockBridgeAdapter
*
67 TEST_F(ProximityAuthBleSystemTest
, ConstructAndDestroyShouldNotCrash
) {
70 ProximityAuthBleSystemTestable
proximity_auth_system(screenlock_bridge_
);
73 TEST_F(ProximityAuthBleSystemTest
,
74 OnScreenDidLock_OnLockScreenEvent_OnScreenDidUnlock
) {
77 ProximityAuthBleSystemTestable
proximity_auth_system(screenlock_bridge_
);
78 proximity_auth_system
.OnScreenDidLock(
79 ScreenlockBridge::LockHandler::LOCK_SCREEN
);
80 proximity_auth_system
.OnScreenDidUnlock(
81 ScreenlockBridge::LockHandler::LOCK_SCREEN
);
84 TEST_F(ProximityAuthBleSystemTest
,
85 OnScreenDidLock_OnSigninScreenEvent_OnScreenDidUnlock
) {
88 ProximityAuthBleSystemTestable
proximity_auth_system(screenlock_bridge_
);
89 proximity_auth_system
.OnScreenDidLock(
90 ScreenlockBridge::LockHandler::SIGNIN_SCREEN
);
91 proximity_auth_system
.OnScreenDidUnlock(
92 ScreenlockBridge::LockHandler::SIGNIN_SCREEN
);
95 TEST_F(ProximityAuthBleSystemTest
,
96 OnScreenDidLock_OnOtherScreenEvent_OnScreenDidUnlock
) {
99 ProximityAuthBleSystemTestable
proximity_auth_system(screenlock_bridge_
);
100 proximity_auth_system
.OnScreenDidLock(
101 ScreenlockBridge::LockHandler::OTHER_SCREEN
);
102 proximity_auth_system
.OnScreenDidUnlock(
103 ScreenlockBridge::LockHandler::OTHER_SCREEN
);
106 } // namespace proximity_auth