| 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/device_to_device_authenticator.h" | 5 #include "components/proximity_auth/device_to_device_authenticator.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 11 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 12 #include "base/timer/mock_timer.h" | 14 #include "base/timer/mock_timer.h" |
| 13 #include "components/proximity_auth/connection.h" | 15 #include "components/proximity_auth/connection.h" |
| 14 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 16 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" |
| 15 #include "components/proximity_auth/device_to_device_responder_operations.h" | 17 #include "components/proximity_auth/device_to_device_responder_operations.h" |
| 16 #include "components/proximity_auth/proximity_auth_test_util.h" | 18 #include "components/proximity_auth/proximity_auth_test_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void set_connection_blocked(bool connection_blocked) { | 79 void set_connection_blocked(bool connection_blocked) { |
| 78 connection_blocked_ = connection_blocked; | 80 connection_blocked_ = connection_blocked; |
| 79 } | 81 } |
| 80 | 82 |
| 81 bool connection_blocked() { return connection_blocked_; } | 83 bool connection_blocked() { return connection_blocked_; } |
| 82 | 84 |
| 83 protected: | 85 protected: |
| 84 // Connection: | 86 // Connection: |
| 85 void SendMessageImpl(scoped_ptr<WireMessage> message) override { | 87 void SendMessageImpl(scoped_ptr<WireMessage> message) override { |
| 86 const WireMessage& message_alias = *message; | 88 const WireMessage& message_alias = *message; |
| 87 message_buffer_.push_back(message.Pass()); | 89 message_buffer_.push_back(std::move(message)); |
| 88 OnDidSendMessage(message_alias, !connection_blocked_); | 90 OnDidSendMessage(message_alias, !connection_blocked_); |
| 89 } | 91 } |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 ScopedVector<WireMessage> message_buffer_; | 94 ScopedVector<WireMessage> message_buffer_; |
| 93 | 95 |
| 94 bool connection_blocked_; | 96 bool connection_blocked_; |
| 95 | 97 |
| 96 DISALLOW_COPY_AND_ASSIGN(FakeConnection); | 98 DISALLOW_COPY_AND_ASSIGN(FakeConnection); |
| 97 }; | 99 }; |
| 98 | 100 |
| 99 // Harness for testing DeviceToDeviceAuthenticator. | 101 // Harness for testing DeviceToDeviceAuthenticator. |
| 100 class DeviceToDeviceAuthenticatorForTest : public DeviceToDeviceAuthenticator { | 102 class DeviceToDeviceAuthenticatorForTest : public DeviceToDeviceAuthenticator { |
| 101 public: | 103 public: |
| 102 DeviceToDeviceAuthenticatorForTest( | 104 DeviceToDeviceAuthenticatorForTest( |
| 103 Connection* connection, | 105 Connection* connection, |
| 104 scoped_ptr<SecureMessageDelegate> secure_message_delegate) | 106 scoped_ptr<SecureMessageDelegate> secure_message_delegate) |
| 105 : DeviceToDeviceAuthenticator(connection, | 107 : DeviceToDeviceAuthenticator(connection, |
| 106 kAccountId, | 108 kAccountId, |
| 107 secure_message_delegate.Pass()), | 109 std::move(secure_message_delegate)), |
| 108 timer_(nullptr) {} | 110 timer_(nullptr) {} |
| 109 ~DeviceToDeviceAuthenticatorForTest() override {} | 111 ~DeviceToDeviceAuthenticatorForTest() override {} |
| 110 | 112 |
| 111 base::MockTimer* timer() { return timer_; } | 113 base::MockTimer* timer() { return timer_; } |
| 112 | 114 |
| 113 private: | 115 private: |
| 114 // DeviceToDeviceAuthenticator: | 116 // DeviceToDeviceAuthenticator: |
| 115 scoped_ptr<base::Timer> CreateTimer() override { | 117 scoped_ptr<base::Timer> CreateTimer() override { |
| 116 bool retain_user_task = false; | 118 bool retain_user_task = false; |
| 117 bool is_repeating = false; | 119 bool is_repeating = false; |
| 118 | 120 |
| 119 scoped_ptr<base::MockTimer> timer( | 121 scoped_ptr<base::MockTimer> timer( |
| 120 new base::MockTimer(retain_user_task, is_repeating)); | 122 new base::MockTimer(retain_user_task, is_repeating)); |
| 121 | 123 |
| 122 timer_ = timer.get(); | 124 timer_ = timer.get(); |
| 123 return timer.Pass(); | 125 return std::move(timer); |
| 124 } | 126 } |
| 125 | 127 |
| 126 // This instance is owned by the super class. | 128 // This instance is owned by the super class. |
| 127 base::MockTimer* timer_; | 129 base::MockTimer* timer_; |
| 128 | 130 |
| 129 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceAuthenticatorForTest); | 131 DISALLOW_COPY_AND_ASSIGN(DeviceToDeviceAuthenticatorForTest); |
| 130 }; | 132 }; |
| 131 | 133 |
| 132 } // namespace | 134 } // namespace |
| 133 | 135 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 EXPECT_FALSE(responder_auth_message.empty()); | 207 EXPECT_FALSE(responder_auth_message.empty()); |
| 206 | 208 |
| 207 WireMessage wire_message(responder_auth_message); | 209 WireMessage wire_message(responder_auth_message); |
| 208 connection_.OnBytesReceived(wire_message.Serialize()); | 210 connection_.OnBytesReceived(wire_message.Serialize()); |
| 209 | 211 |
| 210 return responder_auth_message; | 212 return responder_auth_message; |
| 211 } | 213 } |
| 212 | 214 |
| 213 void OnAuthenticationResult(Authenticator::Result result, | 215 void OnAuthenticationResult(Authenticator::Result result, |
| 214 scoped_ptr<SecureContext> secure_context) { | 216 scoped_ptr<SecureContext> secure_context) { |
| 215 secure_context_ = secure_context.Pass(); | 217 secure_context_ = std::move(secure_context); |
| 216 OnAuthenticationResultProxy(result); | 218 OnAuthenticationResultProxy(result); |
| 217 } | 219 } |
| 218 | 220 |
| 219 MOCK_METHOD1(OnAuthenticationResultProxy, void(Authenticator::Result result)); | 221 MOCK_METHOD1(OnAuthenticationResultProxy, void(Authenticator::Result result)); |
| 220 | 222 |
| 221 // Contains information about the remote device. | 223 // Contains information about the remote device. |
| 222 const RemoteDevice remote_device_; | 224 const RemoteDevice remote_device_; |
| 223 | 225 |
| 224 // Simulates the connection to the remote device. | 226 // Simulates the connection to the remote device. |
| 225 FakeConnection connection_; | 227 FakeConnection connection_; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 WireMessage wire_message(base::RandBytesAsString(300u)); | 341 WireMessage wire_message(base::RandBytesAsString(300u)); |
| 340 connection_.SendMessage( | 342 connection_.SendMessage( |
| 341 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); | 343 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); |
| 342 connection_.OnBytesReceived(wire_message.Serialize()); | 344 connection_.OnBytesReceived(wire_message.Serialize()); |
| 343 connection_.SendMessage( | 345 connection_.SendMessage( |
| 344 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); | 346 make_scoped_ptr(new WireMessage(base::RandBytesAsString(300u)))); |
| 345 connection_.OnBytesReceived(wire_message.Serialize()); | 347 connection_.OnBytesReceived(wire_message.Serialize()); |
| 346 } | 348 } |
| 347 | 349 |
| 348 } // namespace proximity_auth | 350 } // namespace proximity_auth |
| OLD | NEW |