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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 int num_callbacks = 0; | 534 int num_callbacks = 0; |
535 byte_stream_output->RegisterCallback( | 535 byte_stream_output->RegisterCallback( |
536 base::Bind(CountCallbacks, &num_callbacks)); | 536 base::Bind(CountCallbacks, &num_callbacks)); |
537 | 537 |
538 // Immediately close the stream. | 538 // Immediately close the stream. |
539 byte_stream_input->Close(0); | 539 byte_stream_input->Close(0); |
540 task_runner->RunUntilIdle(); | 540 task_runner->RunUntilIdle(); |
541 EXPECT_EQ(1, num_callbacks); | 541 EXPECT_EQ(1, num_callbacks); |
542 } | 542 } |
543 | 543 |
| 544 TEST_F(ByteStreamTest, ByteStream_CloseWithoutAnyWrite) { |
| 545 scoped_ptr<ByteStreamWriter> byte_stream_input; |
| 546 scoped_ptr<ByteStreamReader> byte_stream_output; |
| 547 CreateByteStream( |
| 548 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
| 549 3 * 1024, &byte_stream_input, &byte_stream_output); |
| 550 |
| 551 byte_stream_input->Close(0); |
| 552 message_loop_.RunUntilIdle(); |
| 553 |
| 554 scoped_refptr<net::IOBuffer> output_io_buffer; |
| 555 size_t output_length; |
| 556 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, |
| 557 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 558 } |
| 559 |
| 560 TEST_F(ByteStreamTest, ByteStream_FlushWithoutAnyWrite) { |
| 561 scoped_ptr<ByteStreamWriter> byte_stream_input; |
| 562 scoped_ptr<ByteStreamReader> byte_stream_output; |
| 563 CreateByteStream( |
| 564 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), |
| 565 3 * 1024, &byte_stream_input, &byte_stream_output); |
| 566 |
| 567 byte_stream_input->Flush(); |
| 568 message_loop_.RunUntilIdle(); |
| 569 |
| 570 scoped_refptr<net::IOBuffer> output_io_buffer; |
| 571 size_t output_length; |
| 572 EXPECT_EQ(ByteStreamReader::STREAM_EMPTY, |
| 573 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 574 |
| 575 byte_stream_input->Close(0); |
| 576 message_loop_.RunUntilIdle(); |
| 577 |
| 578 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE, |
| 579 byte_stream_output->Read(&output_io_buffer, &output_length)); |
| 580 } |
| 581 |
544 } // namespace content | 582 } // namespace content |
OLD | NEW |