| 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/connection_handler_impl.h" | 5 #include "google_apis/gcm/engine/connection_handler_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <string> | 9 #include <string> |
| 8 | 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 14 #include "google/protobuf/io/coded_stream.h" | 16 #include "google/protobuf/io/coded_stream.h" |
| 15 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" | 17 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" |
| 16 #include "google/protobuf/wire_format_lite.h" | 18 #include "google/protobuf/wire_format_lite.h" |
| 17 #include "google_apis/gcm/base/mcs_util.h" | 19 #include "google_apis/gcm/base/mcs_util.h" |
| 18 #include "google_apis/gcm/base/socket_stream.h" | 20 #include "google_apis/gcm/base/socket_stream.h" |
| 19 #include "google_apis/gcm/protocol/mcs.pb.h" | 21 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 20 #include "net/socket/socket_test_util.h" | 22 #include "net/socket/socket_test_util.h" |
| 21 #include "net/socket/stream_socket.h" | 23 #include "net/socket/stream_socket.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 25 |
| 24 namespace gcm { | 26 namespace gcm { |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 typedef scoped_ptr<google::protobuf::MessageLite> ScopedMessage; | 29 typedef scoped_ptr<google::protobuf::MessageLite> ScopedMessage; |
| 28 typedef std::vector<net::MockRead> ReadList; | 30 typedef std::vector<net::MockRead> ReadList; |
| 29 typedef std::vector<net::MockWrite> WriteList; | 31 typedef std::vector<net::MockWrite> WriteList; |
| 30 | 32 |
| 31 const uint64 kAuthId = 54321; | 33 const uint64_t kAuthId = 54321; |
| 32 const uint64 kAuthToken = 12345; | 34 const uint64_t kAuthToken = 12345; |
| 33 const char kMCSVersion = 41; // The protocol version. | 35 const char kMCSVersion = 41; // The protocol version. |
| 34 const int kMCSPort = 5228; // The server port. | 36 const int kMCSPort = 5228; // The server port. |
| 35 const char kDataMsgFrom[] = "data_from"; | 37 const char kDataMsgFrom[] = "data_from"; |
| 36 const char kDataMsgCategory[] = "data_category"; | 38 const char kDataMsgCategory[] = "data_category"; |
| 37 const char kDataMsgFrom2[] = "data_from2"; | 39 const char kDataMsgFrom2[] = "data_from2"; |
| 38 const char kDataMsgCategory2[] = "data_category2"; | 40 const char kDataMsgCategory2[] = "data_category2"; |
| 39 const char kDataMsgFromLong[] = | 41 const char kDataMsgFromLong[] = |
| 40 "this is a long from that will result in a message > 128 bytes"; | 42 "this is a long from that will result in a message > 128 bytes"; |
| 41 const char kDataMsgCategoryLong[] = | 43 const char kDataMsgCategoryLong[] = |
| 42 "this is a long category that will result in a message > 128 bytes"; | 44 "this is a long category that will result in a message > 128 bytes"; |
| 43 const char kDataMsgFromLong2[] = | 45 const char kDataMsgFromLong2[] = |
| 44 "this is a second long from that will result in a message > 128 bytes"; | 46 "this is a second long from that will result in a message > 128 bytes"; |
| 45 const char kDataMsgCategoryLong2[] = | 47 const char kDataMsgCategoryLong2[] = |
| 46 "this is a second long category that will result in a message > 128 bytes"; | 48 "this is a second long category that will result in a message > 128 bytes"; |
| 47 const uint8 kInvalidTag = 100; // An invalid tag. | 49 const uint8_t kInvalidTag = 100; // An invalid tag. |
| 48 | 50 |
| 49 // ---- Helpers for building messages. ---- | 51 // ---- Helpers for building messages. ---- |
| 50 | 52 |
| 51 // Encode a protobuf packet with protobuf type |tag| and serialized protobuf | 53 // Encode a protobuf packet with protobuf type |tag| and serialized protobuf |
| 52 // bytes |proto| into the MCS message form (tag + varint size + bytes). | 54 // bytes |proto| into the MCS message form (tag + varint size + bytes). |
| 53 std::string EncodePacket(uint8 tag, const std::string& proto) { | 55 std::string EncodePacket(uint8_t tag, const std::string& proto) { |
| 54 std::string result; | 56 std::string result; |
| 55 google::protobuf::io::StringOutputStream string_output_stream(&result); | 57 google::protobuf::io::StringOutputStream string_output_stream(&result); |
| 56 { | 58 { |
| 57 google::protobuf::io::CodedOutputStream coded_output_stream( | 59 google::protobuf::io::CodedOutputStream coded_output_stream( |
| 58 &string_output_stream); | 60 &string_output_stream); |
| 59 const unsigned char tag_byte[1] = { tag }; | 61 const unsigned char tag_byte[1] = { tag }; |
| 60 coded_output_stream.WriteRaw(tag_byte, 1); | 62 coded_output_stream.WriteRaw(tag_byte, 1); |
| 61 coded_output_stream.WriteVarint32(proto.size()); | 63 coded_output_stream.WriteVarint32(proto.size()); |
| 62 coded_output_stream.WriteRaw(proto.c_str(), proto.size()); | 64 coded_output_stream.WriteRaw(proto.c_str(), proto.size()); |
| 63 // ~CodedOutputStream must run before the move constructor at the | 65 // ~CodedOutputStream must run before the move constructor at the |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 WaitForMessage(); // The login send. | 902 WaitForMessage(); // The login send. |
| 901 WaitForMessage(); // The login response. | 903 WaitForMessage(); // The login response. |
| 902 received_message.reset(); | 904 received_message.reset(); |
| 903 WaitForMessage(); // The invalid message. | 905 WaitForMessage(); // The invalid message. |
| 904 EXPECT_FALSE(received_message.get()); | 906 EXPECT_FALSE(received_message.get()); |
| 905 EXPECT_EQ(net::ERR_FAILED, last_error()); | 907 EXPECT_EQ(net::ERR_FAILED, last_error()); |
| 906 } | 908 } |
| 907 | 909 |
| 908 } // namespace | 910 } // namespace |
| 909 } // namespace gcm | 911 } // namespace gcm |
| OLD | NEW |