| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/byte_stream.h" | 5 #include "content/browser/byte_stream.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 // Push a series of IO buffers on; test pushback happening and | 110 // Push a series of IO buffers on; test pushback happening and |
| 111 // that it's advisory. | 111 // that it's advisory. |
| 112 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 112 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
| 113 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 113 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
| 114 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 114 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
| 115 EXPECT_FALSE(Write(byte_stream_input.get(), 1)); | 115 EXPECT_FALSE(Write(byte_stream_input.get(), 1)); |
| 116 EXPECT_FALSE(Write(byte_stream_input.get(), 1024)); | 116 EXPECT_FALSE(Write(byte_stream_input.get(), 1024)); |
| 117 // Flush | 117 // Flush |
| 118 byte_stream_input->Close(0); | 118 byte_stream_input->Close(0); |
| 119 EXPECT_EQ(4 * 1024U + 1U, byte_stream_input->GetTotalBufferedBytes()); |
| 119 message_loop_.RunUntilIdle(); | 120 message_loop_.RunUntilIdle(); |
| 121 // Data already sent to reader is also counted in. |
| 122 EXPECT_EQ(4 * 1024U + 1U, byte_stream_input->GetTotalBufferedBytes()); |
| 120 | 123 |
| 121 // Pull the IO buffers out; do we get the same buffers and do they | 124 // Pull the IO buffers out; do we get the same buffers and do they |
| 122 // have the same contents? | 125 // have the same contents? |
| 123 scoped_refptr<net::IOBuffer> output_io_buffer; | 126 scoped_refptr<net::IOBuffer> output_io_buffer; |
| 124 size_t output_length; | 127 size_t output_length; |
| 125 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 128 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
| 126 byte_stream_output->Read(&output_io_buffer, &output_length)); | 129 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 127 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 130 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
| 128 | 131 |
| 129 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 132 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
| 130 byte_stream_output->Read(&output_io_buffer, &output_length)); | 133 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 131 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 134 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
| 132 | 135 |
| 133 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 136 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
| 134 byte_stream_output->Read(&output_io_buffer, &output_length)); | 137 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 135 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 138 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
| 136 | 139 |
| 137 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 140 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
| 138 byte_stream_output->Read(&output_io_buffer, &output_length)); | 141 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 139 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 142 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
| 140 | 143 |
| 141 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 144 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
| 142 byte_stream_output->Read(&output_io_buffer, &output_length)); | 145 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 143 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 146 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
| 144 | 147 |
| 145 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, | 148 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, |
| 146 byte_stream_output->Read(&output_io_buffer, &output_length)); | 149 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 150 |
| 151 message_loop_.RunUntilIdle(); |
| 152 // Reader now knows that all data is read out. |
| 153 EXPECT_EQ(1024U, byte_stream_input->GetTotalBufferedBytes()); |
| 147 } | 154 } |
| 148 | 155 |
| 149 // Confirm that Flush() method makes the writer to send written contents to | 156 // Confirm that Flush() method makes the writer to send written contents to |
| 150 // the reader. | 157 // the reader. |
| 151 TEST_F(ByteStreamTest, ByteStream_Flush) { | 158 TEST_F(ByteStreamTest, ByteStream_Flush) { |
| 152 scoped_ptr<ByteStreamWriter> byte_stream_input; | 159 scoped_ptr<ByteStreamWriter> byte_stream_input; |
| 153 scoped_ptr<ByteStreamReader> byte_stream_output; | 160 scoped_ptr<ByteStreamReader> byte_stream_output; |
| 154 CreateByteStream( | 161 CreateByteStream( |
| 155 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 162 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
| 156 1024, &byte_stream_input, &byte_stream_output); | 163 1024, &byte_stream_input, &byte_stream_output); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 byte_stream_output->Read(&output_io_buffer, &output_length)); | 580 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 574 | 581 |
| 575 byte_stream_input->Close(0); | 582 byte_stream_input->Close(0); |
| 576 message_loop_.RunUntilIdle(); | 583 message_loop_.RunUntilIdle(); |
| 577 | 584 |
| 578 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, | 585 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, |
| 579 byte_stream_output->Read(&output_io_buffer, &output_length)); | 586 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 580 } | 587 } |
| 581 | 588 |
| 582 } // namespace content | 589 } // namespace content |
| OLD | NEW |