| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/drive/drive_file_stream_reader.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_stream_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <string> | 10 #include <string> |
| 8 | 11 |
| 9 #include "base/bind.h" | 12 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 13 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 14 #include "components/drive/drive_test_util.h" | 17 #include "components/drive/drive_test_util.h" |
| 15 #include "components/drive/fake_file_system.h" | 18 #include "components/drive/fake_file_system.h" |
| 16 #include "components/drive/file_system_core_util.h" | 19 #include "components/drive/file_system_core_util.h" |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // Read data from the reader, again. | 386 // Read data from the reader, again. |
| 384 std::string second_content; | 387 std::string second_content; |
| 385 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); | 388 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); |
| 386 | 389 |
| 387 // The same content is expected. | 390 // The same content is expected. |
| 388 EXPECT_EQ(first_content, second_content); | 391 EXPECT_EQ(first_content, second_content); |
| 389 } | 392 } |
| 390 | 393 |
| 391 TEST_F(DriveFileStreamReaderTest, ReadRange) { | 394 TEST_F(DriveFileStreamReaderTest, ReadRange) { |
| 392 // In this test case, we just confirm that the part of file is read. | 395 // In this test case, we just confirm that the part of file is read. |
| 393 const int64 kRangeOffset = 3; | 396 const int64_t kRangeOffset = 3; |
| 394 const int64 kRangeLength = 4; | 397 const int64_t kRangeLength = 4; |
| 395 | 398 |
| 396 const base::FilePath kDriveFile = | 399 const base::FilePath kDriveFile = |
| 397 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 400 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 398 // Create the reader, and initialize it. | 401 // Create the reader, and initialize it. |
| 399 // In this case, the file is not yet locally cached. | 402 // In this case, the file is not yet locally cached. |
| 400 scoped_ptr<DriveFileStreamReader> reader(new DriveFileStreamReader( | 403 scoped_ptr<DriveFileStreamReader> reader(new DriveFileStreamReader( |
| 401 GetFileSystemGetter(), worker_thread_->task_runner().get())); | 404 GetFileSystemGetter(), worker_thread_->task_runner().get())); |
| 402 EXPECT_FALSE(reader->IsInitialized()); | 405 EXPECT_FALSE(reader->IsInitialized()); |
| 403 | 406 |
| 404 int error = net::ERR_FAILED; | 407 int error = net::ERR_FAILED; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 419 } | 422 } |
| 420 EXPECT_EQ(net::OK, error); | 423 EXPECT_EQ(net::OK, error); |
| 421 ASSERT_TRUE(entry); | 424 ASSERT_TRUE(entry); |
| 422 EXPECT_TRUE(reader->IsInitialized()); | 425 EXPECT_TRUE(reader->IsInitialized()); |
| 423 | 426 |
| 424 // Read data from the reader. | 427 // Read data from the reader. |
| 425 std::string first_content; | 428 std::string first_content; |
| 426 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &first_content)); | 429 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &first_content)); |
| 427 | 430 |
| 428 // The length should be equal to range length. | 431 // The length should be equal to range length. |
| 429 EXPECT_EQ(kRangeLength, static_cast<int64>(first_content.size())); | 432 EXPECT_EQ(kRangeLength, static_cast<int64_t>(first_content.size())); |
| 430 | 433 |
| 431 // Create second instance and initialize it. | 434 // Create second instance and initialize it. |
| 432 // In this case, the file should be cached one. | 435 // In this case, the file should be cached one. |
| 433 reader.reset(new DriveFileStreamReader(GetFileSystemGetter(), | 436 reader.reset(new DriveFileStreamReader(GetFileSystemGetter(), |
| 434 worker_thread_->task_runner().get())); | 437 worker_thread_->task_runner().get())); |
| 435 EXPECT_FALSE(reader->IsInitialized()); | 438 EXPECT_FALSE(reader->IsInitialized()); |
| 436 | 439 |
| 437 error = net::ERR_FAILED; | 440 error = net::ERR_FAILED; |
| 438 entry.reset(); | 441 entry.reset(); |
| 439 { | 442 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 452 | 455 |
| 453 // Read data from the reader, again. | 456 // Read data from the reader, again. |
| 454 std::string second_content; | 457 std::string second_content; |
| 455 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); | 458 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); |
| 456 | 459 |
| 457 // The same content is expected. | 460 // The same content is expected. |
| 458 EXPECT_EQ(first_content, second_content); | 461 EXPECT_EQ(first_content, second_content); |
| 459 } | 462 } |
| 460 | 463 |
| 461 TEST_F(DriveFileStreamReaderTest, OutOfRangeError) { | 464 TEST_F(DriveFileStreamReaderTest, OutOfRangeError) { |
| 462 const int64 kRangeOffset = 1000000; // Out of range. | 465 const int64_t kRangeOffset = 1000000; // Out of range. |
| 463 const int64 kRangeLength = 4; | 466 const int64_t kRangeLength = 4; |
| 464 | 467 |
| 465 const base::FilePath kDriveFile = | 468 const base::FilePath kDriveFile = |
| 466 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 469 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 467 // Create the reader, and initialize it. | 470 // Create the reader, and initialize it. |
| 468 // In this case, the file is not yet locally cached. | 471 // In this case, the file is not yet locally cached. |
| 469 scoped_ptr<DriveFileStreamReader> reader(new DriveFileStreamReader( | 472 scoped_ptr<DriveFileStreamReader> reader(new DriveFileStreamReader( |
| 470 GetFileSystemGetter(), worker_thread_->task_runner().get())); | 473 GetFileSystemGetter(), worker_thread_->task_runner().get())); |
| 471 EXPECT_FALSE(reader->IsInitialized()); | 474 EXPECT_FALSE(reader->IsInitialized()); |
| 472 | 475 |
| 473 int error = net::ERR_FAILED; | 476 int error = net::ERR_FAILED; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 ASSERT_TRUE(entry); | 563 ASSERT_TRUE(entry); |
| 561 EXPECT_TRUE(reader->IsInitialized()); | 564 EXPECT_TRUE(reader->IsInitialized()); |
| 562 | 565 |
| 563 // Read data from the reader, again. | 566 // Read data from the reader, again. |
| 564 std::string second_content; | 567 std::string second_content; |
| 565 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); | 568 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &second_content)); |
| 566 EXPECT_EQ(0u, second_content.size()); | 569 EXPECT_EQ(0u, second_content.size()); |
| 567 } | 570 } |
| 568 | 571 |
| 569 } // namespace drive | 572 } // namespace drive |
| OLD | NEW |