OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 total_bytes_to_read); | 274 total_bytes_to_read); |
275 | 275 |
276 // For the first read, the internal file stream reader is fired, as there is | 276 // For the first read, the internal file stream reader is fired, as there is |
277 // no data in the preloading buffer. | 277 // no data in the preloading buffer. |
278 const int read_bytes = 2; | 278 const int read_bytes = 2; |
279 ASSERT_LT(read_bytes, kPreloadingBufferLength); | 279 ASSERT_LT(read_bytes, kPreloadingBufferLength); |
280 ASSERT_LE(read_bytes, total_bytes_to_read); | 280 ASSERT_LE(read_bytes, total_bytes_to_read); |
281 | 281 |
282 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read_bytes)); | 282 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read_bytes)); |
283 std::vector<int> read_log; | 283 std::vector<int> read_log; |
284 const int result = | 284 const int result = reader.Read( |
285 reader.Read(buffer, read_bytes, base::Bind(&LogValue<int>, &read_log)); | 285 buffer.get(), read_bytes, base::Bind(&LogValue<int>, &read_log)); |
286 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
287 | 287 |
288 EXPECT_EQ(net::ERR_IO_PENDING, result); | 288 EXPECT_EQ(net::ERR_IO_PENDING, result); |
289 ASSERT_EQ(1u, inner_read_log.size()); | 289 ASSERT_EQ(1u, inner_read_log.size()); |
290 EXPECT_EQ(total_bytes_to_read, inner_read_log[0]); | 290 EXPECT_EQ(total_bytes_to_read, inner_read_log[0]); |
291 ASSERT_EQ(1u, read_log.size()); | 291 ASSERT_EQ(1u, read_log.size()); |
292 EXPECT_EQ(read_bytes, read_log[0]); | 292 EXPECT_EQ(read_bytes, read_log[0]); |
293 } | 293 } |
294 | 294 |
295 TEST_F(FileSystemProviderBufferingFileStreamReaderTest, | 295 TEST_F(FileSystemProviderBufferingFileStreamReaderTest, |
296 Read_LessThanBufferSize_WithoutSpecifiedLength) { | 296 Read_LessThanBufferSize_WithoutSpecifiedLength) { |
297 std::vector<int> inner_read_log; | 297 std::vector<int> inner_read_log; |
298 BufferingFileStreamReader reader( | 298 BufferingFileStreamReader reader( |
299 scoped_ptr<storage::FileStreamReader>( | 299 scoped_ptr<storage::FileStreamReader>( |
300 new FakeFileStreamReader(&inner_read_log, net::OK)), | 300 new FakeFileStreamReader(&inner_read_log, net::OK)), |
301 kPreloadingBufferLength, | 301 kPreloadingBufferLength, |
302 storage::kMaximumLength); | 302 storage::kMaximumLength); |
303 | 303 |
304 // For the first read, the internal file stream reader is fired, as there is | 304 // For the first read, the internal file stream reader is fired, as there is |
305 // no data in the preloading buffer. | 305 // no data in the preloading buffer. |
306 const int read_bytes = 2; | 306 const int read_bytes = 2; |
307 ASSERT_LT(read_bytes, kPreloadingBufferLength); | 307 ASSERT_LT(read_bytes, kPreloadingBufferLength); |
308 | 308 |
309 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read_bytes)); | 309 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read_bytes)); |
310 std::vector<int> read_log; | 310 std::vector<int> read_log; |
311 const int result = | 311 const int result = reader.Read( |
312 reader.Read(buffer, read_bytes, base::Bind(&LogValue<int>, &read_log)); | 312 buffer.get(), read_bytes, base::Bind(&LogValue<int>, &read_log)); |
313 base::RunLoop().RunUntilIdle(); | 313 base::RunLoop().RunUntilIdle(); |
314 | 314 |
315 EXPECT_EQ(net::ERR_IO_PENDING, result); | 315 EXPECT_EQ(net::ERR_IO_PENDING, result); |
316 ASSERT_EQ(1u, inner_read_log.size()); | 316 ASSERT_EQ(1u, inner_read_log.size()); |
317 EXPECT_EQ(kPreloadingBufferLength, inner_read_log[0]); | 317 EXPECT_EQ(kPreloadingBufferLength, inner_read_log[0]); |
318 ASSERT_EQ(1u, read_log.size()); | 318 ASSERT_EQ(1u, read_log.size()); |
319 EXPECT_EQ(read_bytes, read_log[0]); | 319 EXPECT_EQ(read_bytes, read_log[0]); |
320 } | 320 } |
321 | 321 |
322 TEST_F(FileSystemProviderBufferingFileStreamReaderTest, Read_WithError) { | 322 TEST_F(FileSystemProviderBufferingFileStreamReaderTest, Read_WithError) { |
(...skipping 28 matching lines...) Expand all Loading... |
351 reader.GetLength(base::Bind(&LogValue<int64>, &get_length_log)); | 351 reader.GetLength(base::Bind(&LogValue<int64>, &get_length_log)); |
352 base::RunLoop().RunUntilIdle(); | 352 base::RunLoop().RunUntilIdle(); |
353 | 353 |
354 EXPECT_EQ(net::ERR_IO_PENDING, result); | 354 EXPECT_EQ(net::ERR_IO_PENDING, result); |
355 ASSERT_EQ(1u, get_length_log.size()); | 355 ASSERT_EQ(1u, get_length_log.size()); |
356 EXPECT_EQ(kFileSize, get_length_log[0]); | 356 EXPECT_EQ(kFileSize, get_length_log[0]); |
357 } | 357 } |
358 | 358 |
359 } // namespace file_system_provider | 359 } // namespace file_system_provider |
360 } // namespace chromeos | 360 } // namespace chromeos |
OLD | NEW |