| 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> | 7 #include <stdint.h> |
| 8 |
| 9 #include <memory> |
| 8 #include <string> | 10 #include <string> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/bind.h" | 13 #include "base/bind.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 16 #include "google/protobuf/io/coded_stream.h" | 17 #include "google/protobuf/io/coded_stream.h" |
| 17 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" | 18 #include "google/protobuf/io/zero_copy_stream_impl_lite.h" |
| 18 #include "google/protobuf/wire_format_lite.h" | 19 #include "google/protobuf/wire_format_lite.h" |
| 19 #include "google_apis/gcm/base/mcs_util.h" | 20 #include "google_apis/gcm/base/mcs_util.h" |
| 20 #include "google_apis/gcm/base/socket_stream.h" | 21 #include "google_apis/gcm/base/socket_stream.h" |
| 21 #include "google_apis/gcm/protocol/mcs.pb.h" | 22 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 22 #include "net/base/ip_address.h" | 23 #include "net/base/ip_address.h" |
| 23 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
| 24 #include "net/socket/stream_socket.h" | 25 #include "net/socket/stream_socket.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 namespace gcm { | 28 namespace gcm { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 typedef scoped_ptr<google::protobuf::MessageLite> ScopedMessage; | 31 typedef std::unique_ptr<google::protobuf::MessageLite> ScopedMessage; |
| 31 typedef std::vector<net::MockRead> ReadList; | 32 typedef std::vector<net::MockRead> ReadList; |
| 32 typedef std::vector<net::MockWrite> WriteList; | 33 typedef std::vector<net::MockWrite> WriteList; |
| 33 | 34 |
| 34 const uint64_t kAuthId = 54321; | 35 const uint64_t kAuthId = 54321; |
| 35 const uint64_t kAuthToken = 12345; | 36 const uint64_t kAuthToken = 12345; |
| 36 const char kMCSVersion = 41; // The protocol version. | 37 const char kMCSVersion = 41; // The protocol version. |
| 37 const int kMCSPort = 5228; // The server port. | 38 const int kMCSPort = 5228; // The server port. |
| 38 const char kDataMsgFrom[] = "data_from"; | 39 const char kDataMsgFrom[] = "data_from"; |
| 39 const char kDataMsgCategory[] = "data_category"; | 40 const char kDataMsgCategory[] = "data_category"; |
| 40 const char kDataMsgFrom2[] = "data_from2"; | 41 const char kDataMsgFrom2[] = "data_from2"; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 void WaitForMessage(); | 165 void WaitForMessage(); |
| 165 | 166 |
| 166 private: | 167 private: |
| 167 void ReadContinuation(ScopedMessage* dst_proto, ScopedMessage new_proto); | 168 void ReadContinuation(ScopedMessage* dst_proto, ScopedMessage new_proto); |
| 168 void WriteContinuation(); | 169 void WriteContinuation(); |
| 169 void ConnectionContinuation(int error); | 170 void ConnectionContinuation(int error); |
| 170 | 171 |
| 171 // SocketStreams and their data provider. | 172 // SocketStreams and their data provider. |
| 172 ReadList mock_reads_; | 173 ReadList mock_reads_; |
| 173 WriteList mock_writes_; | 174 WriteList mock_writes_; |
| 174 scoped_ptr<net::StaticSocketDataProvider> data_provider_; | 175 std::unique_ptr<net::StaticSocketDataProvider> data_provider_; |
| 175 | 176 |
| 176 // The connection handler being tested. | 177 // The connection handler being tested. |
| 177 scoped_ptr<ConnectionHandlerImpl> connection_handler_; | 178 std::unique_ptr<ConnectionHandlerImpl> connection_handler_; |
| 178 | 179 |
| 179 // The last connection error received. | 180 // The last connection error received. |
| 180 int last_error_; | 181 int last_error_; |
| 181 | 182 |
| 182 // net:: components. | 183 // net:: components. |
| 183 scoped_ptr<net::StreamSocket> socket_; | 184 std::unique_ptr<net::StreamSocket> socket_; |
| 184 net::MockClientSocketFactory socket_factory_; | 185 net::MockClientSocketFactory socket_factory_; |
| 185 net::AddressList address_list_; | 186 net::AddressList address_list_; |
| 186 | 187 |
| 187 base::MessageLoopForIO message_loop_; | 188 base::MessageLoopForIO message_loop_; |
| 188 scoped_ptr<base::RunLoop> run_loop_; | 189 std::unique_ptr<base::RunLoop> run_loop_; |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 GCMConnectionHandlerImplTest::GCMConnectionHandlerImplTest() | 192 GCMConnectionHandlerImplTest::GCMConnectionHandlerImplTest() |
| 192 : last_error_(0) { | 193 : last_error_(0) { |
| 193 address_list_ = net::AddressList::CreateFromIPAddress( | 194 address_list_ = net::AddressList::CreateFromIPAddress( |
| 194 net::IPAddress::IPv4Localhost(), kMCSPort); | 195 net::IPAddress::IPv4Localhost(), kMCSPort); |
| 195 } | 196 } |
| 196 | 197 |
| 197 GCMConnectionHandlerImplTest::~GCMConnectionHandlerImplTest() { | 198 GCMConnectionHandlerImplTest::~GCMConnectionHandlerImplTest() { |
| 198 } | 199 } |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 WaitForMessage(); // The login send. | 903 WaitForMessage(); // The login send. |
| 903 WaitForMessage(); // The login response. | 904 WaitForMessage(); // The login response. |
| 904 received_message.reset(); | 905 received_message.reset(); |
| 905 WaitForMessage(); // The invalid message. | 906 WaitForMessage(); // The invalid message. |
| 906 EXPECT_FALSE(received_message.get()); | 907 EXPECT_FALSE(received_message.get()); |
| 907 EXPECT_EQ(net::ERR_FAILED, last_error()); | 908 EXPECT_EQ(net::ERR_FAILED, last_error()); |
| 908 } | 909 } |
| 909 | 910 |
| 910 } // namespace | 911 } // namespace |
| 911 } // namespace gcm | 912 } // namespace gcm |
| OLD | NEW |