OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/client.h" | 5 #include "components/proximity_auth/client.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "components/proximity_auth/client_observer.h" | 9 #include "components/proximity_auth/client_observer.h" |
10 #include "components/proximity_auth/connection.h" | 10 #include "components/proximity_auth/connection.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return decoded_message; | 55 return decoded_message; |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 DISALLOW_COPY_AND_ASSIGN(MockSecureContext); | 59 DISALLOW_COPY_AND_ASSIGN(MockSecureContext); |
60 }; | 60 }; |
61 | 61 |
62 class FakeConnection : public Connection { | 62 class FakeConnection : public Connection { |
63 public: | 63 public: |
64 FakeConnection() : Connection(RemoteDevice()) { Connect(); } | 64 FakeConnection() : Connection(RemoteDevice()) { Connect(); } |
65 virtual ~FakeConnection() { Disconnect(); } | 65 ~FakeConnection() override { Disconnect(); } |
66 | 66 |
67 virtual void Connect() override { SetStatus(CONNECTED); } | 67 void Connect() override { SetStatus(CONNECTED); } |
68 | 68 |
69 virtual void Disconnect() override { SetStatus(DISCONNECTED); } | 69 void Disconnect() override { SetStatus(DISCONNECTED); } |
70 | 70 |
71 virtual void SendMessageImpl(scoped_ptr<WireMessage> message) override { | 71 void SendMessageImpl(scoped_ptr<WireMessage> message) override { |
72 ASSERT_FALSE(current_message_); | 72 ASSERT_FALSE(current_message_); |
73 current_message_ = message.Pass(); | 73 current_message_ = message.Pass(); |
74 } | 74 } |
75 | 75 |
76 // Completes the current send operation with success |success|. | 76 // Completes the current send operation with success |success|. |
77 void FinishSendingMessageWithSuccess(bool success) { | 77 void FinishSendingMessageWithSuccess(bool success) { |
78 ASSERT_TRUE(current_message_); | 78 ASSERT_TRUE(current_message_); |
79 // Capture a copy of the message, as OnDidSendMessage() might reentrantly | 79 // Capture a copy of the message, as OnDidSendMessage() might reentrantly |
80 // call SendMessage(). | 80 // call SendMessage(). |
81 scoped_ptr<WireMessage> sent_message = current_message_.Pass(); | 81 scoped_ptr<WireMessage> sent_message = current_message_.Pass(); |
82 OnDidSendMessage(*sent_message, success); | 82 OnDidSendMessage(*sent_message, success); |
83 } | 83 } |
84 | 84 |
85 // Simulates receiving a wire message with the given |payload|. | 85 // Simulates receiving a wire message with the given |payload|. |
86 void ReceiveMessageWithPayload(const std::string& payload) { | 86 void ReceiveMessageWithPayload(const std::string& payload) { |
87 pending_payload_ = payload; | 87 pending_payload_ = payload; |
88 OnBytesReceived(std::string()); | 88 OnBytesReceived(std::string()); |
89 pending_payload_.clear(); | 89 pending_payload_.clear(); |
90 } | 90 } |
91 | 91 |
92 // Returns a message containing the payload set via | 92 // Returns a message containing the payload set via |
93 // ReceiveMessageWithPayload(). | 93 // ReceiveMessageWithPayload(). |
94 virtual scoped_ptr<WireMessage> DeserializeWireMessage( | 94 scoped_ptr<WireMessage> DeserializeWireMessage( |
95 bool* is_incomplete_message) override { | 95 bool* is_incomplete_message) override { |
96 *is_incomplete_message = false; | 96 *is_incomplete_message = false; |
97 return make_scoped_ptr(new WireMessage(std::string(), pending_payload_)); | 97 return make_scoped_ptr(new WireMessage(std::string(), pending_payload_)); |
98 } | 98 } |
99 | 99 |
100 WireMessage* current_message() { return current_message_.get(); } | 100 WireMessage* current_message() { return current_message_.get(); } |
101 | 101 |
102 private: | 102 private: |
103 // The message currently being sent. Only set between a call to | 103 // The message currently being sent. Only set between a call to |
104 // SendMessageImpl() and FinishSendingMessageWithSuccess(). | 104 // SendMessageImpl() and FinishSendingMessageWithSuccess(). |
(...skipping 30 matching lines...) Expand all Loading... |
135 Client* const client_; | 135 Client* const client_; |
136 | 136 |
137 DISALLOW_COPY_AND_ASSIGN(MockClientObserver); | 137 DISALLOW_COPY_AND_ASSIGN(MockClientObserver); |
138 }; | 138 }; |
139 | 139 |
140 class TestClient : public Client { | 140 class TestClient : public Client { |
141 public: | 141 public: |
142 TestClient() | 142 TestClient() |
143 : Client(make_scoped_ptr(new NiceMock<FakeConnection>()), | 143 : Client(make_scoped_ptr(new NiceMock<FakeConnection>()), |
144 make_scoped_ptr(new NiceMock<MockSecureContext>())) {} | 144 make_scoped_ptr(new NiceMock<MockSecureContext>())) {} |
145 virtual ~TestClient() {} | 145 ~TestClient() override {} |
146 | 146 |
147 // Simple getters for the mock objects owned by |this| client. | 147 // Simple getters for the mock objects owned by |this| client. |
148 FakeConnection* GetFakeConnection() { | 148 FakeConnection* GetFakeConnection() { |
149 return static_cast<FakeConnection*>(connection()); | 149 return static_cast<FakeConnection*>(connection()); |
150 } | 150 } |
151 MockSecureContext* GetMockSecureContext() { | 151 MockSecureContext* GetMockSecureContext() { |
152 return static_cast<MockSecureContext*>(secure_context()); | 152 return static_cast<MockSecureContext*>(secure_context()); |
153 } | 153 } |
154 | 154 |
155 private: | 155 private: |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 "\"data\":\"YSB3aW5uZXIgaXMgeW91\"" | 504 "\"data\":\"YSB3aW5uZXIgaXMgeW91\"" |
505 "}, but encoded"); | 505 "}, but encoded"); |
506 | 506 |
507 // The unlock request should have remained buffered, and should only now be | 507 // The unlock request should have remained buffered, and should only now be |
508 // sent. | 508 // sent. |
509 EXPECT_CALL(observer, OnUnlockResponse(false)); | 509 EXPECT_CALL(observer, OnUnlockResponse(false)); |
510 client.GetFakeConnection()->FinishSendingMessageWithSuccess(false); | 510 client.GetFakeConnection()->FinishSendingMessageWithSuccess(false); |
511 } | 511 } |
512 | 512 |
513 } // namespace proximity_auth | 513 } // namespace proximity_auth |
OLD | NEW |