OLD | NEW |
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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/test/test_simple_task_runner.h" | 12 #include "base/test/test_simple_task_runner.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "components/cryptauth/cryptauth_test_util.h" |
15 #include "components/proximity_auth/fake_secure_context.h" | 16 #include "components/proximity_auth/fake_secure_context.h" |
16 #include "components/proximity_auth/logging/logging.h" | 17 #include "components/proximity_auth/logging/logging.h" |
17 #include "components/proximity_auth/messenger.h" | 18 #include "components/proximity_auth/messenger.h" |
18 #include "components/proximity_auth/mock_proximity_auth_client.h" | 19 #include "components/proximity_auth/mock_proximity_auth_client.h" |
19 #include "components/proximity_auth/proximity_auth_test_util.h" | |
20 #include "components/proximity_auth/proximity_monitor.h" | 20 #include "components/proximity_auth/proximity_monitor.h" |
21 #include "components/proximity_auth/remote_device_life_cycle.h" | 21 #include "components/proximity_auth/remote_device_life_cycle.h" |
22 #include "components/proximity_auth/remote_status_update.h" | 22 #include "components/proximity_auth/remote_status_update.h" |
23 #include "components/proximity_auth/screenlock_bridge.h" | 23 #include "components/proximity_auth/screenlock_bridge.h" |
24 #include "components/proximity_auth/secure_context.h" | 24 #include "components/proximity_auth/secure_context.h" |
25 #include "device/bluetooth/bluetooth_adapter_factory.h" | 25 #include "device/bluetooth/bluetooth_adapter_factory.h" |
26 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 26 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 using MessengerObserver::OnDisconnected; | 153 using MessengerObserver::OnDisconnected; |
154 using ScreenlockBridge::Observer::OnScreenDidLock; | 154 using ScreenlockBridge::Observer::OnScreenDidLock; |
155 using ScreenlockBridge::Observer::OnScreenDidUnlock; | 155 using ScreenlockBridge::Observer::OnScreenDidUnlock; |
156 using ScreenlockBridge::Observer::OnFocusedUserChanged; | 156 using ScreenlockBridge::Observer::OnFocusedUserChanged; |
157 | 157 |
158 MockProximityMonitor* proximity_monitor() { return proximity_monitor_; } | 158 MockProximityMonitor* proximity_monitor() { return proximity_monitor_; } |
159 | 159 |
160 private: | 160 private: |
161 std::unique_ptr<ProximityMonitor> CreateProximityMonitor( | 161 std::unique_ptr<ProximityMonitor> CreateProximityMonitor( |
162 const cryptauth::RemoteDevice& remote_device) override { | 162 const cryptauth::RemoteDevice& remote_device) override { |
163 EXPECT_EQ(kTestRemoteDevicePublicKey, remote_device.public_key); | 163 EXPECT_EQ(cryptauth::kTestRemoteDevicePublicKey, remote_device.public_key); |
164 std::unique_ptr<MockProximityMonitor> proximity_monitor( | 164 std::unique_ptr<MockProximityMonitor> proximity_monitor( |
165 new NiceMock<MockProximityMonitor>()); | 165 new NiceMock<MockProximityMonitor>()); |
166 proximity_monitor_ = proximity_monitor.get(); | 166 proximity_monitor_ = proximity_monitor.get(); |
167 return std::move(proximity_monitor); | 167 return std::move(proximity_monitor); |
168 } | 168 } |
169 | 169 |
170 // Owned by the super class. | 170 // Owned by the super class. |
171 MockProximityMonitor* proximity_monitor_; | 171 MockProximityMonitor* proximity_monitor_; |
172 | 172 |
173 DISALLOW_COPY_AND_ASSIGN(TestUnlockManager); | 173 DISALLOW_COPY_AND_ASSIGN(TestUnlockManager); |
174 }; | 174 }; |
175 | 175 |
176 // Creates a mock Bluetooth adapter and sets it as the global adapter for | 176 // Creates a mock Bluetooth adapter and sets it as the global adapter for |
177 // testing. | 177 // testing. |
178 scoped_refptr<device::MockBluetoothAdapter> | 178 scoped_refptr<device::MockBluetoothAdapter> |
179 CreateAndRegisterMockBluetoothAdapter() { | 179 CreateAndRegisterMockBluetoothAdapter() { |
180 scoped_refptr<device::MockBluetoothAdapter> adapter = | 180 scoped_refptr<device::MockBluetoothAdapter> adapter = |
181 new NiceMock<device::MockBluetoothAdapter>(); | 181 new NiceMock<device::MockBluetoothAdapter>(); |
182 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); | 182 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter); |
183 return adapter; | 183 return adapter; |
184 } | 184 } |
185 | 185 |
186 } // namespace | 186 } // namespace |
187 | 187 |
188 class ProximityAuthUnlockManagerTest : public testing::Test { | 188 class ProximityAuthUnlockManagerTest : public testing::Test { |
189 public: | 189 public: |
190 ProximityAuthUnlockManagerTest() | 190 ProximityAuthUnlockManagerTest() |
191 : remote_device_(CreateClassicRemoteDeviceForTest()), | 191 : remote_device_(cryptauth::CreateClassicRemoteDeviceForTest()), |
192 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), | 192 bluetooth_adapter_(CreateAndRegisterMockBluetoothAdapter()), |
193 task_runner_(new base::TestSimpleTaskRunner()), | 193 task_runner_(new base::TestSimpleTaskRunner()), |
194 thread_task_runner_handle_(task_runner_) { | 194 thread_task_runner_handle_(task_runner_) { |
195 ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true)); | 195 ON_CALL(*bluetooth_adapter_, IsPowered()).WillByDefault(Return(true)); |
196 ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(&messenger_)); | 196 ON_CALL(life_cycle_, GetMessenger()).WillByDefault(Return(&messenger_)); |
197 ON_CALL(life_cycle_, GetRemoteDevice()) | 197 ON_CALL(life_cycle_, GetRemoteDevice()) |
198 .WillByDefault(Return(remote_device_)); | 198 .WillByDefault(Return(remote_device_)); |
199 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); | 199 ON_CALL(messenger_, SupportsSignIn()).WillByDefault(Return(true)); |
200 ON_CALL(messenger_, GetSecureContext()) | 200 ON_CALL(messenger_, GetSecureContext()) |
201 .WillByDefault(Return(&secure_context_)); | 201 .WillByDefault(Return(&secure_context_)); |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 })); | 924 })); |
925 | 925 |
926 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); | 926 EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); |
927 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); | 927 unlock_manager_->OnAuthAttempted(ScreenlockBridge::LockHandler::USER_CLICK); |
928 | 928 |
929 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); | 929 EXPECT_CALL(proximity_auth_client_, FinalizeSignin(std::string())); |
930 unlock_manager_->OnDecryptResponse(std::string()); | 930 unlock_manager_->OnDecryptResponse(std::string()); |
931 } | 931 } |
932 | 932 |
933 } // namespace proximity_auth | 933 } // namespace proximity_auth |
OLD | NEW |