Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / components / proximity_auth / ble / proximity_auth_ble_system_unittest.cc
blobb223e4aa4a4c8a7b9614b27c3e4253576b92f7ed
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"
7 #include "base/bind.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"
15 using testing::_;
16 using testing::NiceMock;
17 using testing::Return;
19 namespace proximity_auth {
20 namespace {
21 class MockConnectionFinder : public ConnectionFinder {
22 public:
23 MockConnectionFinder() {}
24 ~MockConnectionFinder() {}
26 MOCK_METHOD1(Find, void(const ConnectionCallback&));
29 } // namespace
31 class ProximityAuthBleSystemTestable : public ProximityAuthBleSystem {
32 public:
33 class MockScreenlockBridgeAdapter
34 : public ProximityAuthBleSystem::ScreenlockBridgeAdapter {
35 public:
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 {
53 protected:
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*
64 screenlock_bridge_;
67 TEST_F(ProximityAuthBleSystemTest, ConstructAndDestroyShouldNotCrash) {
68 SetExpectations();
70 ProximityAuthBleSystemTestable proximity_auth_system(screenlock_bridge_);
73 TEST_F(ProximityAuthBleSystemTest,
74 OnScreenDidLock_OnLockScreenEvent_OnScreenDidUnlock) {
75 SetExpectations();
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) {
86 SetExpectations();
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) {
97 SetExpectations();
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