| 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/remote_device_life_cycle_impl.h" | 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "components/proximity_auth/authenticator.h" | 11 #include "components/proximity_auth/authenticator.h" |
| 12 #include "components/proximity_auth/connection_finder.h" | 12 #include "components/proximity_auth/connection_finder.h" |
| 13 #include "components/proximity_auth/fake_connection.h" | 13 #include "components/proximity_auth/fake_connection.h" |
| 14 #include "components/proximity_auth/messenger.h" | 14 #include "components/proximity_auth/messenger.h" |
| 15 #include "components/proximity_auth/proximity_auth_test_util.h" |
| 15 #include "components/proximity_auth/secure_context.h" | 16 #include "components/proximity_auth/secure_context.h" |
| 16 #include "components/proximity_auth/wire_message.h" | 17 #include "components/proximity_auth/wire_message.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using testing::_; | 21 using testing::_; |
| 21 using testing::Mock; | 22 using testing::Mock; |
| 22 using testing::NiceMock; | 23 using testing::NiceMock; |
| 23 using testing::Return; | 24 using testing::Return; |
| 24 using testing::StrictMock; | 25 using testing::StrictMock; |
| 25 | 26 |
| 26 namespace proximity_auth { | 27 namespace proximity_auth { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Attributes of the remote device under test. | |
| 31 const char kRemoteDeviceName[] = "remote device"; | |
| 32 const char kRemoteDevicePublicKey[] = "public key"; | |
| 33 const char kRemoteDeviceBluetoothAddress[] = "AA:BB:CC:DD:EE:FF"; | |
| 34 const char kRemoteDevicePSK[] = "remote device psk"; | |
| 35 | |
| 36 class StubSecureContext : public SecureContext { | 31 class StubSecureContext : public SecureContext { |
| 37 public: | 32 public: |
| 38 StubSecureContext() {} | 33 StubSecureContext() {} |
| 39 ~StubSecureContext() override {} | 34 ~StubSecureContext() override {} |
| 40 | 35 |
| 41 void Decode(const std::string& encoded_message, | 36 void Decode(const std::string& encoded_message, |
| 42 const MessageCallback& callback) override { | 37 const MessageCallback& callback) override { |
| 43 NOTREACHED(); | 38 NOTREACHED(); |
| 44 } | 39 } |
| 45 | 40 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); | 142 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); |
| 148 }; | 143 }; |
| 149 | 144 |
| 150 } // namespace | 145 } // namespace |
| 151 | 146 |
| 152 class ProximityAuthRemoteDeviceLifeCycleImplTest | 147 class ProximityAuthRemoteDeviceLifeCycleImplTest |
| 153 : public testing::Test, | 148 : public testing::Test, |
| 154 public RemoteDeviceLifeCycle::Observer { | 149 public RemoteDeviceLifeCycle::Observer { |
| 155 protected: | 150 protected: |
| 156 ProximityAuthRemoteDeviceLifeCycleImplTest() | 151 ProximityAuthRemoteDeviceLifeCycleImplTest() |
| 157 : life_cycle_(RemoteDevice(kRemoteDeviceName, | 152 : life_cycle_(CreateClassicRemoteDeviceForTest()), |
| 158 kRemoteDevicePublicKey, | |
| 159 kRemoteDeviceBluetoothAddress, | |
| 160 kRemoteDevicePSK)), | |
| 161 task_runner_(new base::TestSimpleTaskRunner()), | 153 task_runner_(new base::TestSimpleTaskRunner()), |
| 162 thread_task_runner_handle_(task_runner_) {} | 154 thread_task_runner_handle_(task_runner_) {} |
| 163 | 155 |
| 164 ~ProximityAuthRemoteDeviceLifeCycleImplTest() override { | 156 ~ProximityAuthRemoteDeviceLifeCycleImplTest() override { |
| 165 life_cycle_.RemoveObserver(this); | 157 life_cycle_.RemoveObserver(this); |
| 166 } | 158 } |
| 167 | 159 |
| 168 void StartLifeCycle() { | 160 void StartLifeCycle() { |
| 169 EXPECT_EQ(RemoteDeviceLifeCycle::State::STOPPED, life_cycle_.GetState()); | 161 EXPECT_EQ(RemoteDeviceLifeCycle::State::STOPPED, life_cycle_.GetState()); |
| 170 life_cycle_.AddObserver(this); | 162 life_cycle_.AddObserver(this); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 278 |
| 287 // Authentication succeeds on second pass. | 279 // Authentication succeeds on second pass. |
| 288 Connection* connection = OnConnectionFound(); | 280 Connection* connection = OnConnectionFound(); |
| 289 Authenticate(Authenticator::Result::SUCCESS); | 281 Authenticate(Authenticator::Result::SUCCESS); |
| 290 EXPECT_TRUE(life_cycle_.GetMessenger()); | 282 EXPECT_TRUE(life_cycle_.GetMessenger()); |
| 291 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); | 283 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); |
| 292 connection->Disconnect(); | 284 connection->Disconnect(); |
| 293 } | 285 } |
| 294 | 286 |
| 295 } // namespace proximity_auth | 287 } // namespace proximity_auth |
| OLD | NEW |