| 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 "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h
" | 5 #include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.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/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.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 "base/time/time.h" | 17 #include "base/time/time.h" |
| 15 #include "components/drive/drive_test_util.h" | 18 #include "components/drive/drive_test_util.h" |
| 16 #include "components/drive/fake_file_system.h" | 19 #include "components/drive/fake_file_system.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 76 |
| 74 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 77 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 75 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 78 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 76 0, // offset | 79 0, // offset |
| 77 base::Time())); // expected modification time | 80 base::Time())); // expected modification time |
| 78 | 81 |
| 79 std::string content; | 82 std::string content; |
| 80 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 83 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
| 81 | 84 |
| 82 net::TestInt64CompletionCallback callback; | 85 net::TestInt64CompletionCallback callback; |
| 83 int64 length = reader->GetLength(callback.callback()); | 86 int64_t length = reader->GetLength(callback.callback()); |
| 84 length = callback.GetResult(length); | 87 length = callback.GetResult(length); |
| 85 EXPECT_EQ(content.size(), static_cast<size_t>(length)); | 88 EXPECT_EQ(content.size(), static_cast<size_t>(length)); |
| 86 } | 89 } |
| 87 | 90 |
| 88 TEST_F(WebkitFileStreamReaderImplTest, GetLengthThenRead) { | 91 TEST_F(WebkitFileStreamReaderImplTest, GetLengthThenRead) { |
| 89 const base::FilePath kDriveFile = | 92 const base::FilePath kDriveFile = |
| 90 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 93 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 91 | 94 |
| 92 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 95 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 93 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 96 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 94 0, // offset | 97 0, // offset |
| 95 base::Time())); // expected modification time | 98 base::Time())); // expected modification time |
| 96 | 99 |
| 97 net::TestInt64CompletionCallback callback; | 100 net::TestInt64CompletionCallback callback; |
| 98 int64 length = reader->GetLength(callback.callback()); | 101 int64_t length = reader->GetLength(callback.callback()); |
| 99 length = callback.GetResult(length); | 102 length = callback.GetResult(length); |
| 100 | 103 |
| 101 std::string content; | 104 std::string content; |
| 102 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 105 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
| 103 EXPECT_EQ(content.size(), static_cast<size_t>(length)); | 106 EXPECT_EQ(content.size(), static_cast<size_t>(length)); |
| 104 } | 107 } |
| 105 | 108 |
| 106 TEST_F(WebkitFileStreamReaderImplTest, ReadWithOffset) { | 109 TEST_F(WebkitFileStreamReaderImplTest, ReadWithOffset) { |
| 107 const base::FilePath kDriveFile = | 110 const base::FilePath kDriveFile = |
| 108 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 111 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 109 const int kOffset = 5; | 112 const int kOffset = 5; |
| 110 | 113 |
| 111 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 114 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 112 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 115 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 113 kOffset, | 116 kOffset, |
| 114 base::Time())); // expected modification time | 117 base::Time())); // expected modification time |
| 115 | 118 |
| 116 std::string content; | 119 std::string content; |
| 117 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 120 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
| 118 | 121 |
| 119 net::TestInt64CompletionCallback callback; | 122 net::TestInt64CompletionCallback callback; |
| 120 int64 length = reader->GetLength(callback.callback()); | 123 int64_t length = reader->GetLength(callback.callback()); |
| 121 length = callback.GetResult(length); | 124 length = callback.GetResult(length); |
| 122 EXPECT_EQ(content.size() + kOffset, static_cast<size_t>(length)); | 125 EXPECT_EQ(content.size() + kOffset, static_cast<size_t>(length)); |
| 123 } | 126 } |
| 124 | 127 |
| 125 TEST_F(WebkitFileStreamReaderImplTest, ReadError) { | 128 TEST_F(WebkitFileStreamReaderImplTest, ReadError) { |
| 126 const base::FilePath kDriveFile = | 129 const base::FilePath kDriveFile = |
| 127 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); | 130 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); |
| 128 | 131 |
| 129 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 132 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 130 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 133 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 TEST_F(WebkitFileStreamReaderImplTest, GetLengthError) { | 145 TEST_F(WebkitFileStreamReaderImplTest, GetLengthError) { |
| 143 const base::FilePath kDriveFile = | 146 const base::FilePath kDriveFile = |
| 144 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); | 147 util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt"); |
| 145 | 148 |
| 146 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 149 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 147 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 150 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 148 0, // offset | 151 0, // offset |
| 149 base::Time())); // expected modification time | 152 base::Time())); // expected modification time |
| 150 | 153 |
| 151 net::TestInt64CompletionCallback callback; | 154 net::TestInt64CompletionCallback callback; |
| 152 int64 result = reader->GetLength(callback.callback()); | 155 int64_t result = reader->GetLength(callback.callback()); |
| 153 result = callback.GetResult(result); | 156 result = callback.GetResult(result); |
| 154 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); | 157 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result); |
| 155 } | 158 } |
| 156 | 159 |
| 157 TEST_F(WebkitFileStreamReaderImplTest, LastModification) { | 160 TEST_F(WebkitFileStreamReaderImplTest, LastModification) { |
| 158 const base::FilePath kDriveFile = | 161 const base::FilePath kDriveFile = |
| 159 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 162 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 160 | 163 |
| 161 base::Time expected_modification_time; | 164 base::Time expected_modification_time; |
| 162 ASSERT_TRUE(google_apis::util::GetTimeFromString( | 165 ASSERT_TRUE(google_apis::util::GetTimeFromString( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 182 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); | 185 google_apis::test_util::CreateCopyResultCallback(&status, &server_entry)); |
| 183 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
| 184 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); | 187 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); |
| 185 | 188 |
| 186 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 189 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 187 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 190 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 188 0, // offset | 191 0, // offset |
| 189 expected_modification_time)); | 192 expected_modification_time)); |
| 190 | 193 |
| 191 net::TestInt64CompletionCallback callback; | 194 net::TestInt64CompletionCallback callback; |
| 192 int64 result = reader->GetLength(callback.callback()); | 195 int64_t result = reader->GetLength(callback.callback()); |
| 193 result = callback.GetResult(result); | 196 result = callback.GetResult(result); |
| 194 | 197 |
| 195 std::string content; | 198 std::string content; |
| 196 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); | 199 ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content)); |
| 197 EXPECT_GE(content.size(), static_cast<size_t>(result)); | 200 EXPECT_GE(content.size(), static_cast<size_t>(result)); |
| 198 } | 201 } |
| 199 | 202 |
| 200 // TODO(hashimoto): Enable this test. crbug.com/346625 | 203 // TODO(hashimoto): Enable this test. crbug.com/346625 |
| 201 TEST_F(WebkitFileStreamReaderImplTest, DISABLED_LastModificationError) { | 204 TEST_F(WebkitFileStreamReaderImplTest, DISABLED_LastModificationError) { |
| 202 const base::FilePath kDriveFile = | 205 const base::FilePath kDriveFile = |
| 203 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 206 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
| 204 | 207 |
| 205 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( | 208 scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl( |
| 206 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, | 209 GetFileSystemGetter(), worker_thread_->task_runner().get(), kDriveFile, |
| 207 0, // offset | 210 0, // offset |
| 208 base::Time::FromInternalValue(1))); | 211 base::Time::FromInternalValue(1))); |
| 209 | 212 |
| 210 net::TestInt64CompletionCallback callback; | 213 net::TestInt64CompletionCallback callback; |
| 211 int64 result = reader->GetLength(callback.callback()); | 214 int64_t result = reader->GetLength(callback.callback()); |
| 212 result = callback.GetResult(result); | 215 result = callback.GetResult(result); |
| 213 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); | 216 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); |
| 214 } | 217 } |
| 215 | 218 |
| 216 } // namespace internal | 219 } // namespace internal |
| 217 } // namespace drive | 220 } // namespace drive |
| OLD | NEW |