Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: content/browser/byte_stream_unittest.cc

Issue 18098004: Add Flush() method to ByteStream. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/byte_stream.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 message_loop_.RunUntilIdle();
160
161 scoped_refptr<net::IOBuffer> output_io_buffer;
162 size_t output_length = 0;
163 // Check that data is not sent to the reader yet.
164 EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
165 byte_stream_output->Read(&output_io_buffer, &output_length));
166
167 byte_stream_input->Flush();
168 message_loop_.RunUntilIdle();
169
170 EXPECT_EQ(ByteStreamReader::STREAM_HAS_DATA,
171 byte_stream_output->Read(&output_io_buffer, &output_length));
172 EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
173
174 // Check that it's ok to Flush() an empty writer.
175 byte_stream_input->Flush();
176 message_loop_.RunUntilIdle();
177
178 EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
179 byte_stream_output->Read(&output_io_buffer, &output_length));
180
181 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
182 message_loop_.RunUntilIdle();
183
184 EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE,
185 byte_stream_output->Read(&output_io_buffer, &output_length));
186 }
187
149 // Same as above, only use knowledge of the internals to confirm 188 // 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 189 // that we're getting pushback even when data's split across the two
151 // objects 190 // objects
152 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) { 191 TEST_F(ByteStreamTest, ByteStream_PushBackSplit) {
153 scoped_ptr<ByteStreamWriter> byte_stream_input; 192 scoped_ptr<ByteStreamWriter> byte_stream_input;
154 scoped_ptr<ByteStreamReader> byte_stream_output; 193 scoped_ptr<ByteStreamReader> byte_stream_output;
155 CreateByteStream( 194 CreateByteStream(
156 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), 195 message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
157 9 * 1024, &byte_stream_input, &byte_stream_output); 196 9 * 1024, &byte_stream_input, &byte_stream_output);
158 197
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 byte_stream_output->RegisterCallback( 537 byte_stream_output->RegisterCallback(
499 base::Bind(CountCallbacks, &num_callbacks)); 538 base::Bind(CountCallbacks, &num_callbacks));
500 539
501 // Immediately close the stream. 540 // Immediately close the stream.
502 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE); 541 byte_stream_input->Close(DOWNLOAD_INTERRUPT_REASON_NONE);
503 task_runner->RunUntilIdle(); 542 task_runner->RunUntilIdle();
504 EXPECT_EQ(1, num_callbacks); 543 EXPECT_EQ(1, num_callbacks);
505 } 544 }
506 545
507 } // namespace content 546 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/byte_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698