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/download/byte_stream.h" | 5 #include "content/browser/download/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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 pointer_queue_.push_back(bufferp); | 78 pointer_queue_.push_back(bufferp); |
79 length_queue_.push_back(buffer_size); | 79 length_queue_.push_back(buffer_size); |
80 ++producing_seed_key_; | 80 ++producing_seed_key_; |
81 return buffer; | 81 return buffer; |
82 } | 82 } |
83 | 83 |
84 // Create an IOBuffer of the appropriate size and add it to the | 84 // Create an IOBuffer of the appropriate size and add it to the |
85 // ByteStream, returning the result of the ByteStream::Write. | 85 // ByteStream, returning the result of the ByteStream::Write. |
86 // Separate function to avoid duplication of buffer_size in test | 86 // Separate function to avoid duplication of buffer_size in test |
87 // calls. | 87 // calls. |
88 bool Write(content::ByteStreamInput* byte_stream_input, | 88 bool Write(content::ByteStreamWriter* byte_stream_input, |
89 size_t buffer_size) { | 89 size_t buffer_size) { |
90 return byte_stream_input->Write(NewIOBuffer(buffer_size), buffer_size); | 90 return byte_stream_input->Write(NewIOBuffer(buffer_size), buffer_size); |
91 } | 91 } |
92 | 92 |
93 // Validate that we have the IOBuffer we expect. This routine must be | 93 // Validate that we have the IOBuffer we expect. This routine must be |
94 // called on buffers that were allocated from NewIOBuffer, and in the | 94 // called on buffers that were allocated from NewIOBuffer, and in the |
95 // order that they were allocated. Calls to NewIOBuffer && | 95 // order that they were allocated. Calls to NewIOBuffer && |
96 // ValidateIOBuffer may be interleaved. | 96 // ValidateIOBuffer may be interleaved. |
97 bool ValidateIOBuffer( | 97 bool ValidateIOBuffer( |
98 scoped_refptr<net::IOBuffer> buffer, size_t buffer_size) { | 98 scoped_refptr<net::IOBuffer> buffer, size_t buffer_size) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int producing_seed_key_; | 132 int producing_seed_key_; |
133 int consuming_seed_key_; | 133 int consuming_seed_key_; |
134 std::deque<char*> pointer_queue_; | 134 std::deque<char*> pointer_queue_; |
135 std::deque<size_t> length_queue_; | 135 std::deque<size_t> length_queue_; |
136 }; | 136 }; |
137 | 137 |
138 ByteStreamTest::ByteStreamTest() | 138 ByteStreamTest::ByteStreamTest() |
139 : producing_seed_key_(0), | 139 : producing_seed_key_(0), |
140 consuming_seed_key_(0) { } | 140 consuming_seed_key_(0) { } |
141 | 141 |
142 // Confirm that filling and emptying the pipe works properly, and that | 142 // Confirm that filling and emptying the stream works properly, and that |
143 // we get full triggers when we expect. | 143 // we get full triggers when we expect. |
144 TEST_F(ByteStreamTest, ByteStream_PushBack) { | 144 TEST_F(ByteStreamTest, ByteStream_PushBack) { |
145 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 145 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
146 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 146 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
147 content::CreateByteStream( | 147 content::CreateByteStream( |
148 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 148 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
149 3 * 1024, &byte_stream_input, &byte_stream_output); | 149 3 * 1024, &byte_stream_input, &byte_stream_output); |
150 | 150 |
151 // Push a series of IO buffers on; test pushback happening and | 151 // Push a series of IO buffers on; test pushback happening and |
152 // that it's advisory. | 152 // that it's advisory. |
153 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 153 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
154 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 154 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
155 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 155 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
156 EXPECT_FALSE(Write(byte_stream_input.get(), 1)); | 156 EXPECT_FALSE(Write(byte_stream_input.get(), 1)); |
157 EXPECT_FALSE(Write(byte_stream_input.get(), 1024)); | 157 EXPECT_FALSE(Write(byte_stream_input.get(), 1024)); |
158 // Flush | 158 // Flush |
159 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); | 159 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); |
160 message_loop_.RunAllPending(); | 160 message_loop_.RunAllPending(); |
161 | 161 |
162 // Pull the IO buffers out; do we get the same buffers and do they | 162 // Pull the IO buffers out; do we get the same buffers and do they |
163 // have the same contents? | 163 // have the same contents? |
164 scoped_refptr<net::IOBuffer> output_io_buffer; | 164 scoped_refptr<net::IOBuffer> output_io_buffer; |
165 size_t output_length; | 165 size_t output_length; |
166 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 166 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
167 byte_stream_output->Read(&output_io_buffer, &output_length)); | 167 byte_stream_output->Read(&output_io_buffer, &output_length)); |
168 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 168 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
169 | 169 |
170 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 170 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
171 byte_stream_output->Read(&output_io_buffer, &output_length)); | 171 byte_stream_output->Read(&output_io_buffer, &output_length)); |
172 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 172 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
173 | 173 |
174 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 174 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
175 byte_stream_output->Read(&output_io_buffer, &output_length)); | 175 byte_stream_output->Read(&output_io_buffer, &output_length)); |
176 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 176 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
177 | 177 |
178 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 178 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
179 byte_stream_output->Read(&output_io_buffer, &output_length)); | 179 byte_stream_output->Read(&output_io_buffer, &output_length)); |
180 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 180 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
181 | 181 |
182 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 182 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
183 byte_stream_output->Read(&output_io_buffer, &output_length)); | 183 byte_stream_output->Read(&output_io_buffer, &output_length)); |
184 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 184 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
185 | 185 |
186 EXPECT_EQ(content::ByteStreamOutput::STREAM_COMPLETE, | 186 EXPECT_EQ(content::ByteStreamReader::STREAM_COMPLETE, |
187 byte_stream_output->Read(&output_io_buffer, &output_length)); | 187 byte_stream_output->Read(&output_io_buffer, &output_length)); |
188 } | 188 } |
189 | 189 |
190 // Same as above, only use knowledge of the internals to confirm | 190 // Same as above, only use knowledge of the internals to confirm |
191 // that we're getting pushback even when data's split across the two | 191 // that we're getting pushback even when data's split across the two |
192 // objects | 192 // objects |
193 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) { | 193 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) { |
194 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 194 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
195 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 195 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
196 content::CreateByteStream( | 196 content::CreateByteStream( |
197 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 197 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
198 9 * 1024, &byte_stream_input, &byte_stream_output); | 198 9 * 1024, &byte_stream_input, &byte_stream_output); |
199 | 199 |
200 // Push a series of IO buffers on; test pushback happening and | 200 // Push a series of IO buffers on; test pushback happening and |
201 // that it's advisory. | 201 // that it's advisory. |
202 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 202 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
203 message_loop_.RunAllPending(); | 203 message_loop_.RunAllPending(); |
204 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 204 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
205 message_loop_.RunAllPending(); | 205 message_loop_.RunAllPending(); |
206 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 206 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
207 message_loop_.RunAllPending(); | 207 message_loop_.RunAllPending(); |
208 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 208 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
209 message_loop_.RunAllPending(); | 209 message_loop_.RunAllPending(); |
210 EXPECT_FALSE(Write(byte_stream_input.get(), 6 * 1024)); | 210 EXPECT_FALSE(Write(byte_stream_input.get(), 6 * 1024)); |
211 message_loop_.RunAllPending(); | 211 message_loop_.RunAllPending(); |
212 | 212 |
213 // Pull the IO buffers out; do we get the same buffers and do they | 213 // Pull the IO buffers out; do we get the same buffers and do they |
214 // have the same contents? | 214 // have the same contents? |
215 scoped_refptr<net::IOBuffer> output_io_buffer; | 215 scoped_refptr<net::IOBuffer> output_io_buffer; |
216 size_t output_length; | 216 size_t output_length; |
217 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 217 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
218 byte_stream_output->Read(&output_io_buffer, &output_length)); | 218 byte_stream_output->Read(&output_io_buffer, &output_length)); |
219 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 219 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
220 | 220 |
221 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 221 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
222 byte_stream_output->Read(&output_io_buffer, &output_length)); | 222 byte_stream_output->Read(&output_io_buffer, &output_length)); |
223 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 223 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
224 | 224 |
225 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 225 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
226 byte_stream_output->Read(&output_io_buffer, &output_length)); | 226 byte_stream_output->Read(&output_io_buffer, &output_length)); |
227 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 227 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
228 | 228 |
229 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 229 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
230 byte_stream_output->Read(&output_io_buffer, &output_length)); | 230 byte_stream_output->Read(&output_io_buffer, &output_length)); |
231 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 231 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
232 | 232 |
233 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 233 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
234 byte_stream_output->Read(&output_io_buffer, &output_length)); | 234 byte_stream_output->Read(&output_io_buffer, &output_length)); |
235 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 235 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
236 | 236 |
237 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 237 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
238 byte_stream_output->Read(&output_io_buffer, &output_length)); | 238 byte_stream_output->Read(&output_io_buffer, &output_length)); |
239 } | 239 } |
240 | 240 |
241 // Confirm that a Close() notification transmits in-order | 241 // Confirm that a Close() notification transmits in-order |
242 // with data on the pipe. | 242 // with data on the stream. |
243 TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) { | 243 TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) { |
244 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 244 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
245 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 245 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
246 | 246 |
247 scoped_refptr<net::IOBuffer> output_io_buffer; | 247 scoped_refptr<net::IOBuffer> output_io_buffer; |
248 size_t output_length; | 248 size_t output_length; |
249 | 249 |
250 // Empty stream, non-error case. | 250 // Empty stream, non-error case. |
251 content::CreateByteStream( | 251 content::CreateByteStream( |
252 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 252 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
253 3 * 1024, &byte_stream_input, &byte_stream_output); | 253 3 * 1024, &byte_stream_input, &byte_stream_output); |
254 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 254 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
255 byte_stream_output->Read(&output_io_buffer, &output_length)); | 255 byte_stream_output->Read(&output_io_buffer, &output_length)); |
256 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); | 256 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); |
257 message_loop_.RunAllPending(); | 257 message_loop_.RunAllPending(); |
258 ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE, | 258 ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE, |
259 byte_stream_output->Read(&output_io_buffer, &output_length)); | 259 byte_stream_output->Read(&output_io_buffer, &output_length)); |
260 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 260 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
261 byte_stream_output->GetStatus()); | 261 byte_stream_output->GetStatus()); |
262 | 262 |
263 // Non-empty stream, non-error case. | 263 // Non-empty stream, non-error case. |
264 content::CreateByteStream( | 264 content::CreateByteStream( |
265 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 265 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
266 3 * 1024, &byte_stream_input, &byte_stream_output); | 266 3 * 1024, &byte_stream_input, &byte_stream_output); |
267 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 267 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
268 byte_stream_output->Read(&output_io_buffer, &output_length)); | 268 byte_stream_output->Read(&output_io_buffer, &output_length)); |
269 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 269 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
270 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); | 270 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); |
271 message_loop_.RunAllPending(); | 271 message_loop_.RunAllPending(); |
272 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 272 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
273 byte_stream_output->Read(&output_io_buffer, &output_length)); | 273 byte_stream_output->Read(&output_io_buffer, &output_length)); |
274 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 274 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
275 ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE, | 275 ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE, |
276 byte_stream_output->Read(&output_io_buffer, &output_length)); | 276 byte_stream_output->Read(&output_io_buffer, &output_length)); |
277 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, | 277 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE, |
278 byte_stream_output->GetStatus()); | 278 byte_stream_output->GetStatus()); |
279 | 279 |
280 // Empty stream, non-error case. | 280 // Empty stream, non-error case. |
281 content::CreateByteStream( | 281 content::CreateByteStream( |
282 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 282 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
283 3 * 1024, &byte_stream_input, &byte_stream_output); | 283 3 * 1024, &byte_stream_input, &byte_stream_output); |
284 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 284 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
285 byte_stream_output->Read(&output_io_buffer, &output_length)); | 285 byte_stream_output->Read(&output_io_buffer, &output_length)); |
286 byte_stream_input->Close( | 286 byte_stream_input->Close( |
287 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED); | 287 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED); |
288 message_loop_.RunAllPending(); | 288 message_loop_.RunAllPending(); |
289 ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE, | 289 ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE, |
290 byte_stream_output->Read(&output_io_buffer, &output_length)); | 290 byte_stream_output->Read(&output_io_buffer, &output_length)); |
291 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, | 291 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, |
292 byte_stream_output->GetStatus()); | 292 byte_stream_output->GetStatus()); |
293 | 293 |
294 // Non-empty stream, non-error case. | 294 // Non-empty stream, non-error case. |
295 content::CreateByteStream( | 295 content::CreateByteStream( |
296 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), | 296 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
297 3 * 1024, &byte_stream_input, &byte_stream_output); | 297 3 * 1024, &byte_stream_input, &byte_stream_output); |
298 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 298 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
299 byte_stream_output->Read(&output_io_buffer, &output_length)); | 299 byte_stream_output->Read(&output_io_buffer, &output_length)); |
300 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); | 300 EXPECT_TRUE(Write(byte_stream_input.get(), 1024)); |
301 byte_stream_input->Close( | 301 byte_stream_input->Close( |
302 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED); | 302 content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED); |
303 message_loop_.RunAllPending(); | 303 message_loop_.RunAllPending(); |
304 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 304 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
305 byte_stream_output->Read(&output_io_buffer, &output_length)); | 305 byte_stream_output->Read(&output_io_buffer, &output_length)); |
306 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 306 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
307 ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE, | 307 ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE, |
308 byte_stream_output->Read(&output_io_buffer, &output_length)); | 308 byte_stream_output->Read(&output_io_buffer, &output_length)); |
309 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, | 309 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, |
310 byte_stream_output->GetStatus()); | 310 byte_stream_output->GetStatus()); |
311 } | 311 } |
312 | 312 |
313 // Confirm that callbacks on the sink side are triggered when they should be. | 313 // Confirm that callbacks on the sink side are triggered when they should be. |
314 TEST_F(ByteStreamTest, ByteStream_SinkCallback) { | 314 TEST_F(ByteStreamTest, ByteStream_SinkCallback) { |
315 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); | 315 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); |
316 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 316 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
317 .WillRepeatedly(Return(true)); | 317 .WillRepeatedly(Return(true)); |
318 | 318 |
319 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 319 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
320 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 320 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
321 content::CreateByteStream( | 321 content::CreateByteStream( |
322 message_loop_.message_loop_proxy(), task_runner, | 322 message_loop_.message_loop_proxy(), task_runner, |
323 10000, &byte_stream_input, &byte_stream_output); | 323 10000, &byte_stream_input, &byte_stream_output); |
324 | 324 |
325 scoped_refptr<net::IOBuffer> output_io_buffer; | 325 scoped_refptr<net::IOBuffer> output_io_buffer; |
326 size_t output_length; | 326 size_t output_length; |
327 base::Closure intermediate_callback; | 327 base::Closure intermediate_callback; |
328 | 328 |
329 // Note that the specifics of when the callbacks are called with regard | 329 // Note that the specifics of when the callbacks are called with regard |
330 // to how much data is pushed onto the pipe is not (currently) part | 330 // to how much data is pushed onto the stream is not (currently) part |
331 // of the interface contract. If it becomes part of the contract, the | 331 // of the interface contract. If it becomes part of the contract, the |
332 // tests below should get much more precise. | 332 // tests below should get much more precise. |
333 | 333 |
334 // Confirm callback called when you add more than 33% of the buffer. | 334 // Confirm callback called when you add more than 33% of the buffer. |
335 | 335 |
336 // Setup callback | 336 // Setup callback |
337 int num_callbacks = 0; | 337 int num_callbacks = 0; |
338 byte_stream_output->RegisterCallback( | 338 byte_stream_output->RegisterCallback( |
339 base::Bind(CountCallbacks, &num_callbacks)); | 339 base::Bind(CountCallbacks, &num_callbacks)); |
340 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 340 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
341 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 341 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
342 Return(true))); | 342 Return(true))); |
343 | 343 |
344 EXPECT_TRUE(Write(byte_stream_input.get(), 4000)); | 344 EXPECT_TRUE(Write(byte_stream_input.get(), 4000)); |
345 message_loop_.RunAllPending(); | 345 message_loop_.RunAllPending(); |
346 | 346 |
347 // Check callback results match expectations. | 347 // Check callback results match expectations. |
348 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 348 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
349 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 349 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
350 .WillRepeatedly(Return(true)); | 350 .WillRepeatedly(Return(true)); |
351 EXPECT_EQ(0, num_callbacks); | 351 EXPECT_EQ(0, num_callbacks); |
352 intermediate_callback.Run(); | 352 intermediate_callback.Run(); |
353 EXPECT_EQ(1, num_callbacks); | 353 EXPECT_EQ(1, num_callbacks); |
354 | 354 |
355 // Check data and stream state. | 355 // Check data and stream state. |
356 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 356 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
357 byte_stream_output->Read(&output_io_buffer, &output_length)); | 357 byte_stream_output->Read(&output_io_buffer, &output_length)); |
358 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 358 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
359 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 359 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
360 byte_stream_output->Read(&output_io_buffer, &output_length)); | 360 byte_stream_output->Read(&output_io_buffer, &output_length)); |
361 | 361 |
362 // Confirm callback *isn't* called at less than 33% (by lack of | 362 // Confirm callback *isn't* called at less than 33% (by lack of |
363 // unexpected call on task runner). | 363 // unexpected call on task runner). |
364 EXPECT_TRUE(Write(byte_stream_input.get(), 3000)); | 364 EXPECT_TRUE(Write(byte_stream_input.get(), 3000)); |
365 message_loop_.RunAllPending(); | 365 message_loop_.RunAllPending(); |
366 | 366 |
367 // This reflects an implementation artifact that data goes with callbacks, | 367 // This reflects an implementation artifact that data goes with callbacks, |
368 // which should not be considered part of the interface guarantee. | 368 // which should not be considered part of the interface guarantee. |
369 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 369 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
370 byte_stream_output->Read(&output_io_buffer, &output_length)); | 370 byte_stream_output->Read(&output_io_buffer, &output_length)); |
371 } | 371 } |
372 | 372 |
373 // Confirm that callbacks on the source side are triggered when they should | 373 // Confirm that callbacks on the source side are triggered when they should |
374 // be. | 374 // be. |
375 TEST_F(ByteStreamTest, ByteStream_SourceCallback) { | 375 TEST_F(ByteStreamTest, ByteStream_SourceCallback) { |
376 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); | 376 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); |
377 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 377 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
378 .WillRepeatedly(Return(true)); | 378 .WillRepeatedly(Return(true)); |
379 | 379 |
380 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 380 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
381 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 381 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
382 content::CreateByteStream( | 382 content::CreateByteStream( |
383 task_runner, message_loop_.message_loop_proxy(), | 383 task_runner, message_loop_.message_loop_proxy(), |
384 10000, &byte_stream_input, &byte_stream_output); | 384 10000, &byte_stream_input, &byte_stream_output); |
385 | 385 |
386 scoped_refptr<net::IOBuffer> output_io_buffer; | 386 scoped_refptr<net::IOBuffer> output_io_buffer; |
387 size_t output_length; | 387 size_t output_length; |
388 base::Closure intermediate_callback; | 388 base::Closure intermediate_callback; |
389 | 389 |
390 // Note that the specifics of when the callbacks are called with regard | 390 // Note that the specifics of when the callbacks are called with regard |
391 // to how much data is pulled from the pipe is not (currently) part | 391 // to how much data is pulled from the stream is not (currently) part |
392 // of the interface contract. If it becomes part of the contract, the | 392 // of the interface contract. If it becomes part of the contract, the |
393 // tests below should get much more precise. | 393 // tests below should get much more precise. |
394 | 394 |
395 // Confirm callback called when about 33% space available, and not | 395 // Confirm callback called when about 33% space available, and not |
396 // at other transitions. | 396 // at other transitions. |
397 | 397 |
398 // Setup expectations and add data. | 398 // Setup expectations and add data. |
399 int num_callbacks = 0; | 399 int num_callbacks = 0; |
400 byte_stream_input->RegisterCallback( | 400 byte_stream_input->RegisterCallback( |
401 base::Bind(CountCallbacks, &num_callbacks)); | 401 base::Bind(CountCallbacks, &num_callbacks)); |
402 EXPECT_TRUE(Write(byte_stream_input.get(), 2000)); | 402 EXPECT_TRUE(Write(byte_stream_input.get(), 2000)); |
403 EXPECT_TRUE(Write(byte_stream_input.get(), 2001)); | 403 EXPECT_TRUE(Write(byte_stream_input.get(), 2001)); |
404 EXPECT_FALSE(Write(byte_stream_input.get(), 6000)); | 404 EXPECT_FALSE(Write(byte_stream_input.get(), 6000)); |
405 | 405 |
406 // Allow bytes to transition (needed for message passing implementation), | 406 // Allow bytes to transition (needed for message passing implementation), |
407 // and get and validate the data. | 407 // and get and validate the data. |
408 message_loop_.RunAllPending(); | 408 message_loop_.RunAllPending(); |
409 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 409 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
410 byte_stream_output->Read(&output_io_buffer, &output_length)); | 410 byte_stream_output->Read(&output_io_buffer, &output_length)); |
411 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 411 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
412 | 412 |
413 // Setup expectations. | 413 // Setup expectations. |
414 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 414 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
415 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 415 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
416 Return(true))); | 416 Return(true))); |
417 | 417 |
418 // Grab data, triggering callback. Recorded on dispatch, but doesn't | 418 // Grab data, triggering callback. Recorded on dispatch, but doesn't |
419 // happen because it's caught by the mock. | 419 // happen because it's caught by the mock. |
420 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 420 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
421 byte_stream_output->Read(&output_io_buffer, &output_length)); | 421 byte_stream_output->Read(&output_io_buffer, &output_length)); |
422 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 422 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
423 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 423 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
424 .WillRepeatedly(Return(true)); | 424 .WillRepeatedly(Return(true)); |
425 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 425 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
426 | 426 |
427 // Confirm that the callback passed to the mock does what we expect. | 427 // Confirm that the callback passed to the mock does what we expect. |
428 EXPECT_EQ(0, num_callbacks); | 428 EXPECT_EQ(0, num_callbacks); |
429 intermediate_callback.Run(); | 429 intermediate_callback.Run(); |
430 EXPECT_EQ(1, num_callbacks); | 430 EXPECT_EQ(1, num_callbacks); |
431 | 431 |
432 // Same drill with final buffer. | 432 // Same drill with final buffer. |
433 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 433 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
434 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 434 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
435 Return(true))); | 435 Return(true))); |
436 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 436 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
437 byte_stream_output->Read(&output_io_buffer, &output_length)); | 437 byte_stream_output->Read(&output_io_buffer, &output_length)); |
438 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 438 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
439 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 439 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
440 .WillRepeatedly(Return(true)); | 440 .WillRepeatedly(Return(true)); |
441 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 441 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
442 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 442 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
443 byte_stream_output->Read(&output_io_buffer, &output_length)); | 443 byte_stream_output->Read(&output_io_buffer, &output_length)); |
444 EXPECT_EQ(1, num_callbacks); | 444 EXPECT_EQ(1, num_callbacks); |
445 intermediate_callback.Run(); | 445 intermediate_callback.Run(); |
446 // Should have updated the internal structures but not called the | 446 // Should have updated the internal structures but not called the |
447 // callback. | 447 // callback. |
448 EXPECT_EQ(1, num_callbacks); | 448 EXPECT_EQ(1, num_callbacks); |
449 } | 449 } |
450 | 450 |
451 // Confirm that racing a change to a sink callback with a post results | 451 // Confirm that racing a change to a sink callback with a post results |
452 // in the new callback being called. | 452 // in the new callback being called. |
453 TEST_F(ByteStreamTest, ByteStream_SinkInterrupt) { | 453 TEST_F(ByteStreamTest, ByteStream_SinkInterrupt) { |
454 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); | 454 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); |
455 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 455 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
456 .WillRepeatedly(Return(true)); | 456 .WillRepeatedly(Return(true)); |
457 | 457 |
458 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 458 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
459 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 459 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
460 content::CreateByteStream( | 460 content::CreateByteStream( |
461 message_loop_.message_loop_proxy(), task_runner, | 461 message_loop_.message_loop_proxy(), task_runner, |
462 10000, &byte_stream_input, &byte_stream_output); | 462 10000, &byte_stream_input, &byte_stream_output); |
463 | 463 |
464 scoped_refptr<net::IOBuffer> output_io_buffer; | 464 scoped_refptr<net::IOBuffer> output_io_buffer; |
465 size_t output_length; | 465 size_t output_length; |
466 base::Closure intermediate_callback; | 466 base::Closure intermediate_callback; |
467 | 467 |
468 // Setup expectations and record initial state. | 468 // Setup expectations and record initial state. |
469 int num_callbacks = 0; | 469 int num_callbacks = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
487 // If we change the callback now, the new one should be run | 487 // If we change the callback now, the new one should be run |
488 // (simulates race with post task). | 488 // (simulates race with post task). |
489 int num_alt_callbacks = 0; | 489 int num_alt_callbacks = 0; |
490 byte_stream_output->RegisterCallback( | 490 byte_stream_output->RegisterCallback( |
491 base::Bind(CountCallbacks, &num_alt_callbacks)); | 491 base::Bind(CountCallbacks, &num_alt_callbacks)); |
492 intermediate_callback.Run(); | 492 intermediate_callback.Run(); |
493 EXPECT_EQ(0, num_callbacks); | 493 EXPECT_EQ(0, num_callbacks); |
494 EXPECT_EQ(1, num_alt_callbacks); | 494 EXPECT_EQ(1, num_alt_callbacks); |
495 | 495 |
496 // Final cleanup. | 496 // Final cleanup. |
497 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 497 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
498 byte_stream_output->Read(&output_io_buffer, &output_length)); | 498 byte_stream_output->Read(&output_io_buffer, &output_length)); |
499 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 499 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
500 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 500 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
501 byte_stream_output->Read(&output_io_buffer, &output_length)); | 501 byte_stream_output->Read(&output_io_buffer, &output_length)); |
502 | 502 |
503 } | 503 } |
504 | 504 |
505 // Confirm that racing a change to a source callback with a post results | 505 // Confirm that racing a change to a source callback with a post results |
506 // in the new callback being called. | 506 // in the new callback being called. |
507 TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) { | 507 TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) { |
508 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); | 508 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); |
509 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 509 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
510 .WillRepeatedly(Return(true)); | 510 .WillRepeatedly(Return(true)); |
511 | 511 |
512 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 512 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
513 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 513 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
514 content::CreateByteStream( | 514 content::CreateByteStream( |
515 task_runner, message_loop_.message_loop_proxy(), | 515 task_runner, message_loop_.message_loop_proxy(), |
516 10000, &byte_stream_input, &byte_stream_output); | 516 10000, &byte_stream_input, &byte_stream_output); |
517 | 517 |
518 scoped_refptr<net::IOBuffer> output_io_buffer; | 518 scoped_refptr<net::IOBuffer> output_io_buffer; |
519 size_t output_length; | 519 size_t output_length; |
520 base::Closure intermediate_callback; | 520 base::Closure intermediate_callback; |
521 | 521 |
522 // Setup state for test and record initiali expectations | 522 // Setup state for test and record initiali expectations |
523 int num_callbacks = 0; | 523 int num_callbacks = 0; |
524 byte_stream_input->RegisterCallback( | 524 byte_stream_input->RegisterCallback( |
525 base::Bind(CountCallbacks, &num_callbacks)); | 525 base::Bind(CountCallbacks, &num_callbacks)); |
526 EXPECT_TRUE(Write(byte_stream_input.get(), 2000)); | 526 EXPECT_TRUE(Write(byte_stream_input.get(), 2000)); |
527 EXPECT_TRUE(Write(byte_stream_input.get(), 2001)); | 527 EXPECT_TRUE(Write(byte_stream_input.get(), 2001)); |
528 EXPECT_FALSE(Write(byte_stream_input.get(), 6000)); | 528 EXPECT_FALSE(Write(byte_stream_input.get(), 6000)); |
529 message_loop_.RunAllPending(); | 529 message_loop_.RunAllPending(); |
530 | 530 |
531 // Initial get should not trigger callback. | 531 // Initial get should not trigger callback. |
532 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 532 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
533 byte_stream_output->Read(&output_io_buffer, &output_length)); | 533 byte_stream_output->Read(&output_io_buffer, &output_length)); |
534 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 534 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
535 message_loop_.RunAllPending(); | 535 message_loop_.RunAllPending(); |
536 | 536 |
537 // Setup expectations. | 537 // Setup expectations. |
538 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 538 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
539 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 539 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
540 Return(true))); | 540 Return(true))); |
541 | 541 |
542 // Second get *should* trigger callback. | 542 // Second get *should* trigger callback. |
543 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 543 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
544 byte_stream_output->Read(&output_io_buffer, &output_length)); | 544 byte_stream_output->Read(&output_io_buffer, &output_length)); |
545 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 545 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
546 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 546 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
547 .WillRepeatedly(Return(true)); | 547 .WillRepeatedly(Return(true)); |
548 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 548 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
549 | 549 |
550 // Which should do the right thing when it's run. | 550 // Which should do the right thing when it's run. |
551 int num_alt_callbacks = 0; | 551 int num_alt_callbacks = 0; |
552 byte_stream_input->RegisterCallback( | 552 byte_stream_input->RegisterCallback( |
553 base::Bind(CountCallbacks, &num_alt_callbacks)); | 553 base::Bind(CountCallbacks, &num_alt_callbacks)); |
554 intermediate_callback.Run(); | 554 intermediate_callback.Run(); |
555 EXPECT_EQ(0, num_callbacks); | 555 EXPECT_EQ(0, num_callbacks); |
556 EXPECT_EQ(1, num_alt_callbacks); | 556 EXPECT_EQ(1, num_alt_callbacks); |
557 | 557 |
558 // Third get should also trigger callback. | 558 // Third get should also trigger callback. |
559 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 559 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
560 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 560 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
561 Return(true))); | 561 Return(true))); |
562 EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA, | 562 EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA, |
563 byte_stream_output->Read(&output_io_buffer, &output_length)); | 563 byte_stream_output->Read(&output_io_buffer, &output_length)); |
564 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 564 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
565 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 565 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
566 .WillRepeatedly(Return(true)); | 566 .WillRepeatedly(Return(true)); |
567 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); | 567 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length)); |
568 EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY, | 568 EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY, |
569 byte_stream_output->Read(&output_io_buffer, &output_length)); | 569 byte_stream_output->Read(&output_io_buffer, &output_length)); |
570 } | 570 } |
571 | 571 |
572 // Confirm that callback is called on zero data transfer but source | 572 // Confirm that callback is called on zero data transfer but source |
573 // complete. | 573 // complete. |
574 TEST_F(ByteStreamTest, ByteStream_ZeroCallback) { | 574 TEST_F(ByteStreamTest, ByteStream_ZeroCallback) { |
575 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); | 575 scoped_refptr<MockTaskRunner> task_runner(new StrictMock<MockTaskRunner>()); |
576 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 576 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
577 .WillRepeatedly(Return(true)); | 577 .WillRepeatedly(Return(true)); |
578 | 578 |
579 scoped_ptr<content::ByteStreamInput> byte_stream_input; | 579 scoped_ptr<content::ByteStreamWriter> byte_stream_input; |
580 scoped_ptr<content::ByteStreamOutput> byte_stream_output; | 580 scoped_ptr<content::ByteStreamReader> byte_stream_output; |
581 content::CreateByteStream( | 581 content::CreateByteStream( |
582 message_loop_.message_loop_proxy(), task_runner, | 582 message_loop_.message_loop_proxy(), task_runner, |
583 10000, &byte_stream_input, &byte_stream_output); | 583 10000, &byte_stream_input, &byte_stream_output); |
584 | 584 |
585 base::Closure intermediate_callback; | 585 base::Closure intermediate_callback; |
586 | 586 |
587 // Setup expectations and record initial state. | 587 // Setup expectations and record initial state. |
588 int num_callbacks = 0; | 588 int num_callbacks = 0; |
589 byte_stream_output->RegisterCallback( | 589 byte_stream_output->RegisterCallback( |
590 base::Bind(CountCallbacks, &num_callbacks)); | 590 base::Bind(CountCallbacks, &num_callbacks)); |
591 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) | 591 EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0)) |
592 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), | 592 .WillOnce(DoAll(SaveArg<1>(&intermediate_callback), |
593 Return(true))); | 593 Return(true))); |
594 | 594 |
595 // Immediately close the stream. | 595 // Immediately close the stream. |
596 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); | 596 byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE); |
597 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); | 597 ::testing::Mock::VerifyAndClearExpectations(task_runner.get()); |
598 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) | 598 EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread()) |
599 .WillRepeatedly(Return(true)); | 599 .WillRepeatedly(Return(true)); |
600 intermediate_callback.Run(); | 600 intermediate_callback.Run(); |
601 EXPECT_EQ(1, num_callbacks); | 601 EXPECT_EQ(1, num_callbacks); |
602 } | 602 } |
603 | 603 |
604 | 604 |
OLD | NEW |