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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file.h" 11 #include "base/files/file.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/test/sequenced_worker_pool_owner.h" 19 #include "base/test/sequenced_worker_pool_owner.h"
20 #include "base/test/test_timeouts.h" 20 #include "base/test/test_timeouts.h"
21 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
25 #include "net/base/test_completion_callback.h" 25 #include "net/base/test_completion_callback.h"
26 #include "net/log/test_net_log.h" 26 #include "net/log/test_net_log.h"
27 #include "net/test/gtest_util.h"
28 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
28 #include "testing/platform_test.h" 30 #include "testing/platform_test.h"
29 31
32 using net::test::IsError;
33 using net::test::IsOk;
34
30 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
31 #include "base/test/test_file_util.h" 36 #include "base/test/test_file_util.h"
32 #endif 37 #endif
33 38
34 namespace net { 39 namespace net {
35 40
36 namespace { 41 namespace {
37 42
38 const char kTestData[] = "0123456789"; 43 const char kTestData[] = "0123456789";
39 const int kTestDataSize = arraysize(kTestData) - 1; 44 const int kTestDataSize = arraysize(kTestData) - 1;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 77
73 namespace { 78 namespace {
74 79
75 TEST_F(FileStreamTest, OpenExplicitClose) { 80 TEST_F(FileStreamTest, OpenExplicitClose) {
76 TestCompletionCallback callback; 81 TestCompletionCallback callback;
77 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 82 FileStream stream(base::ThreadTaskRunnerHandle::Get());
78 int flags = base::File::FLAG_OPEN | 83 int flags = base::File::FLAG_OPEN |
79 base::File::FLAG_READ | 84 base::File::FLAG_READ |
80 base::File::FLAG_ASYNC; 85 base::File::FLAG_ASYNC;
81 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 86 int rv = stream.Open(temp_file_path(), flags, callback.callback());
82 EXPECT_EQ(ERR_IO_PENDING, rv); 87 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
83 EXPECT_EQ(OK, callback.WaitForResult()); 88 EXPECT_THAT(callback.WaitForResult(), IsOk());
84 EXPECT_TRUE(stream.IsOpen()); 89 EXPECT_TRUE(stream.IsOpen());
85 EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback())); 90 EXPECT_THAT(stream.Close(callback.callback()), IsError(ERR_IO_PENDING));
86 EXPECT_EQ(OK, callback.WaitForResult()); 91 EXPECT_THAT(callback.WaitForResult(), IsOk());
87 EXPECT_FALSE(stream.IsOpen()); 92 EXPECT_FALSE(stream.IsOpen());
88 } 93 }
89 94
90 TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) { 95 TEST_F(FileStreamTest, OpenExplicitCloseOrphaned) {
91 TestCompletionCallback callback; 96 TestCompletionCallback callback;
92 std::unique_ptr<FileStream> stream( 97 std::unique_ptr<FileStream> stream(
93 new FileStream(base::ThreadTaskRunnerHandle::Get())); 98 new FileStream(base::ThreadTaskRunnerHandle::Get()));
94 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 99 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
95 base::File::FLAG_ASYNC; 100 base::File::FLAG_ASYNC;
96 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 101 int rv = stream->Open(temp_file_path(), flags, callback.callback());
97 EXPECT_EQ(ERR_IO_PENDING, rv); 102 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
98 EXPECT_EQ(OK, callback.WaitForResult()); 103 EXPECT_THAT(callback.WaitForResult(), IsOk());
99 EXPECT_TRUE(stream->IsOpen()); 104 EXPECT_TRUE(stream->IsOpen());
100 EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback())); 105 EXPECT_THAT(stream->Close(callback.callback()), IsError(ERR_IO_PENDING));
101 stream.reset(); 106 stream.reset();
102 // File isn't actually closed yet. 107 // File isn't actually closed yet.
103 base::RunLoop runloop; 108 base::RunLoop runloop;
104 runloop.RunUntilIdle(); 109 runloop.RunUntilIdle();
105 // The file should now be closed, though the callback has not been called. 110 // The file should now be closed, though the callback has not been called.
106 } 111 }
107 112
108 // Test the use of FileStream with a file handle provided at construction. 113 // Test the use of FileStream with a file handle provided at construction.
109 TEST_F(FileStreamTest, UseFileHandle) { 114 TEST_F(FileStreamTest, UseFileHandle) {
110 int rv = 0; 115 int rv = 0;
111 TestCompletionCallback callback; 116 TestCompletionCallback callback;
112 TestInt64CompletionCallback callback64; 117 TestInt64CompletionCallback callback64;
113 // 1. Test reading with a file handle. 118 // 1. Test reading with a file handle.
114 ASSERT_EQ(kTestDataSize, 119 ASSERT_EQ(kTestDataSize,
115 base::WriteFile(temp_file_path(), kTestData, kTestDataSize)); 120 base::WriteFile(temp_file_path(), kTestData, kTestDataSize));
116 int flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | 121 int flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ |
117 base::File::FLAG_ASYNC; 122 base::File::FLAG_ASYNC;
118 base::File file(temp_file_path(), flags); 123 base::File file(temp_file_path(), flags);
119 124
120 // Seek to the beginning of the file and read. 125 // Seek to the beginning of the file and read.
121 std::unique_ptr<FileStream> read_stream( 126 std::unique_ptr<FileStream> read_stream(
122 new FileStream(std::move(file), base::ThreadTaskRunnerHandle::Get())); 127 new FileStream(std::move(file), base::ThreadTaskRunnerHandle::Get()));
123 ASSERT_EQ(ERR_IO_PENDING, read_stream->Seek(0, callback64.callback())); 128 ASSERT_THAT(read_stream->Seek(0, callback64.callback()),
129 IsError(ERR_IO_PENDING));
124 ASSERT_EQ(0, callback64.WaitForResult()); 130 ASSERT_EQ(0, callback64.WaitForResult());
125 // Read into buffer and compare. 131 // Read into buffer and compare.
126 scoped_refptr<IOBufferWithSize> read_buffer = 132 scoped_refptr<IOBufferWithSize> read_buffer =
127 new IOBufferWithSize(kTestDataSize); 133 new IOBufferWithSize(kTestDataSize);
128 rv = read_stream->Read(read_buffer.get(), kTestDataSize, callback.callback()); 134 rv = read_stream->Read(read_buffer.get(), kTestDataSize, callback.callback());
129 ASSERT_EQ(kTestDataSize, callback.GetResult(rv)); 135 ASSERT_EQ(kTestDataSize, callback.GetResult(rv));
130 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize)); 136 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize));
131 read_stream.reset(); 137 read_stream.reset();
132 138
133 // 2. Test writing with a file handle. 139 // 2. Test writing with a file handle.
134 base::DeleteFile(temp_file_path(), false); 140 base::DeleteFile(temp_file_path(), false);
135 flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE | 141 flags = base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE |
136 base::File::FLAG_ASYNC; 142 base::File::FLAG_ASYNC;
137 file.Initialize(temp_file_path(), flags); 143 file.Initialize(temp_file_path(), flags);
138 144
139 std::unique_ptr<FileStream> write_stream( 145 std::unique_ptr<FileStream> write_stream(
140 new FileStream(std::move(file), base::ThreadTaskRunnerHandle::Get())); 146 new FileStream(std::move(file), base::ThreadTaskRunnerHandle::Get()));
141 ASSERT_EQ(ERR_IO_PENDING, write_stream->Seek(0, callback64.callback())); 147 ASSERT_THAT(write_stream->Seek(0, callback64.callback()),
148 IsError(ERR_IO_PENDING));
142 ASSERT_EQ(0, callback64.WaitForResult()); 149 ASSERT_EQ(0, callback64.WaitForResult());
143 scoped_refptr<IOBufferWithSize> write_buffer = CreateTestDataBuffer(); 150 scoped_refptr<IOBufferWithSize> write_buffer = CreateTestDataBuffer();
144 rv = write_stream->Write(write_buffer.get(), kTestDataSize, 151 rv = write_stream->Write(write_buffer.get(), kTestDataSize,
145 callback.callback()); 152 callback.callback());
146 ASSERT_EQ(kTestDataSize, callback.GetResult(rv)); 153 ASSERT_EQ(kTestDataSize, callback.GetResult(rv));
147 write_stream.reset(); 154 write_stream.reset();
148 155
149 // Read into buffer and compare to make sure the handle worked fine. 156 // Read into buffer and compare to make sure the handle worked fine.
150 ASSERT_EQ(kTestDataSize, 157 ASSERT_EQ(kTestDataSize,
151 base::ReadFile(temp_file_path(), read_buffer->data(), 158 base::ReadFile(temp_file_path(), read_buffer->data(),
152 kTestDataSize)); 159 kTestDataSize));
153 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize)); 160 ASSERT_EQ(0, memcmp(kTestData, read_buffer->data(), kTestDataSize));
154 } 161 }
155 162
156 TEST_F(FileStreamTest, UseClosedStream) { 163 TEST_F(FileStreamTest, UseClosedStream) {
157 int rv = 0; 164 int rv = 0;
158 TestCompletionCallback callback; 165 TestCompletionCallback callback;
159 TestInt64CompletionCallback callback64; 166 TestInt64CompletionCallback callback64;
160 167
161 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 168 FileStream stream(base::ThreadTaskRunnerHandle::Get());
162 169
163 EXPECT_FALSE(stream.IsOpen()); 170 EXPECT_FALSE(stream.IsOpen());
164 171
165 // Try seeking... 172 // Try seeking...
166 rv = stream.Seek(5, callback64.callback()); 173 rv = stream.Seek(5, callback64.callback());
167 EXPECT_EQ(ERR_UNEXPECTED, callback64.GetResult(rv)); 174 EXPECT_THAT(callback64.GetResult(rv), IsError(ERR_UNEXPECTED));
168 175
169 // Try reading... 176 // Try reading...
170 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(10); 177 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(10);
171 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 178 rv = stream.Read(buf.get(), buf->size(), callback.callback());
172 EXPECT_EQ(ERR_UNEXPECTED, callback.GetResult(rv)); 179 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_UNEXPECTED));
173 } 180 }
174 181
175 TEST_F(FileStreamTest, Read) { 182 TEST_F(FileStreamTest, Read) {
176 int64_t file_size; 183 int64_t file_size;
177 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 184 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
178 185
179 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 186 FileStream stream(base::ThreadTaskRunnerHandle::Get());
180 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 187 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
181 base::File::FLAG_ASYNC; 188 base::File::FLAG_ASYNC;
182 TestCompletionCallback callback; 189 TestCompletionCallback callback;
183 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 190 int rv = stream.Open(temp_file_path(), flags, callback.callback());
184 EXPECT_EQ(OK, callback.GetResult(rv)); 191 EXPECT_THAT(callback.GetResult(rv), IsOk());
185 192
186 int total_bytes_read = 0; 193 int total_bytes_read = 0;
187 194
188 std::string data_read; 195 std::string data_read;
189 for (;;) { 196 for (;;) {
190 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 197 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
191 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 198 rv = stream.Read(buf.get(), buf->size(), callback.callback());
192 rv = callback.GetResult(rv); 199 rv = callback.GetResult(rv);
193 EXPECT_LE(0, rv); 200 EXPECT_LE(0, rv);
194 if (rv <= 0) 201 if (rv <= 0)
195 break; 202 break;
196 total_bytes_read += rv; 203 total_bytes_read += rv;
197 data_read.append(buf->data(), rv); 204 data_read.append(buf->data(), rv);
198 } 205 }
199 EXPECT_EQ(file_size, total_bytes_read); 206 EXPECT_EQ(file_size, total_bytes_read);
200 EXPECT_EQ(kTestData, data_read); 207 EXPECT_EQ(kTestData, data_read);
201 } 208 }
202 209
203 TEST_F(FileStreamTest, Read_EarlyDelete) { 210 TEST_F(FileStreamTest, Read_EarlyDelete) {
204 int64_t file_size; 211 int64_t file_size;
205 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 212 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
206 213
207 std::unique_ptr<FileStream> stream( 214 std::unique_ptr<FileStream> stream(
208 new FileStream(base::ThreadTaskRunnerHandle::Get())); 215 new FileStream(base::ThreadTaskRunnerHandle::Get()));
209 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 216 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
210 base::File::FLAG_ASYNC; 217 base::File::FLAG_ASYNC;
211 TestCompletionCallback callback; 218 TestCompletionCallback callback;
212 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 219 int rv = stream->Open(temp_file_path(), flags, callback.callback());
213 EXPECT_EQ(ERR_IO_PENDING, rv); 220 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
214 EXPECT_EQ(OK, callback.WaitForResult()); 221 EXPECT_THAT(callback.WaitForResult(), IsOk());
215 222
216 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 223 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
217 rv = stream->Read(buf.get(), buf->size(), callback.callback()); 224 rv = stream->Read(buf.get(), buf->size(), callback.callback());
218 stream.reset(); // Delete instead of closing it. 225 stream.reset(); // Delete instead of closing it.
219 if (rv < 0) { 226 if (rv < 0) {
220 EXPECT_EQ(ERR_IO_PENDING, rv); 227 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
221 // The callback should not be called if the request is cancelled. 228 // The callback should not be called if the request is cancelled.
222 base::RunLoop().RunUntilIdle(); 229 base::RunLoop().RunUntilIdle();
223 EXPECT_FALSE(callback.have_result()); 230 EXPECT_FALSE(callback.have_result());
224 } else { 231 } else {
225 EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv)); 232 EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv));
226 } 233 }
227 } 234 }
228 235
229 TEST_F(FileStreamTest, Read_FromOffset) { 236 TEST_F(FileStreamTest, Read_FromOffset) {
230 int64_t file_size; 237 int64_t file_size;
231 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 238 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
232 239
233 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 240 FileStream stream(base::ThreadTaskRunnerHandle::Get());
234 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 241 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
235 base::File::FLAG_ASYNC; 242 base::File::FLAG_ASYNC;
236 TestCompletionCallback callback; 243 TestCompletionCallback callback;
237 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 244 int rv = stream.Open(temp_file_path(), flags, callback.callback());
238 EXPECT_EQ(ERR_IO_PENDING, rv); 245 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
239 EXPECT_EQ(OK, callback.WaitForResult()); 246 EXPECT_THAT(callback.WaitForResult(), IsOk());
240 247
241 TestInt64CompletionCallback callback64; 248 TestInt64CompletionCallback callback64;
242 const int64_t kOffset = 3; 249 const int64_t kOffset = 3;
243 rv = stream.Seek(kOffset, callback64.callback()); 250 rv = stream.Seek(kOffset, callback64.callback());
244 ASSERT_EQ(ERR_IO_PENDING, rv); 251 ASSERT_THAT(rv, IsError(ERR_IO_PENDING));
245 int64_t new_offset = callback64.WaitForResult(); 252 int64_t new_offset = callback64.WaitForResult();
246 EXPECT_EQ(kOffset, new_offset); 253 EXPECT_EQ(kOffset, new_offset);
247 254
248 int total_bytes_read = 0; 255 int total_bytes_read = 0;
249 256
250 std::string data_read; 257 std::string data_read;
251 for (;;) { 258 for (;;) {
252 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 259 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
253 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 260 rv = stream.Read(buf.get(), buf->size(), callback.callback());
254 if (rv == ERR_IO_PENDING) 261 if (rv == ERR_IO_PENDING)
255 rv = callback.WaitForResult(); 262 rv = callback.WaitForResult();
256 EXPECT_LE(0, rv); 263 EXPECT_LE(0, rv);
257 if (rv <= 0) 264 if (rv <= 0)
258 break; 265 break;
259 total_bytes_read += rv; 266 total_bytes_read += rv;
260 data_read.append(buf->data(), rv); 267 data_read.append(buf->data(), rv);
261 } 268 }
262 EXPECT_EQ(file_size - kOffset, total_bytes_read); 269 EXPECT_EQ(file_size - kOffset, total_bytes_read);
263 EXPECT_EQ(kTestData + kOffset, data_read); 270 EXPECT_EQ(kTestData + kOffset, data_read);
264 } 271 }
265 272
266 TEST_F(FileStreamTest, Write) { 273 TEST_F(FileStreamTest, Write) {
267 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 274 FileStream stream(base::ThreadTaskRunnerHandle::Get());
268 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 275 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
269 base::File::FLAG_ASYNC; 276 base::File::FLAG_ASYNC;
270 TestCompletionCallback callback; 277 TestCompletionCallback callback;
271 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 278 int rv = stream.Open(temp_file_path(), flags, callback.callback());
272 EXPECT_EQ(OK, callback.GetResult(rv)); 279 EXPECT_THAT(callback.GetResult(rv), IsOk());
273 280
274 int64_t file_size; 281 int64_t file_size;
275 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 282 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
276 EXPECT_EQ(0, file_size); 283 EXPECT_EQ(0, file_size);
277 284
278 scoped_refptr<IOBuffer> buf = CreateTestDataBuffer(); 285 scoped_refptr<IOBuffer> buf = CreateTestDataBuffer();
279 rv = stream.Write(buf.get(), kTestDataSize, callback.callback()); 286 rv = stream.Write(buf.get(), kTestDataSize, callback.callback());
280 rv = callback.GetResult(rv); 287 rv = callback.GetResult(rv);
281 EXPECT_EQ(kTestDataSize, rv); 288 EXPECT_EQ(kTestDataSize, rv);
282 289
283 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 290 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
284 EXPECT_EQ(kTestDataSize, file_size); 291 EXPECT_EQ(kTestDataSize, file_size);
285 292
286 std::string data_read; 293 std::string data_read;
287 EXPECT_TRUE(base::ReadFileToString(temp_file_path(), &data_read)); 294 EXPECT_TRUE(base::ReadFileToString(temp_file_path(), &data_read));
288 EXPECT_EQ(kTestData, data_read); 295 EXPECT_EQ(kTestData, data_read);
289 } 296 }
290 297
291 TEST_F(FileStreamTest, Write_EarlyDelete) { 298 TEST_F(FileStreamTest, Write_EarlyDelete) {
292 std::unique_ptr<FileStream> stream( 299 std::unique_ptr<FileStream> stream(
293 new FileStream(base::ThreadTaskRunnerHandle::Get())); 300 new FileStream(base::ThreadTaskRunnerHandle::Get()));
294 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 301 int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
295 base::File::FLAG_ASYNC; 302 base::File::FLAG_ASYNC;
296 TestCompletionCallback callback; 303 TestCompletionCallback callback;
297 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 304 int rv = stream->Open(temp_file_path(), flags, callback.callback());
298 EXPECT_EQ(ERR_IO_PENDING, rv); 305 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
299 EXPECT_EQ(OK, callback.WaitForResult()); 306 EXPECT_THAT(callback.WaitForResult(), IsOk());
300 307
301 int64_t file_size; 308 int64_t file_size;
302 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 309 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
303 EXPECT_EQ(0, file_size); 310 EXPECT_EQ(0, file_size);
304 311
305 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 312 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
306 rv = stream->Write(buf.get(), buf->size(), callback.callback()); 313 rv = stream->Write(buf.get(), buf->size(), callback.callback());
307 stream.reset(); 314 stream.reset();
308 if (rv < 0) { 315 if (rv < 0) {
309 EXPECT_EQ(ERR_IO_PENDING, rv); 316 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
310 // The callback should not be called if the request is cancelled. 317 // The callback should not be called if the request is cancelled.
311 base::RunLoop().RunUntilIdle(); 318 base::RunLoop().RunUntilIdle();
312 EXPECT_FALSE(callback.have_result()); 319 EXPECT_FALSE(callback.have_result());
313 } else { 320 } else {
314 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 321 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
315 EXPECT_EQ(file_size, rv); 322 EXPECT_EQ(file_size, rv);
316 } 323 }
317 } 324 }
318 325
319 TEST_F(FileStreamTest, Write_FromOffset) { 326 TEST_F(FileStreamTest, Write_FromOffset) {
320 int64_t file_size; 327 int64_t file_size;
321 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 328 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
322 329
323 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 330 FileStream stream(base::ThreadTaskRunnerHandle::Get());
324 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE | 331 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE |
325 base::File::FLAG_ASYNC; 332 base::File::FLAG_ASYNC;
326 TestCompletionCallback callback; 333 TestCompletionCallback callback;
327 int rv = stream.Open(temp_file_path(), flags, callback.callback()); 334 int rv = stream.Open(temp_file_path(), flags, callback.callback());
328 EXPECT_EQ(ERR_IO_PENDING, rv); 335 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
329 EXPECT_EQ(OK, callback.WaitForResult()); 336 EXPECT_THAT(callback.WaitForResult(), IsOk());
330 337
331 TestInt64CompletionCallback callback64; 338 TestInt64CompletionCallback callback64;
332 const int64_t kOffset = kTestDataSize; 339 const int64_t kOffset = kTestDataSize;
333 rv = stream.Seek(kOffset, callback64.callback()); 340 rv = stream.Seek(kOffset, callback64.callback());
334 ASSERT_EQ(ERR_IO_PENDING, rv); 341 ASSERT_THAT(rv, IsError(ERR_IO_PENDING));
335 int64_t new_offset = callback64.WaitForResult(); 342 int64_t new_offset = callback64.WaitForResult();
336 EXPECT_EQ(kTestDataSize, new_offset); 343 EXPECT_EQ(kTestDataSize, new_offset);
337 344
338 int total_bytes_written = 0; 345 int total_bytes_written = 0;
339 346
340 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 347 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
341 scoped_refptr<DrainableIOBuffer> drainable = 348 scoped_refptr<DrainableIOBuffer> drainable =
342 new DrainableIOBuffer(buf.get(), buf->size()); 349 new DrainableIOBuffer(buf.get(), buf->size());
343 while (total_bytes_written != kTestDataSize) { 350 while (total_bytes_written != kTestDataSize) {
344 rv = stream.Write(drainable.get(), drainable->BytesRemaining(), 351 rv = stream.Write(drainable.get(), drainable->BytesRemaining(),
(...skipping 13 matching lines...) Expand all
358 TEST_F(FileStreamTest, BasicReadWrite) { 365 TEST_F(FileStreamTest, BasicReadWrite) {
359 int64_t file_size; 366 int64_t file_size;
360 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 367 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
361 368
362 std::unique_ptr<FileStream> stream( 369 std::unique_ptr<FileStream> stream(
363 new FileStream(base::ThreadTaskRunnerHandle::Get())); 370 new FileStream(base::ThreadTaskRunnerHandle::Get()));
364 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 371 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
365 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 372 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
366 TestCompletionCallback callback; 373 TestCompletionCallback callback;
367 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 374 int rv = stream->Open(temp_file_path(), flags, callback.callback());
368 EXPECT_EQ(ERR_IO_PENDING, rv); 375 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
369 EXPECT_EQ(OK, callback.WaitForResult()); 376 EXPECT_THAT(callback.WaitForResult(), IsOk());
370 377
371 int64_t total_bytes_read = 0; 378 int64_t total_bytes_read = 0;
372 379
373 std::string data_read; 380 std::string data_read;
374 for (;;) { 381 for (;;) {
375 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 382 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
376 rv = stream->Read(buf.get(), buf->size(), callback.callback()); 383 rv = stream->Read(buf.get(), buf->size(), callback.callback());
377 if (rv == ERR_IO_PENDING) 384 if (rv == ERR_IO_PENDING)
378 rv = callback.WaitForResult(); 385 rv = callback.WaitForResult();
379 EXPECT_LE(0, rv); 386 EXPECT_LE(0, rv);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 TEST_F(FileStreamTest, BasicWriteRead) { 418 TEST_F(FileStreamTest, BasicWriteRead) {
412 int64_t file_size; 419 int64_t file_size;
413 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 420 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
414 421
415 std::unique_ptr<FileStream> stream( 422 std::unique_ptr<FileStream> stream(
416 new FileStream(base::ThreadTaskRunnerHandle::Get())); 423 new FileStream(base::ThreadTaskRunnerHandle::Get()));
417 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 424 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
418 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 425 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
419 TestCompletionCallback callback; 426 TestCompletionCallback callback;
420 int rv = stream->Open(temp_file_path(), flags, callback.callback()); 427 int rv = stream->Open(temp_file_path(), flags, callback.callback());
421 EXPECT_EQ(ERR_IO_PENDING, rv); 428 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
422 EXPECT_EQ(OK, callback.WaitForResult()); 429 EXPECT_THAT(callback.WaitForResult(), IsOk());
423 430
424 TestInt64CompletionCallback callback64; 431 TestInt64CompletionCallback callback64;
425 rv = stream->Seek(file_size, callback64.callback()); 432 rv = stream->Seek(file_size, callback64.callback());
426 ASSERT_EQ(ERR_IO_PENDING, rv); 433 ASSERT_THAT(rv, IsError(ERR_IO_PENDING));
427 int64_t offset = callback64.WaitForResult(); 434 int64_t offset = callback64.WaitForResult();
428 EXPECT_EQ(offset, file_size); 435 EXPECT_EQ(offset, file_size);
429 436
430 int total_bytes_written = 0; 437 int total_bytes_written = 0;
431 438
432 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 439 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
433 scoped_refptr<DrainableIOBuffer> drainable = 440 scoped_refptr<DrainableIOBuffer> drainable =
434 new DrainableIOBuffer(buf.get(), buf->size()); 441 new DrainableIOBuffer(buf.get(), buf->size());
435 while (total_bytes_written != kTestDataSize) { 442 while (total_bytes_written != kTestDataSize) {
436 rv = stream->Write(drainable.get(), drainable->BytesRemaining(), 443 rv = stream->Write(drainable.get(), drainable->BytesRemaining(),
437 callback.callback()); 444 callback.callback());
438 if (rv == ERR_IO_PENDING) 445 if (rv == ERR_IO_PENDING)
439 rv = callback.WaitForResult(); 446 rv = callback.WaitForResult();
440 EXPECT_LT(0, rv); 447 EXPECT_LT(0, rv);
441 if (rv <= 0) 448 if (rv <= 0)
442 break; 449 break;
443 drainable->DidConsume(rv); 450 drainable->DidConsume(rv);
444 total_bytes_written += rv; 451 total_bytes_written += rv;
445 } 452 }
446 453
447 EXPECT_EQ(kTestDataSize, total_bytes_written); 454 EXPECT_EQ(kTestDataSize, total_bytes_written);
448 455
449 rv = stream->Seek(0, callback64.callback()); 456 rv = stream->Seek(0, callback64.callback());
450 ASSERT_EQ(ERR_IO_PENDING, rv); 457 ASSERT_THAT(rv, IsError(ERR_IO_PENDING));
451 offset = callback64.WaitForResult(); 458 offset = callback64.WaitForResult();
452 EXPECT_EQ(0, offset); 459 EXPECT_EQ(0, offset);
453 460
454 int total_bytes_read = 0; 461 int total_bytes_read = 0;
455 462
456 std::string data_read; 463 std::string data_read;
457 for (;;) { 464 for (;;) {
458 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 465 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
459 rv = stream->Read(buf.get(), buf->size(), callback.callback()); 466 rv = stream->Read(buf.get(), buf->size(), callback.callback());
460 if (rv == ERR_IO_PENDING) 467 if (rv == ERR_IO_PENDING)
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 rv = stream_->Write( 549 rv = stream_->Write(
543 drainable_.get(), drainable_->BytesRemaining(), callback.callback()); 550 drainable_.get(), drainable_->BytesRemaining(), callback.callback());
544 DCHECK_EQ(ERR_IO_PENDING, rv); 551 DCHECK_EQ(ERR_IO_PENDING, rv);
545 rv = callback.WaitForResult(); 552 rv = callback.WaitForResult();
546 drainable_->DidConsume(total_bytes_written); 553 drainable_->DidConsume(total_bytes_written);
547 *total_bytes_written_ += total_bytes_written; 554 *total_bytes_written_ += total_bytes_written;
548 *total_bytes_read_ += total_bytes_read; 555 *total_bytes_read_ += total_bytes_read;
549 *data_read_ += data_read; 556 *data_read_ += data_read;
550 } else { // We're done writing all data. Start reading the data. 557 } else { // We're done writing all data. Start reading the data.
551 TestInt64CompletionCallback callback64; 558 TestInt64CompletionCallback callback64;
552 EXPECT_EQ(ERR_IO_PENDING, stream_->Seek(0, callback64.callback())); 559 EXPECT_THAT(stream_->Seek(0, callback64.callback()),
560 IsError(ERR_IO_PENDING));
553 { 561 {
554 base::MessageLoop::ScopedNestableTaskAllower allow( 562 base::MessageLoop::ScopedNestableTaskAllower allow(
555 base::MessageLoop::current()); 563 base::MessageLoop::current());
556 EXPECT_LE(0, callback64.WaitForResult()); 564 EXPECT_LE(0, callback64.WaitForResult());
557 } 565 }
558 } 566 }
559 567
560 result_ = *total_bytes_written_; 568 result_ = *total_bytes_written_;
561 have_result_ = true; 569 have_result_ = true;
562 if (waiting_for_result_) 570 if (waiting_for_result_)
(...skipping 17 matching lines...) Expand all
580 TEST_F(FileStreamTest, WriteRead) { 588 TEST_F(FileStreamTest, WriteRead) {
581 int64_t file_size; 589 int64_t file_size;
582 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 590 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
583 591
584 std::unique_ptr<FileStream> stream( 592 std::unique_ptr<FileStream> stream(
585 new FileStream(base::ThreadTaskRunnerHandle::Get())); 593 new FileStream(base::ThreadTaskRunnerHandle::Get()));
586 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 594 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
587 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 595 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
588 TestCompletionCallback open_callback; 596 TestCompletionCallback open_callback;
589 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 597 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
590 EXPECT_EQ(ERR_IO_PENDING, rv); 598 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
591 EXPECT_EQ(OK, open_callback.WaitForResult()); 599 EXPECT_THAT(open_callback.WaitForResult(), IsOk());
592 600
593 TestInt64CompletionCallback callback64; 601 TestInt64CompletionCallback callback64;
594 EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback())); 602 EXPECT_THAT(stream->Seek(file_size, callback64.callback()),
603 IsError(ERR_IO_PENDING));
595 EXPECT_EQ(file_size, callback64.WaitForResult()); 604 EXPECT_EQ(file_size, callback64.WaitForResult());
596 605
597 int total_bytes_written = 0; 606 int total_bytes_written = 0;
598 int total_bytes_read = 0; 607 int total_bytes_read = 0;
599 std::string data_read; 608 std::string data_read;
600 TestWriteReadCompletionCallback callback(stream.get(), &total_bytes_written, 609 TestWriteReadCompletionCallback callback(stream.get(), &total_bytes_written,
601 &total_bytes_read, &data_read); 610 &total_bytes_read, &data_read);
602 611
603 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 612 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
604 rv = stream->Write(buf.get(), buf->size(), callback.callback()); 613 rv = stream->Write(buf.get(), buf->size(), callback.callback());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 TEST_F(FileStreamTest, WriteClose) { 695 TEST_F(FileStreamTest, WriteClose) {
687 int64_t file_size; 696 int64_t file_size;
688 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 697 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
689 698
690 std::unique_ptr<FileStream> stream( 699 std::unique_ptr<FileStream> stream(
691 new FileStream(base::ThreadTaskRunnerHandle::Get())); 700 new FileStream(base::ThreadTaskRunnerHandle::Get()));
692 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 701 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
693 base::File::FLAG_WRITE | base::File::FLAG_ASYNC; 702 base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
694 TestCompletionCallback open_callback; 703 TestCompletionCallback open_callback;
695 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 704 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
696 EXPECT_EQ(ERR_IO_PENDING, rv); 705 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
697 EXPECT_EQ(OK, open_callback.WaitForResult()); 706 EXPECT_THAT(open_callback.WaitForResult(), IsOk());
698 707
699 TestInt64CompletionCallback callback64; 708 TestInt64CompletionCallback callback64;
700 EXPECT_EQ(ERR_IO_PENDING, stream->Seek(file_size, callback64.callback())); 709 EXPECT_THAT(stream->Seek(file_size, callback64.callback()),
710 IsError(ERR_IO_PENDING));
701 EXPECT_EQ(file_size, callback64.WaitForResult()); 711 EXPECT_EQ(file_size, callback64.WaitForResult());
702 712
703 int total_bytes_written = 0; 713 int total_bytes_written = 0;
704 TestWriteCloseCompletionCallback callback(stream.get(), &total_bytes_written); 714 TestWriteCloseCompletionCallback callback(stream.get(), &total_bytes_written);
705 715
706 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer(); 716 scoped_refptr<IOBufferWithSize> buf = CreateTestDataBuffer();
707 rv = stream->Write(buf.get(), buf->size(), callback.callback()); 717 rv = stream->Write(buf.get(), buf->size(), callback.callback());
708 if (rv == ERR_IO_PENDING) 718 if (rv == ERR_IO_PENDING)
709 total_bytes_written = callback.WaitForResult(); 719 total_bytes_written = callback.WaitForResult();
710 EXPECT_LT(0, total_bytes_written); 720 EXPECT_LT(0, total_bytes_written);
711 EXPECT_EQ(kTestDataSize, total_bytes_written); 721 EXPECT_EQ(kTestDataSize, total_bytes_written);
712 722
713 stream.reset(); 723 stream.reset();
714 724
715 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 725 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
716 EXPECT_EQ(kTestDataSize * 2, file_size); 726 EXPECT_EQ(kTestDataSize * 2, file_size);
717 } 727 }
718 728
719 TEST_F(FileStreamTest, OpenAndDelete) { 729 TEST_F(FileStreamTest, OpenAndDelete) {
720 base::SequencedWorkerPoolOwner pool_owner(1, "StreamTest"); 730 base::SequencedWorkerPoolOwner pool_owner(1, "StreamTest");
721 731
722 bool prev = base::ThreadRestrictions::SetIOAllowed(false); 732 bool prev = base::ThreadRestrictions::SetIOAllowed(false);
723 std::unique_ptr<FileStream> stream(new FileStream(pool_owner.pool())); 733 std::unique_ptr<FileStream> stream(new FileStream(pool_owner.pool()));
724 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE | 734 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE |
725 base::File::FLAG_ASYNC; 735 base::File::FLAG_ASYNC;
726 TestCompletionCallback open_callback; 736 TestCompletionCallback open_callback;
727 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 737 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
728 EXPECT_EQ(ERR_IO_PENDING, rv); 738 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
729 739
730 // Delete the stream without waiting for the open operation to be 740 // Delete the stream without waiting for the open operation to be
731 // complete. Should be safe. 741 // complete. Should be safe.
732 stream.reset(); 742 stream.reset();
733 743
734 // Force an operation through the pool. 744 // Force an operation through the pool.
735 std::unique_ptr<FileStream> stream2(new FileStream(pool_owner.pool())); 745 std::unique_ptr<FileStream> stream2(new FileStream(pool_owner.pool()));
736 TestCompletionCallback open_callback2; 746 TestCompletionCallback open_callback2;
737 rv = stream2->Open(temp_file_path(), flags, open_callback2.callback()); 747 rv = stream2->Open(temp_file_path(), flags, open_callback2.callback());
738 EXPECT_EQ(OK, open_callback2.GetResult(rv)); 748 EXPECT_THAT(open_callback2.GetResult(rv), IsOk());
739 stream2.reset(); 749 stream2.reset();
740 750
741 // open_callback won't be called. 751 // open_callback won't be called.
742 base::RunLoop().RunUntilIdle(); 752 base::RunLoop().RunUntilIdle();
743 EXPECT_FALSE(open_callback.have_result()); 753 EXPECT_FALSE(open_callback.have_result());
744 base::ThreadRestrictions::SetIOAllowed(prev); 754 base::ThreadRestrictions::SetIOAllowed(prev);
745 } 755 }
746 756
747 // Verify that Write() errors are mapped correctly. 757 // Verify that Write() errors are mapped correctly.
748 TEST_F(FileStreamTest, WriteError) { 758 TEST_F(FileStreamTest, WriteError) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 EXPECT_TRUE(base::PathExists(path)); 819 EXPECT_TRUE(base::PathExists(path));
810 int64_t file_size; 820 int64_t file_size;
811 EXPECT_TRUE(base::GetFileSize(path, &file_size)); 821 EXPECT_TRUE(base::GetFileSize(path, &file_size));
812 EXPECT_LT(0, file_size); 822 EXPECT_LT(0, file_size);
813 823
814 FileStream stream(base::ThreadTaskRunnerHandle::Get()); 824 FileStream stream(base::ThreadTaskRunnerHandle::Get());
815 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | 825 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
816 base::File::FLAG_ASYNC; 826 base::File::FLAG_ASYNC;
817 TestCompletionCallback callback; 827 TestCompletionCallback callback;
818 int rv = stream.Open(path, flags, callback.callback()); 828 int rv = stream.Open(path, flags, callback.callback());
819 EXPECT_EQ(ERR_IO_PENDING, rv); 829 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
820 EXPECT_EQ(OK, callback.WaitForResult()); 830 EXPECT_THAT(callback.WaitForResult(), IsOk());
821 831
822 int total_bytes_read = 0; 832 int total_bytes_read = 0;
823 833
824 std::string data_read; 834 std::string data_read;
825 for (;;) { 835 for (;;) {
826 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4); 836 scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
827 rv = stream.Read(buf.get(), buf->size(), callback.callback()); 837 rv = stream.Read(buf.get(), buf->size(), callback.callback());
828 if (rv == ERR_IO_PENDING) 838 if (rv == ERR_IO_PENDING)
829 rv = callback.WaitForResult(); 839 rv = callback.WaitForResult();
830 EXPECT_LE(0, rv); 840 EXPECT_LE(0, rv);
831 if (rv <= 0) 841 if (rv <= 0)
832 break; 842 break;
833 total_bytes_read += rv; 843 total_bytes_read += rv;
834 data_read.append(buf->data(), rv); 844 data_read.append(buf->data(), rv);
835 } 845 }
836 EXPECT_EQ(file_size, total_bytes_read); 846 EXPECT_EQ(file_size, total_bytes_read);
837 } 847 }
838 #endif 848 #endif
839 849
840 } // namespace 850 } // namespace
841 851
842 } // namespace net 852 } // namespace net
OLDNEW
« no previous file with comments | « net/base/elements_upload_data_stream_unittest.cc ('k') | net/base/static_cookie_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698