| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "google_apis/gcm/engine/fake_connection_handler.h" | 5 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "google_apis/gcm/base/mcs_util.h" | 8 #include "google_apis/gcm/base/mcs_util.h" |
| 9 #include "net/socket/stream_socket.h" | 9 #include "net/socket/stream_socket.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 FakeConnectionHandler::FakeConnectionHandler( | 28 FakeConnectionHandler::FakeConnectionHandler( |
| 29 const ConnectionHandler::ProtoReceivedCallback& read_callback, | 29 const ConnectionHandler::ProtoReceivedCallback& read_callback, |
| 30 const ConnectionHandler::ProtoSentCallback& write_callback) | 30 const ConnectionHandler::ProtoSentCallback& write_callback) |
| 31 : read_callback_(read_callback), | 31 : read_callback_(read_callback), |
| 32 write_callback_(write_callback), | 32 write_callback_(write_callback), |
| 33 fail_login_(false), | 33 fail_login_(false), |
| 34 fail_send_(false), | 34 fail_send_(false), |
| 35 initialized_(false) { | 35 initialized_(false), |
| 36 had_error_(false) { |
| 36 } | 37 } |
| 37 | 38 |
| 38 FakeConnectionHandler::~FakeConnectionHandler() { | 39 FakeConnectionHandler::~FakeConnectionHandler() { |
| 39 } | 40 } |
| 40 | 41 |
| 41 void FakeConnectionHandler::Init(const mcs_proto::LoginRequest& login_request, | 42 void FakeConnectionHandler::Init(const mcs_proto::LoginRequest& login_request, |
| 42 net::StreamSocket* socket) { | 43 net::StreamSocket* socket) { |
| 43 ASSERT_GE(expected_outgoing_messages_.size(), 1U); | 44 ASSERT_GE(expected_outgoing_messages_.size(), 1U); |
| 44 EXPECT_EQ(expected_outgoing_messages_.front().SerializeAsString(), | 45 EXPECT_EQ(expected_outgoing_messages_.front().SerializeAsString(), |
| 45 login_request.SerializeAsString()); | 46 login_request.SerializeAsString()); |
| 46 expected_outgoing_messages_.pop_front(); | 47 expected_outgoing_messages_.pop_front(); |
| 47 DVLOG(1) << "Received init call."; | 48 DVLOG(1) << "Received init call."; |
| 48 read_callback_.Run(BuildLoginResponse(fail_login_)); | 49 read_callback_.Run(BuildLoginResponse(fail_login_)); |
| 49 initialized_ = !fail_login_; | 50 initialized_ = !fail_login_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 void FakeConnectionHandler::Reset() { | 53 void FakeConnectionHandler::Reset() { |
| 53 initialized_ = false; | 54 initialized_ = false; |
| 55 had_error_ = false; |
| 54 } | 56 } |
| 55 | 57 |
| 56 bool FakeConnectionHandler::CanSendMessage() const { | 58 bool FakeConnectionHandler::CanSendMessage() const { |
| 57 return initialized_; | 59 return initialized_ && !had_error_; |
| 58 } | 60 } |
| 59 | 61 |
| 60 void FakeConnectionHandler::SendMessage( | 62 void FakeConnectionHandler::SendMessage( |
| 61 const google::protobuf::MessageLite& message) { | 63 const google::protobuf::MessageLite& message) { |
| 62 if (expected_outgoing_messages_.empty()) | 64 if (expected_outgoing_messages_.empty()) |
| 63 FAIL() << "Unexpected message sent."; | 65 FAIL() << "Unexpected message sent."; |
| 64 EXPECT_EQ(expected_outgoing_messages_.front().SerializeAsString(), | 66 EXPECT_EQ(expected_outgoing_messages_.front().SerializeAsString(), |
| 65 message.SerializeAsString()); | 67 message.SerializeAsString()); |
| 66 expected_outgoing_messages_.pop_front(); | 68 expected_outgoing_messages_.pop_front(); |
| 67 DVLOG(1) << "Received message, " | 69 DVLOG(1) << "Received message, " |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 | 84 |
| 83 bool FakeConnectionHandler::AllOutgoingMessagesReceived() const { | 85 bool FakeConnectionHandler::AllOutgoingMessagesReceived() const { |
| 84 return expected_outgoing_messages_.empty(); | 86 return expected_outgoing_messages_.empty(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void FakeConnectionHandler::ReceiveMessage(const MCSMessage& message) { | 89 void FakeConnectionHandler::ReceiveMessage(const MCSMessage& message) { |
| 88 read_callback_.Run(message.CloneProtobuf()); | 90 read_callback_.Run(message.CloneProtobuf()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace gcm | 93 } // namespace gcm |
| OLD | NEW |