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

Side by Side Diff: net/base/file_stream_unittest.cc

Issue 1148383003: Only support seeking file streams from the beginning of the file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Win DBG build by Pass()-ing file out of CreateForAsyncHandle. Created 5 years, 6 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
« no previous file with comments | « net/base/file_stream_context_win.cc ('k') | net/base/mock_file_stream.h » ('j') | 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 "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 TEST_F(FileStreamTest, OpenExplicitClose) { 72 TEST_F(FileStreamTest, OpenExplicitClose) {
73 TestCompletionCallback callback; 73 TestCompletionCallback callback;
74 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 74 FileStream stream(base::ThreadTaskRunnerHandle::Get());
75 int flags = base::File::FLAG_OPEN | 75 int flags = base::File::FLAG_OPEN |
76 base::File::FLAG_READ | 76 base::File::FLAG_READ |
77 base::File::FLAG_ASYNC; 77 base::File::FLAG_ASYNC;
78 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 78 int rv = stream.Open(temp_file_path(), flags, callback.callback());
79 EXPECT_EQ(ERR_IO_PENDING, rv); 79 EXPECT_EQ(ERR_IO_PENDING, rv);
80 EXPECT_EQ(OK, callback.WaitForResult()); 80 EXPECT_EQ(OK, callback.WaitForResult());
81 EXPECT_TRUE(stream.IsOpen()); 81 EXPECT_TRUE(stream.IsOpen());
82 EXPECT_TRUE(stream.GetFileForTesting().IsValid());
83 EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback())); 82 EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback()));
84 EXPECT_EQ(OK, callback.WaitForResult()); 83 EXPECT_EQ(OK, callback.WaitForResult());
85 EXPECT_FALSE(stream.IsOpen()); 84 EXPECT_FALSE(stream.IsOpen());
86 EXPECT_FALSE(stream.GetFileForTesting().IsValid());
87 } 85 }
88 86
89 TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) { 87 TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) {
90 TestCompletionCallback callback; 88 TestCompletionCallback callback;
91 scoped_ptr<FileStream> stream( 89 scoped_ptr<FileStream> stream(
92 new FileStream(base::ThreadTaskRunnerHandle::Get())); 90 new FileStream(base::ThreadTaskRunnerHandle::Get()));
93 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 91 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
94 base::File::FLAG_ASYNC; 92 base::File::FLAG_ASYNC;
95 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 93 int rv = stream->Open(temp_file_path(), flags, callback.callback());
96 EXPECT_EQ(ERR_IO_PENDING, rv); 94 EXPECT_EQ(ERR_IO_PENDING, rv);
97 EXPECT_EQ(OK, callback.WaitForResult()); 95 EXPECT_EQ(OK, callback.WaitForResult());
98 EXPECT_TRUE(stream->IsOpen()); 96 EXPECT_TRUE(stream->IsOpen());
99 EXPECT_TRUE(stream->GetFileForTesting().IsValid());
100 EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback())); 97 EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback()));
101 stream.reset(); 98 stream.reset();
102 // File isn't actually closed yet. 99 // File isn't actually closed yet.
103 base::RunLoop runloop; 100 base::RunLoop runloop;
104 runloop.RunUntilIdle(); 101 runloop.RunUntilIdle();
105 // The file should now be closed, though the callback has not been called. 102 // The file should now be closed, though the callback has not been called.
106 } 103 }
107 104
108 // Test the use of FileStream with a file handle provided at construction. 105 // Test the use of FileStream with a file handle provided at construction.
109 TEST_F(FileStreamTest, UseFileHandle) { 106 TEST_F(FileStreamTest, UseFileHandle) {
110 int rv = 0; 107 int rv = 0;
111 TestCompletionCallback callback; 108 TestCompletionCallback callback;
112 TestInt64CompletionCallback callback64; 109 TestInt64CompletionCallback callback64;
113 // 1. Test reading with a file handle. 110 // 1. Test reading with a file handle.
114 ASSERT_EQ(kTestDataSize, 111 ASSERT_EQ(kTestDataSize,
115 base::WriteFile(temp_file_path(), kTestData, kTestDataSize)); 112 base::WriteFile(temp_file_path(), kTestData, kTestDataSize));
116 int flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | 113 int flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
117 base::File::FLAG_ASYNC; 114 base::File::FLAG_ASYNC;
118 base::File file(temp_file_path(), flags); 115 base::File file(temp_file_path(), flags);
119 116
120 // Seek to the beginning of the file and read. 117 // Seek to the beginning of the file and read.
121 scoped_ptr<FileStream> read_stream( 118 scoped_ptr<FileStream> read_stream(
122 new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get())); 119 new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get()));
123 ASSERT_EQ(ERR_IO_PENDING, 120 ASSERT_EQ(ERR_IO_PENDING, read_stream->Seek(0, callback64.callback()));
124 read_stream->Seek(base::File::FROM_BEGIN, 0,
125 callback64.callback()));
126 ASSERT_EQ(0, callback64.WaitForResult()); 121 ASSERT_EQ(0, callback64.WaitForResult());
127 // Read into buffer and compare. 122 // Read into buffer and compare.
128 scoped_refptr<IOBufferWithSize> read_buffer = 123 scoped_refptr<IOBufferWithSize> read_buffer =
129 new IOBufferWithSize(kTestDataSize); 124 new IOBufferWithSize(kTestDataSize);
130 rv = read_stream->Read(read_buffer.get(), kTestDataSize, callback.callback()); 125 rv = read_stream->Read(read_buffer.get(), kTestDataSize, callback.callback());
131 ASSERT_EQ(kTestDataSize, callback.GetResult(rv)); 126 ASSERT_EQ(kTestDataSize, callback.GetResult(rv));
132 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize)); 127 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize));
133 read_stream.reset(); 128 read_stream.reset();
134 129
135 // 2. Test writing with a file handle. 130 // 2. Test writing with a file handle.
136 base::DeleteFile(temp_file_path(), false); 131 base::DeleteFile(temp_file_path(), false);
137 flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE | 132 flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE |
138 base::File::FLAG_ASYNC; 133 base::File::FLAG_ASYNC;
139 file.Initialize(temp_file_path(), flags); 134 file.Initialize(temp_file_path(), flags);
140 135
141 scoped_ptr<FileStream> write_stream( 136 scoped_ptr<FileStream> write_stream(
142 new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get())); 137 new FileStream(file.Pass(), base::ThreadTaskRunnerHandle::Get()));
143 ASSERT_EQ(ERR_IO_PENDING, 138 ASSERT_EQ(ERR_IO_PENDING, write_stream->Seek(0, callback64.callback()));
144 write_stream->Seek(base::File::FROM_BEGIN, 0,
145 callback64.callback()));
146 ASSERT_EQ(0, callback64.WaitForResult()); 139 ASSERT_EQ(0, callback64.WaitForResult());
147 scoped_refptr<IOBufferWithSize> write_buffer = CreateTestDataBuffer(); 140 scoped_refptr<IOBufferWithSize> write_buffer = CreateTestDataBuffer();
148 rv = write_stream->Write(write_buffer.get(), kTestDataSize, 141 rv = write_stream->Write(write_buffer.get(), kTestDataSize,
149 callback.callback()); 142 callback.callback());
150 ASSERT_EQ(kTestDataSize, callback.GetResult(rv)); 143 ASSERT_EQ(kTestDataSize, callback.GetResult(rv));
151 write_stream.reset(); 144 write_stream.reset();
152 145
153 // Read into buffer and compare to make sure the handle worked fine. 146 // Read into buffer and compare to make sure the handle worked fine.
154 ASSERT_EQ(kTestDataSize, 147 ASSERT_EQ(kTestDataSize,
155 base::ReadFile(temp_file_path(), read_buffer->data(), 148 base::ReadFile(temp_file_path(), read_buffer->data(),
156 kTestDataSize)); 149 kTestDataSize));
157 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize)); 150 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize));
158 } 151 }
159 152
160 TEST_F(FileStreamTest, UseClosedStream) { 153 TEST_F(FileStreamTest, UseClosedStream) {
161 int rv = 0; 154 int rv = 0;
162 TestCompletionCallback callback; 155 TestCompletionCallback callback;
163 TestInt64CompletionCallback callback64; 156 TestInt64CompletionCallback callback64;
164 157
165 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 158 FileStream stream(base::ThreadTaskRunnerHandle::Get());
166 159
167 EXPECT_FALSE(stream.IsOpen()); 160 EXPECT_FALSE(stream.IsOpen());
168 161
169 // Try seeking... 162 // Try seeking...
170 rv = stream.Seek(base::File::FROM_BEGIN, 5, callback64.callback()); 163 rv = stream.Seek(5, callback64.callback());
171 EXPECT_EQ(ERR_UNEXPECTED, callback64.GetResult(rv)); 164 EXPECT_EQ(ERR_UNEXPECTED, callback64.GetResult(rv));
172 165
173 // Try reading... 166 // Try reading...
174 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(10); 167 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(10);
175 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 168 rv = stream.Read(buf.get(), buf->size(), callback.callback());
176 EXPECT_EQ(ERR_UNEXPECTED, callback.GetResult(rv)); 169 EXPECT_EQ(ERR_UNEXPECTED, callback.GetResult(rv));
177 } 170 }
178 171
179 TEST_F(FileStreamTest, Read) { 172 TEST_F(FileStreamTest, Read) {
180 int64_t file_size; 173 int64_t file_size;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 230 FileStream stream(base::ThreadTaskRunnerHandle::Get());
238 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 231 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
239 base::File::FLAG_ASYNC; 232 base::File::FLAG_ASYNC;
240 TestCompletionCallback callback; 233 TestCompletionCallback callback;
241 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 234 int rv = stream.Open(temp_file_path(), flags, callback.callback());
242 EXPECT_EQ(ERR_IO_PENDING, rv); 235 EXPECT_EQ(ERR_IO_PENDING, rv);
243 EXPECT_EQ(OK, callback.WaitForResult()); 236 EXPECT_EQ(OK, callback.WaitForResult());
244 237
245 TestInt64CompletionCallback callback64; 238 TestInt64CompletionCallback callback64;
246 const int64_t kOffset = 3; 239 const int64_t kOffset = 3;
247 rv = stream.Seek(base::File::FROM_BEGIN, kOffset, callback64.callback()); 240 rv = stream.Seek(kOffset, callback64.callback());
248 ASSERT_EQ(ERR_IO_PENDING, rv); 241 ASSERT_EQ(ERR_IO_PENDING, rv);
249 int64_t new_offset = callback64.WaitForResult(); 242 int64_t new_offset = callback64.WaitForResult();
250 EXPECT_EQ(kOffset, new_offset); 243 EXPECT_EQ(kOffset, new_offset);
251 244
252 int total_bytes_read = 0; 245 int total_bytes_read = 0;
253 246
254 std::string data_read; 247 std::string data_read;
255 for (;;) { 248 for (;;) {
256 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 249 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
257 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 250 rv = stream.Read(buf.get(), buf->size(), callback.callback());
258 if (rv == ERR_IO_PENDING) 251 if (rv == ERR_IO_PENDING)
259 rv = callback.WaitForResult(); 252 rv = callback.WaitForResult();
260 EXPECT_LE(0, rv); 253 EXPECT_LE(0, rv);
261 if (rv <= 0) 254 if (rv <= 0)
262 break; 255 break;
263 total_bytes_read += rv; 256 total_bytes_read += rv;
264 data_read.append(buf->data(), rv); 257 data_read.append(buf->data(), rv);
265 } 258 }
266 EXPECT_EQ(file_size - kOffset, total_bytes_read); 259 EXPECT_EQ(file_size - kOffset, total_bytes_read);
267 EXPECT_EQ(kTestData + kOffset, data_read); 260 EXPECT_EQ(kTestData + kOffset, data_read);
268 } 261 }
269 262
270 TEST_F(FileStreamTest, SeekAround) {
271 FileStream stream(base::ThreadTaskRunnerHandle::Get());
272 int flags = base::File::FLAG_OPEN | base::File::FLAG_ASYNC |
273 base::File::FLAG_READ;
274 TestCompletionCallback callback;
275 int rv = stream.Open(temp_file_path(), flags, callback.callback());
276 EXPECT_EQ(ERR_IO_PENDING, rv);
277 EXPECT_EQ(OK, callback.WaitForResult());
278
279 TestInt64CompletionCallback callback64;
280
281 const int64_t kOffset = 3;
282 rv = stream.Seek(base::File::FROM_BEGIN, kOffset, callback64.callback());
283 ASSERT_EQ(ERR_IO_PENDING, rv);
284 int64_t new_offset = callback64.WaitForResult();
285 EXPECT_EQ(kOffset, new_offset);
286
287 rv = stream.Seek(base::File::FROM_CURRENT, kOffset, callback64.callback());
288 ASSERT_EQ(ERR_IO_PENDING, rv);
289 new_offset = callback64.WaitForResult();
290 EXPECT_EQ(2 * kOffset, new_offset);
291
292 rv = stream.Seek(base::File::FROM_CURRENT, -kOffset, callback64.callback());
293 ASSERT_EQ(ERR_IO_PENDING, rv);
294 new_offset = callback64.WaitForResult();
295 EXPECT_EQ(kOffset, new_offset);
296
297 const int kTestDataLen = arraysize(kTestData) - 1;
298
299 rv = stream.Seek(base::File::FROM_END, -kTestDataLen, callback64.callback());
300 ASSERT_EQ(ERR_IO_PENDING, rv);
301 new_offset = callback64.WaitForResult();
302 EXPECT_EQ(0, new_offset);
303 }
304
305 TEST_F(FileStreamTest, Write) { 263 TEST_F(FileStreamTest, Write) {
306 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 264 FileStream stream(base::ThreadTaskRunnerHandle::Get());
307 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 265 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
308 base::File::FLAG_ASYNC; 266 base::File::FLAG_ASYNC;
309 TestCompletionCallback callback; 267 TestCompletionCallback callback;
310 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 268 int rv = stream.Open(temp_file_path(), flags, callback.callback());
311 EXPECT_EQ(OK, callback.GetResult(rv)); 269 EXPECT_EQ(OK, callback.GetResult(rv));
312 270
313 int64_t file_size; 271 int64_t file_size;
314 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 272 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 319
362 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 320 FileStream stream(base::ThreadTaskRunnerHandle::Get());
363 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE | 321 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE |
364 base::File::FLAG_ASYNC; 322 base::File::FLAG_ASYNC;
365 TestCompletionCallback callback; 323 TestCompletionCallback callback;
366 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 324 int rv = stream.Open(temp_file_path(), flags, callback.callback());
367 EXPECT_EQ(ERR_IO_PENDING, rv); 325 EXPECT_EQ(ERR_IO_PENDING, rv);
368 EXPECT_EQ(OK, callback.WaitForResult()); 326 EXPECT_EQ(OK, callback.WaitForResult());
369 327
370 TestInt64CompletionCallback callback64; 328 TestInt64CompletionCallback callback64;
371 const int64_t kOffset = 0; 329 const int64_t kOffset = kTestDataSize;
372 rv = stream.Seek(base::File::FROM_END, kOffset, callback64.callback()); 330 rv = stream.Seek(kOffset, callback64.callback());
373 ASSERT_EQ(ERR_IO_PENDING, rv); 331 ASSERT_EQ(ERR_IO_PENDING, rv);
374 int64_t new_offset = callback64.WaitForResult(); 332 int64_t new_offset = callback64.WaitForResult();
375 EXPECT_EQ(kTestDataSize, new_offset); 333 EXPECT_EQ(kTestDataSize, new_offset);
376 334
377 int total_bytes_written = 0; 335 int total_bytes_written = 0;
378 336
379 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 337 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
380 scoped_refptr<DrainableIOBuffer> drainable = 338 scoped_refptr<DrainableIOBuffer> drainable =
381 new DrainableIOBuffer(buf.get(), buf->size()); 339 new DrainableIOBuffer(buf.get(), buf->size());
382 while (total_bytes_written != kTestDataSize) { 340 while (total_bytes_written != kTestDataSize) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 scoped_ptr<FileStream> stream( 412 scoped_ptr<FileStream> stream(
455 new FileStream(base::ThreadTaskRunnerHandle::Get())); 413 new FileStream(base::ThreadTaskRunnerHandle::Get()));
456 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 414 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
457 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 415 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
458 TestCompletionCallback callback; 416 TestCompletionCallback callback;
459 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 417 int rv = stream->Open(temp_file_path(), flags, callback.callback());
460 EXPECT_EQ(ERR_IO_PENDING, rv); 418 EXPECT_EQ(ERR_IO_PENDING, rv);
461 EXPECT_EQ(OK, callback.WaitForResult()); 419 EXPECT_EQ(OK, callback.WaitForResult());
462 420
463 TestInt64CompletionCallback callback64; 421 TestInt64CompletionCallback callback64;
464 rv = stream->Seek(base::File::FROM_END, 0, callback64.callback()); 422 rv = stream->Seek(file_size, callback64.callback());
465 ASSERT_EQ(ERR_IO_PENDING, rv); 423 ASSERT_EQ(ERR_IO_PENDING, rv);
466 int64_t offset = callback64.WaitForResult(); 424 int64_t offset = callback64.WaitForResult();
467 EXPECT_EQ(offset, file_size); 425 EXPECT_EQ(offset, file_size);
468 426
469 int total_bytes_written = 0; 427 int total_bytes_written = 0;
470 428
471 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 429 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
472 scoped_refptr<DrainableIOBuffer> drainable = 430 scoped_refptr<DrainableIOBuffer> drainable =
473 new DrainableIOBuffer(buf.get(), buf->size()); 431 new DrainableIOBuffer(buf.get(), buf->size());
474 while (total_bytes_written != kTestDataSize) { 432 while (total_bytes_written != kTestDataSize) {
475 rv = stream->Write(drainable.get(), drainable->BytesRemaining(), 433 rv = stream->Write(drainable.get(), drainable->BytesRemaining(),
476 callback.callback()); 434 callback.callback());
477 if (rv == ERR_IO_PENDING) 435 if (rv == ERR_IO_PENDING)
478 rv = callback.WaitForResult(); 436 rv = callback.WaitForResult();
479 EXPECT_LT(0, rv); 437 EXPECT_LT(0, rv);
480 if (rv <= 0) 438 if (rv <= 0)
481 break; 439 break;
482 drainable->DidConsume(rv); 440 drainable->DidConsume(rv);
483 total_bytes_written += rv; 441 total_bytes_written += rv;
484 } 442 }
485 443
486 EXPECT_EQ(kTestDataSize, total_bytes_written); 444 EXPECT_EQ(kTestDataSize, total_bytes_written);
487 445
488 rv = stream->Seek(base::File::FROM_BEGIN, 0, callback64.callback()); 446 rv = stream->Seek(0, callback64.callback());
489 ASSERT_EQ(ERR_IO_PENDING, rv); 447 ASSERT_EQ(ERR_IO_PENDING, rv);
490 offset = callback64.WaitForResult(); 448 offset = callback64.WaitForResult();
491 EXPECT_EQ(0, offset); 449 EXPECT_EQ(0, offset);
492 450
493 int total_bytes_read = 0; 451 int total_bytes_read = 0;
494 452
495 std::string data_read; 453 std::string data_read;
496 for (;;) { 454 for (;;) {
497 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 455 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
498 rv = stream->Read(buf.get(), buf->size(), callback.callback()); 456 rv = stream->Read(buf.get(), buf->size(), callback.callback());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 rv = stream_->Write( 539 rv = stream_->Write(
582 drainable_.get(), drainable_->BytesRemaining(), callback.callback()); 540 drainable_.get(), drainable_->BytesRemaining(), callback.callback());
583 DCHECK_EQ(ERR_IO_PENDING, rv); 541 DCHECK_EQ(ERR_IO_PENDING, rv);
584 rv = callback.WaitForResult(); 542 rv = callback.WaitForResult();
585 drainable_->DidConsume(total_bytes_written); 543 drainable_->DidConsume(total_bytes_written);
586 *total_bytes_written_ += total_bytes_written; 544 *total_bytes_written_ += total_bytes_written;
587 *total_bytes_read_ += total_bytes_read; 545 *total_bytes_read_ += total_bytes_read;
588 *data_read_ += data_read; 546 *data_read_ += data_read;
589 } else { // We're done writing all data. Start reading the data. 547 } else { // We're done writing all data. Start reading the data.
590 TestInt64CompletionCallback callback64; 548 TestInt64CompletionCallback callback64;
591 EXPECT_EQ(ERR_IO_PENDING, 549 EXPECT_EQ(ERR_IO_PENDING, stream_->Seek(0, callback64.callback()));
592 stream_->Seek(base::File::FROM_BEGIN, 0,
593 callback64.callback()));
594 { 550 {
595 base::MessageLoop::ScopedNestableTaskAllower allow( 551 base::MessageLoop::ScopedNestableTaskAllower allow(
596 base::MessageLoop::current()); 552 base::MessageLoop::current());
597 EXPECT_LE(0, callback64.WaitForResult()); 553 EXPECT_LE(0, callback64.WaitForResult());
598 } 554 }
599 } 555 }
600 556
601 result_ = *total_bytes_written_; 557 result_ = *total_bytes_written_;
602 have_result_ = true; 558 have_result_ = true;
603 if (waiting_for_result_) 559 if (waiting_for_result_)
(...skipping 21 matching lines...) Expand all
625 scoped_ptr<FileStream> stream( 581 scoped_ptr<FileStream> stream(
626 new FileStream(base::ThreadTaskRunnerHandle::Get())); 582 new FileStream(base::ThreadTaskRunnerHandle::Get()));
627 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 583 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
628 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 584 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
629 TestCompletionCallback open_callback; 585 TestCompletionCallback open_callback;
630 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 586 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
631 EXPECT_EQ(ERR_IO_PENDING, rv); 587 EXPECT_EQ(ERR_IO_PENDING, rv);
632 EXPECT_EQ(OK, open_callback.WaitForResult()); 588 EXPECT_EQ(OK, open_callback.WaitForResult());
633 589
634 TestInt64CompletionCallback callback64; 590 TestInt64CompletionCallback callback64;
635 EXPECT_EQ(ERR_IO_PENDING, 591 EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback()));
636 stream->Seek(base::File::FROM_END, 0, callback64.callback()));
637 EXPECT_EQ(file_size, callback64.WaitForResult()); 592 EXPECT_EQ(file_size, callback64.WaitForResult());
638 593
639 int total_bytes_written = 0; 594 int total_bytes_written = 0;
640 int total_bytes_read = 0; 595 int total_bytes_read = 0;
641 std::string data_read; 596 std::string data_read;
642 TestWriteReadCompletionCallback callback(stream.get(), &total_bytes_written, 597 TestWriteReadCompletionCallback callback(stream.get(), &total_bytes_written,
643 &total_bytes_read, &data_read); 598 &total_bytes_read, &data_read);
644 599
645 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 600 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
646 rv = stream->Write(buf.get(), buf->size(), callback.callback()); 601 rv = stream->Write(buf.get(), buf->size(), callback.callback());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 scoped_ptr<FileStream> stream( 687 scoped_ptr<FileStream> stream(
733 new FileStream(base::ThreadTaskRunnerHandle::Get())); 688 new FileStream(base::ThreadTaskRunnerHandle::Get()));
734 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 689 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
735 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 690 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
736 TestCompletionCallback open_callback; 691 TestCompletionCallback open_callback;
737 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 692 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
738 EXPECT_EQ(ERR_IO_PENDING, rv); 693 EXPECT_EQ(ERR_IO_PENDING, rv);
739 EXPECT_EQ(OK, open_callback.WaitForResult()); 694 EXPECT_EQ(OK, open_callback.WaitForResult());
740 695
741 TestInt64CompletionCallback callback64; 696 TestInt64CompletionCallback callback64;
742 EXPECT_EQ(ERR_IO_PENDING, 697 EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback()));
743 stream->Seek(base::File::FROM_END, 0, callback64.callback()));
744 EXPECT_EQ(file_size, callback64.WaitForResult()); 698 EXPECT_EQ(file_size, callback64.WaitForResult());
745 699
746 int total_bytes_written = 0; 700 int total_bytes_written = 0;
747 TestWriteCloseCompletionCallback callback(stream.get(), &total_bytes_written); 701 TestWriteCloseCompletionCallback callback(stream.get(), &total_bytes_written);
748 702
749 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 703 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
750 rv = stream->Write(buf.get(), buf->size(), callback.callback()); 704 rv = stream->Write(buf.get(), buf->size(), callback.callback());
751 if (rv == ERR_IO_PENDING) 705 if (rv == ERR_IO_PENDING)
752 total_bytes_written = callback.WaitForResult(); 706 total_bytes_written = callback.WaitForResult();
753 EXPECT_LT(0, total_bytes_written); 707 EXPECT_LT(0, total_bytes_written);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 total_bytes_read += rv; 833 total_bytes_read += rv;
880 data_read.append(buf->data(), rv); 834 data_read.append(buf->data(), rv);
881 } 835 }
882 EXPECT_EQ(file_size, total_bytes_read); 836 EXPECT_EQ(file_size, total_bytes_read);
883 } 837 }
884 #endif 838 #endif
885 839
886 } // namespace 840 } // namespace
887 841
888 } // namespace net 842 } // namespace net
OLDNEW
« no previous file with comments | « net/base/file_stream_context_win.cc ('k') | net/base/mock_file_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698