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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 const char kReadData[] = "read_data"; | 22 const char kReadData[] = "read_data"; |
23 const int kReadDataSize = arraysize(kReadData) - 1; | 23 const int kReadDataSize = arraysize(kReadData) - 1; |
24 const char kReadData2[] = "read_alternate_data"; | 24 const char kReadData2[] = "read_alternate_data"; |
25 const int kReadData2Size = arraysize(kReadData2) - 1; | 25 const int kReadData2Size = arraysize(kReadData2) - 1; |
26 const char kWriteData[] = "write_data"; | 26 const char kWriteData[] = "write_data"; |
27 const int kWriteDataSize = arraysize(kWriteData) - 1; | 27 const int kWriteDataSize = arraysize(kWriteData) - 1; |
28 | 28 |
29 class GCMSocketStreamTest : public testing::Test { | 29 class GCMSocketStreamTest : public testing::Test { |
30 public: | 30 public: |
31 GCMSocketStreamTest(); | 31 GCMSocketStreamTest(); |
32 virtual ~GCMSocketStreamTest(); | 32 ~GCMSocketStreamTest() override; |
33 | 33 |
34 // Build a socket with the expected reads and writes. | 34 // Build a socket with the expected reads and writes. |
35 void BuildSocket(const ReadList& read_list, const WriteList& write_list); | 35 void BuildSocket(const ReadList& read_list, const WriteList& write_list); |
36 | 36 |
37 // Pump the message loop until idle. | 37 // Pump the message loop until idle. |
38 void PumpLoop(); | 38 void PumpLoop(); |
39 | 39 |
40 // Simulates a google::protobuf::io::CodedInputStream read. | 40 // Simulates a google::protobuf::io::CodedInputStream read. |
41 base::StringPiece DoInputStreamRead(int bytes); | 41 base::StringPiece DoInputStreamRead(int bytes); |
42 // Simulates a google::protobuf::io::CodedOutputStream write. | 42 // Simulates a google::protobuf::io::CodedOutputStream write. |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 TEST_F(GCMSocketStreamTest, WriteDisconnected) { | 397 TEST_F(GCMSocketStreamTest, WriteDisconnected) { |
398 BuildSocket(ReadList(), WriteList()); | 398 BuildSocket(ReadList(), WriteList()); |
399 socket()->Disconnect(); | 399 socket()->Disconnect(); |
400 DoOutputStreamWrite(base::StringPiece(kWriteData, kWriteDataSize)); | 400 DoOutputStreamWrite(base::StringPiece(kWriteData, kWriteDataSize)); |
401 ASSERT_EQ(SocketOutputStream::CLOSED, output_stream()->GetState()); | 401 ASSERT_EQ(SocketOutputStream::CLOSED, output_stream()->GetState()); |
402 ASSERT_EQ(net::ERR_CONNECTION_CLOSED, output_stream()->last_error()); | 402 ASSERT_EQ(net::ERR_CONNECTION_CLOSED, output_stream()->last_error()); |
403 } | 403 } |
404 | 404 |
405 } // namespace | 405 } // namespace |
406 } // namespace gcm | 406 } // namespace gcm |
OLD | NEW |