OLD | NEW |
---|---|
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/upload_file_element_reader.h" | 5 #include "net/base/upload_file_element_reader.h" |
6 | 6 |
7 #include <limits> | |
8 | |
7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
10 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
11 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
13 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
16 | 18 |
(...skipping 10 matching lines...) Expand all Loading... | |
27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
28 | 30 |
29 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), | 31 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
30 &temp_file_path_)); | 32 &temp_file_path_)); |
31 ASSERT_EQ( | 33 ASSERT_EQ( |
32 static_cast<int>(bytes_.size()), | 34 static_cast<int>(bytes_.size()), |
33 base::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); | 35 base::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); |
34 | 36 |
35 reader_.reset(new UploadFileElementReader( | 37 reader_.reset(new UploadFileElementReader( |
36 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, | 38 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, |
37 kuint64max, base::Time())); | 39 std::numeric_limits<uint64_t>::max(), base::Time())); |
mmenke
2015/12/07 16:06:51
include stdint.h
Avi (use Gerrit)
2015/12/07 16:30:06
Done.
| |
38 TestCompletionCallback callback; | 40 TestCompletionCallback callback; |
39 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback())); | 41 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback())); |
40 EXPECT_EQ(OK, callback.WaitForResult()); | 42 EXPECT_EQ(OK, callback.WaitForResult()); |
41 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); | 43 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); |
42 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); | 44 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); |
43 EXPECT_FALSE(reader_->IsInMemory()); | 45 EXPECT_FALSE(reader_->IsInMemory()); |
44 } | 46 } |
45 | 47 |
46 ~UploadFileElementReaderTest() override { | 48 ~UploadFileElementReaderTest() override { |
47 reader_.reset(); | 49 reader_.reset(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 } | 200 } |
199 | 201 |
200 TEST_F(UploadFileElementReaderTest, FileChanged) { | 202 TEST_F(UploadFileElementReaderTest, FileChanged) { |
201 base::File::Info info; | 203 base::File::Info info; |
202 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); | 204 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); |
203 | 205 |
204 // Expect one second before the actual modification time to simulate change. | 206 // Expect one second before the actual modification time to simulate change. |
205 const base::Time expected_modification_time = | 207 const base::Time expected_modification_time = |
206 info.last_modified - base::TimeDelta::FromSeconds(1); | 208 info.last_modified - base::TimeDelta::FromSeconds(1); |
207 reader_.reset(new UploadFileElementReader( | 209 reader_.reset(new UploadFileElementReader( |
208 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, kuint64max, | 210 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, |
209 expected_modification_time)); | 211 std::numeric_limits<uint64_t>::max(), expected_modification_time)); |
210 TestCompletionCallback init_callback; | 212 TestCompletionCallback init_callback; |
211 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 213 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
212 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); | 214 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); |
213 } | 215 } |
214 | 216 |
215 TEST_F(UploadFileElementReaderTest, InexactExpectedTimeStamp) { | 217 TEST_F(UploadFileElementReaderTest, InexactExpectedTimeStamp) { |
216 base::File::Info info; | 218 base::File::Info info; |
217 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); | 219 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); |
218 | 220 |
219 const base::Time expected_modification_time = | 221 const base::Time expected_modification_time = |
220 info.last_modified - base::TimeDelta::FromMilliseconds(900); | 222 info.last_modified - base::TimeDelta::FromMilliseconds(900); |
221 reader_.reset(new UploadFileElementReader( | 223 reader_.reset(new UploadFileElementReader( |
222 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, kuint64max, | 224 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path_, 0, |
223 expected_modification_time)); | 225 std::numeric_limits<uint64_t>::max(), expected_modification_time)); |
224 TestCompletionCallback init_callback; | 226 TestCompletionCallback init_callback; |
225 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 227 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
226 EXPECT_EQ(OK, init_callback.WaitForResult()); | 228 EXPECT_EQ(OK, init_callback.WaitForResult()); |
227 } | 229 } |
228 | 230 |
229 TEST_F(UploadFileElementReaderTest, WrongPath) { | 231 TEST_F(UploadFileElementReaderTest, WrongPath) { |
230 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); | 232 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); |
231 reader_.reset( | 233 reader_.reset(new UploadFileElementReader( |
232 new UploadFileElementReader(base::ThreadTaskRunnerHandle::Get().get(), | 234 base::ThreadTaskRunnerHandle::Get().get(), wrong_path, 0, |
233 wrong_path, 0, kuint64max, base::Time())); | 235 std::numeric_limits<uint64_t>::max(), base::Time())); |
234 TestCompletionCallback init_callback; | 236 TestCompletionCallback init_callback; |
235 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 237 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
236 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 238 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
237 } | 239 } |
238 | 240 |
239 } // namespace net | 241 } // namespace net |
OLD | NEW |