| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <utility> | 10 #include <utility> |
| 9 | 11 |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
| 14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 15 #include "components/proximity_auth/authenticator.h" | 16 #include "components/proximity_auth/authenticator.h" |
| 16 #include "components/proximity_auth/connection_finder.h" | 17 #include "components/proximity_auth/connection_finder.h" |
| 17 #include "components/proximity_auth/fake_connection.h" | 18 #include "components/proximity_auth/fake_connection.h" |
| 18 #include "components/proximity_auth/messenger.h" | 19 #include "components/proximity_auth/messenger.h" |
| 19 #include "components/proximity_auth/proximity_auth_test_util.h" | 20 #include "components/proximity_auth/proximity_auth_test_util.h" |
| 20 #include "components/proximity_auth/secure_context.h" | 21 #include "components/proximity_auth/secure_context.h" |
| 21 #include "components/proximity_auth/wire_message.h" | 22 #include "components/proximity_auth/wire_message.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 class FakeConnectionFinder : public ConnectionFinder { | 62 class FakeConnectionFinder : public ConnectionFinder { |
| 62 public: | 63 public: |
| 63 FakeConnectionFinder(const RemoteDevice& remote_device) | 64 FakeConnectionFinder(const RemoteDevice& remote_device) |
| 64 : remote_device_(remote_device), connection_(nullptr) {} | 65 : remote_device_(remote_device), connection_(nullptr) {} |
| 65 ~FakeConnectionFinder() override {} | 66 ~FakeConnectionFinder() override {} |
| 66 | 67 |
| 67 void OnConnectionFound() { | 68 void OnConnectionFound() { |
| 68 ASSERT_FALSE(connection_callback_.is_null()); | 69 ASSERT_FALSE(connection_callback_.is_null()); |
| 69 scoped_ptr<FakeConnection> scoped_connection_( | 70 std::unique_ptr<FakeConnection> scoped_connection_( |
| 70 new FakeConnection(remote_device_)); | 71 new FakeConnection(remote_device_)); |
| 71 connection_ = scoped_connection_.get(); | 72 connection_ = scoped_connection_.get(); |
| 72 connection_callback_.Run(std::move(scoped_connection_)); | 73 connection_callback_.Run(std::move(scoped_connection_)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 FakeConnection* connection() { return connection_; } | 76 FakeConnection* connection() { return connection_; } |
| 76 | 77 |
| 77 private: | 78 private: |
| 78 // ConnectionFinder: | 79 // ConnectionFinder: |
| 79 void Find(const ConnectionCallback& connection_callback) override { | 80 void Find(const ConnectionCallback& connection_callback) override { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 96 ~FakeAuthenticator() override { | 97 ~FakeAuthenticator() override { |
| 97 // This object should be destroyed immediately after authentication is | 98 // This object should be destroyed immediately after authentication is |
| 98 // complete in order not to outlive the underlying connection. | 99 // complete in order not to outlive the underlying connection. |
| 99 EXPECT_FALSE(callback_.is_null()); | 100 EXPECT_FALSE(callback_.is_null()); |
| 100 EXPECT_EQ(kTestRemoteDevicePublicKey, | 101 EXPECT_EQ(kTestRemoteDevicePublicKey, |
| 101 connection_->remote_device().public_key); | 102 connection_->remote_device().public_key); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void OnAuthenticationResult(Authenticator::Result result) { | 105 void OnAuthenticationResult(Authenticator::Result result) { |
| 105 ASSERT_FALSE(callback_.is_null()); | 106 ASSERT_FALSE(callback_.is_null()); |
| 106 scoped_ptr<SecureContext> secure_context; | 107 std::unique_ptr<SecureContext> secure_context; |
| 107 if (result == Authenticator::Result::SUCCESS) | 108 if (result == Authenticator::Result::SUCCESS) |
| 108 secure_context.reset(new StubSecureContext()); | 109 secure_context.reset(new StubSecureContext()); |
| 109 callback_.Run(result, std::move(secure_context)); | 110 callback_.Run(result, std::move(secure_context)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 // Authenticator: | 114 // Authenticator: |
| 114 void Authenticate(const AuthenticationCallback& callback) override { | 115 void Authenticate(const AuthenticationCallback& callback) override { |
| 115 ASSERT_TRUE(callback_.is_null()); | 116 ASSERT_TRUE(callback_.is_null()); |
| 116 callback_ = callback; | 117 callback_ = callback; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device) | 130 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device) |
| 130 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), | 131 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), |
| 131 remote_device_(remote_device) {} | 132 remote_device_(remote_device) {} |
| 132 | 133 |
| 133 ~TestableRemoteDeviceLifeCycleImpl() override {} | 134 ~TestableRemoteDeviceLifeCycleImpl() override {} |
| 134 | 135 |
| 135 FakeConnectionFinder* connection_finder() { return connection_finder_; } | 136 FakeConnectionFinder* connection_finder() { return connection_finder_; } |
| 136 FakeAuthenticator* authenticator() { return authenticator_; } | 137 FakeAuthenticator* authenticator() { return authenticator_; } |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 scoped_ptr<ConnectionFinder> CreateConnectionFinder() override { | 140 std::unique_ptr<ConnectionFinder> CreateConnectionFinder() override { |
| 140 scoped_ptr<FakeConnectionFinder> scoped_connection_finder( | 141 std::unique_ptr<FakeConnectionFinder> scoped_connection_finder( |
| 141 new FakeConnectionFinder(remote_device_)); | 142 new FakeConnectionFinder(remote_device_)); |
| 142 connection_finder_ = scoped_connection_finder.get(); | 143 connection_finder_ = scoped_connection_finder.get(); |
| 143 return std::move(scoped_connection_finder); | 144 return std::move(scoped_connection_finder); |
| 144 } | 145 } |
| 145 | 146 |
| 146 scoped_ptr<Authenticator> CreateAuthenticator() override { | 147 std::unique_ptr<Authenticator> CreateAuthenticator() override { |
| 147 EXPECT_TRUE(connection_finder_); | 148 EXPECT_TRUE(connection_finder_); |
| 148 scoped_ptr<FakeAuthenticator> scoped_authenticator( | 149 std::unique_ptr<FakeAuthenticator> scoped_authenticator( |
| 149 new FakeAuthenticator(connection_finder_->connection())); | 150 new FakeAuthenticator(connection_finder_->connection())); |
| 150 authenticator_ = scoped_authenticator.get(); | 151 authenticator_ = scoped_authenticator.get(); |
| 151 return std::move(scoped_authenticator); | 152 return std::move(scoped_authenticator); |
| 152 } | 153 } |
| 153 | 154 |
| 154 const RemoteDevice remote_device_; | 155 const RemoteDevice remote_device_; |
| 155 FakeConnectionFinder* connection_finder_; | 156 FakeConnectionFinder* connection_finder_; |
| 156 FakeAuthenticator* authenticator_; | 157 FakeAuthenticator* authenticator_; |
| 157 | 158 |
| 158 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); | 159 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 307 |
| 307 // Authentication succeeds on second pass. | 308 // Authentication succeeds on second pass. |
| 308 Connection* connection = OnConnectionFound(); | 309 Connection* connection = OnConnectionFound(); |
| 309 Authenticate(Authenticator::Result::SUCCESS); | 310 Authenticate(Authenticator::Result::SUCCESS); |
| 310 EXPECT_TRUE(life_cycle_.GetMessenger()); | 311 EXPECT_TRUE(life_cycle_.GetMessenger()); |
| 311 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); | 312 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); |
| 312 connection->Disconnect(); | 313 connection->Disconnect(); |
| 313 } | 314 } |
| 314 | 315 |
| 315 } // namespace proximity_auth | 316 } // namespace proximity_auth |
| OLD | NEW |