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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 139 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
140 | 140 |
141 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | 141 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, |
142 byte_stream_output->Read(&output_io_buffer, &output_length)); | 142 byte_stream_output->Read(&output_io_buffer, &output_length)); |
143 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 143 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
144 | 144 |
145 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, | 145 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, |
146 byte_stream_output->Read(&output_io_buffer, &output_length)); | 146 byte_stream_output->Read(&output_io_buffer, &output_length)); |
147 } | 147 } |
148 | 148 |
149 // Confirm that Flush() method makes the writer to send written contents to | |
150 // the reader. | |
151 TEST_F(ByteStreamTest, ByteStream_Flush) { | |
152 scoped_ptr<ByteStreamWriter> byte_stream_input; | |
153 scoped_ptr<ByteStreamReader> byte_stream_output; | |
154 CreateByteStream( | |
155 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | |
156 1024, &byte_stream_input, &byte_stream_output); | |
157 | |
158 EXPECT_TRUE(Write(byte_stream_input.get(), 1)); | |
159 byte_stream_input->Flush(); | |
Randy Smith (Not in Mondays)
2013/07/18 16:11:44
nit: I'd like there to be part of this test that c
tyoshino (SeeGerritForStatus)
2013/07/25 05:13:38
Added expectation.
| |
160 message_loop_.RunUntilIdle(); | |
161 | |
162 scoped_refptr<net::IOBuffer> output_io_buffer; | |
163 size_t output_length; | |
164 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA, | |
165 byte_stream_output->Read(&output_io_buffer, &output_length)); | |
166 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | |
167 | |
168 // Check that it's ok to Flush() an empty writer. | |
169 byte_stream_input->Flush(); | |
170 message_loop_.RunUntilIdle(); | |
171 | |
172 EXPECT_EQ(ByteStreamReader::STREAM_EMPTY, | |
173 byte_stream_output->Read(&output_io_buffer, &output_length)); | |
174 | |
175 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE); | |
176 message_loop_.RunUntilIdle(); | |
177 | |
178 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, | |
179 byte_stream_output->Read(&output_io_buffer, &output_length)); | |
180 } | |
181 | |
149 // Same as above, only use knowledge of the internals to confirm | 182 // Same as above, only use knowledge of the internals to confirm |
150 // that we're getting pushback even when data's split across the two | 183 // that we're getting pushback even when data's split across the two |
151 // objects | 184 // objects |
152 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) { | 185 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) { |
153 scoped_ptr<ByteStreamWriter> byte_stream_input; | 186 scoped_ptr<ByteStreamWriter> byte_stream_input; |
154 scoped_ptr<ByteStreamReader> byte_stream_output; | 187 scoped_ptr<ByteStreamReader> byte_stream_output; |
155 CreateByteStream( | 188 CreateByteStream( |
156 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 189 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
157 9 * 1024, &byte_stream_input, &byte_stream_output); | 190 9 * 1024, &byte_stream_input, &byte_stream_output); |
158 | 191 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 byte_stream_output->RegisterCallback( | 531 byte_stream_output->RegisterCallback( |
499 base::Bind(CountCallbacks, &num_callbacks)); | 532 base::Bind(CountCallbacks, &num_callbacks)); |
500 | 533 |
501 // Immediately close the stream. | 534 // Immediately close the stream. |
502 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE); | 535 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE); |
503 task_runner->RunUntilIdle(); | 536 task_runner->RunUntilIdle(); |
504 EXPECT_EQ(1, num_callbacks); | 537 EXPECT_EQ(1, num_callbacks); |
505 } | 538 } |
506 | 539 |
507 } // namespace content | 540 } // namespace content |
OLD | NEW |