OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_PROXIMITY_AUTH_FAKE_CONNECTION_H | |
6 #define COMPONENTS_PROXIMITY_AUTH_FAKE_CONNECTION_H | |
7 | |
8 #include "base/macros.h" | |
9 #include "components/proximity_auth/connection.h" | |
10 | |
11 namespace proximity_auth { | |
12 | |
13 // A fake implementation of Connection to use in tests. | |
14 class FakeConnection : public Connection { | |
15 public: | |
16 FakeConnection(const cryptauth::RemoteDevice& remote_device); | |
17 ~FakeConnection() override; | |
18 | |
19 // Connection: | |
20 void Connect() override; | |
21 void Disconnect() override; | |
22 | |
23 // Completes the current send operation with success |success|. | |
24 void FinishSendingMessageWithSuccess(bool success); | |
25 | |
26 // Simulates receiving a wire message with the given |payload|, bypassing the | |
27 // container WireMessage format. | |
28 void ReceiveMessageWithPayload(const std::string& payload); | |
29 | |
30 // Returns the current message in progress of being sent. | |
31 WireMessage* current_message() { return current_message_.get(); } | |
32 | |
33 using Connection::SetStatus; | |
34 | |
35 private: | |
36 // Connection: | |
37 void SendMessageImpl(std::unique_ptr<WireMessage> message) override; | |
38 std::unique_ptr<WireMessage> DeserializeWireMessage( | |
39 bool* is_incomplete_message) override; | |
40 | |
41 // The message currently being sent. Only set between a call to | |
42 // SendMessageImpl() and FinishSendingMessageWithSuccess(). | |
43 std::unique_ptr<WireMessage> current_message_; | |
44 | |
45 // The payload that should be returned when DeserializeWireMessage() is | |
46 // called. | |
47 std::string pending_payload_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(FakeConnection); | |
50 }; | |
51 | |
52 } // namespace proximity_auth | |
53 | |
54 #endif // COMPONENTS_PROXIMITY_AUTH_FAKE_CONNECTION_H | |
OLD | NEW |