| 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/base/socket_stream.h" | 5 #include "google_apis/gcm/base/socket_stream.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "net/base/ip_address.h" |
| 14 #include "net/socket/socket_test_util.h" | 15 #include "net/socket/socket_test_util.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace gcm { | 18 namespace gcm { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 typedef std::vector<net::MockRead> ReadList; | 21 typedef std::vector<net::MockRead> ReadList; |
| 21 typedef std::vector<net::MockWrite> WriteList; | 22 typedef std::vector<net::MockWrite> WriteList; |
| 22 | 23 |
| 23 const char kReadData[] = "read_data"; | 24 const char kReadData[] = "read_data"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 // net:: components. | 72 // net:: components. |
| 72 scoped_ptr<net::StreamSocket> socket_; | 73 scoped_ptr<net::StreamSocket> socket_; |
| 73 net::MockClientSocketFactory socket_factory_; | 74 net::MockClientSocketFactory socket_factory_; |
| 74 net::AddressList address_list_; | 75 net::AddressList address_list_; |
| 75 | 76 |
| 76 base::MessageLoopForIO message_loop_; | 77 base::MessageLoopForIO message_loop_; |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 GCMSocketStreamTest::GCMSocketStreamTest() { | 80 GCMSocketStreamTest::GCMSocketStreamTest() { |
| 80 net::IPAddressNumber ip_number; | 81 address_list_ = net::AddressList::CreateFromIPAddress( |
| 81 net::ParseIPLiteralToNumber("127.0.0.1", &ip_number); | 82 net::IPAddress::IPv4Localhost(), 5228); |
| 82 address_list_ = net::AddressList::CreateFromIPAddress(ip_number, 5228); | |
| 83 } | 83 } |
| 84 | 84 |
| 85 GCMSocketStreamTest::~GCMSocketStreamTest() {} | 85 GCMSocketStreamTest::~GCMSocketStreamTest() {} |
| 86 | 86 |
| 87 void GCMSocketStreamTest::BuildSocket(const ReadList& read_list, | 87 void GCMSocketStreamTest::BuildSocket(const ReadList& read_list, |
| 88 const WriteList& write_list) { | 88 const WriteList& write_list) { |
| 89 mock_reads_ = read_list; | 89 mock_reads_ = read_list; |
| 90 mock_writes_ = write_list; | 90 mock_writes_ = write_list; |
| 91 data_provider_.reset(new net::StaticSocketDataProvider( | 91 data_provider_.reset(new net::StaticSocketDataProvider( |
| 92 mock_reads_.data(), mock_reads_.size(), mock_writes_.data(), | 92 mock_reads_.data(), mock_reads_.size(), mock_writes_.data(), |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 TEST_F(GCMSocketStreamTest, WriteDisconnected) { | 391 TEST_F(GCMSocketStreamTest, WriteDisconnected) { |
| 392 BuildSocket(ReadList(), WriteList()); | 392 BuildSocket(ReadList(), WriteList()); |
| 393 socket()->Disconnect(); | 393 socket()->Disconnect(); |
| 394 DoOutputStreamWrite(base::StringPiece(kWriteData, kWriteDataSize)); | 394 DoOutputStreamWrite(base::StringPiece(kWriteData, kWriteDataSize)); |
| 395 ASSERT_EQ(SocketOutputStream::CLOSED, output_stream()->GetState()); | 395 ASSERT_EQ(SocketOutputStream::CLOSED, output_stream()->GetState()); |
| 396 ASSERT_EQ(net::ERR_CONNECTION_CLOSED, output_stream()->last_error()); | 396 ASSERT_EQ(net::ERR_CONNECTION_CLOSED, output_stream()->last_error()); |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace | 399 } // namespace |
| 400 } // namespace gcm | 400 } // namespace gcm |
| OLD | NEW |