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