Re-land: C++ readability review
[chromium-blink-merge.git] / google_apis / gcm / engine / fake_connection_handler.h
blobf1094780d08ddb1cf60872bba36559cd1a208398
1 // Copyright 2013 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.
5 #ifndef GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_HANDLER_H_
6 #define GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_HANDLER_H_
8 #include <list>
10 #include "google_apis/gcm/base/mcs_message.h"
11 #include "google_apis/gcm/engine/connection_handler.h"
13 namespace gcm {
15 // A fake implementation of a ConnectionHandler that can arbitrarily receive
16 // messages and verify expectations for outgoing messages.
17 class FakeConnectionHandler : public ConnectionHandler {
18 public:
19 FakeConnectionHandler(
20 const ConnectionHandler::ProtoReceivedCallback& read_callback,
21 const ConnectionHandler::ProtoSentCallback& write_callback);
22 ~FakeConnectionHandler() override;
24 // ConnectionHandler implementation.
25 void Init(const mcs_proto::LoginRequest& login_request,
26 net::StreamSocket* socket) override;
27 void Reset() override;
28 bool CanSendMessage() const override;
29 void SendMessage(const google::protobuf::MessageLite& message) override;
31 // EXPECT's receipt of |message| via SendMessage(..).
32 void ExpectOutgoingMessage(const MCSMessage& message);
34 // Reset the expected outgoing messages.
35 void ResetOutgoingMessageExpectations();
37 // Whether all expected outgoing messages have been received;
38 bool AllOutgoingMessagesReceived() const;
40 // Passes on |message| to |write_callback_|.
41 void ReceiveMessage(const MCSMessage& message);
43 // Whether to return an error with the next login response.
44 void set_fail_login(bool fail_login) {
45 fail_login_ = fail_login;
48 // Whether to invoke the write callback on the next send attempt or fake a
49 // connection error instead.
50 void set_fail_send(bool fail_send) {
51 fail_send_ = fail_send;
54 // Whether a socket-level error was encountered or not.
55 void set_had_error(bool had_error) {
56 had_error_ = had_error;
59 bool initialized() const { return initialized_; }
61 private:
62 ConnectionHandler::ProtoReceivedCallback read_callback_;
63 ConnectionHandler::ProtoSentCallback write_callback_;
65 std::list<MCSMessage> expected_outgoing_messages_;
67 // Whether to fail the login or not.
68 bool fail_login_;
70 // Whether to fail a SendMessage call or not.
71 bool fail_send_;
73 // Whether a successful login has completed.
74 bool initialized_;
76 // Whether an error was encountered after a successful login.
77 bool had_error_;
79 DISALLOW_COPY_AND_ASSIGN(FakeConnectionHandler);
82 } // namespace gcm
84 #endif // GOOGLE_APIS_GCM_ENGINE_FAKE_CONNECTION_HANDLER_H_