| 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 "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 EXPECT_EQ(expected, buf); | 203 EXPECT_EQ(expected, buf); |
| 204 } | 204 } |
| 205 | 205 |
| 206 TEST_F(UploadFileElementReaderTest, FileChanged) { | 206 TEST_F(UploadFileElementReaderTest, FileChanged) { |
| 207 base::File::Info info; | 207 base::File::Info info; |
| 208 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); | 208 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); |
| 209 | 209 |
| 210 // Expect one second before the actual modification time to simulate change. | 210 // Expect one second before the actual modification time to simulate change. |
| 211 const base::Time expected_modification_time = | 211 const base::Time expected_modification_time = |
| 212 info.last_modified - base::TimeDelta::FromSeconds(1); | 212 info.last_modified - base::TimeDelta::FromSeconds(1); |
| 213 reader_.reset( | 213 reader_.reset(new UploadFileElementReader( |
| 214 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 214 base::MessageLoopProxy::current().get(), temp_file_path_, 0, kuint64max, |
| 215 temp_file_path_, | 215 expected_modification_time)); |
| 216 0, | |
| 217 kuint64max, | |
| 218 expected_modification_time)); | |
| 219 TestCompletionCallback init_callback; | 216 TestCompletionCallback init_callback; |
| 220 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 217 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 221 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); | 218 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); |
| 222 } | 219 } |
| 223 | 220 |
| 221 TEST_F(UploadFileElementReaderTest, InexactExpectedTimeStamp) { |
| 222 base::File::Info info; |
| 223 ASSERT_TRUE(base::GetFileInfo(temp_file_path_, &info)); |
| 224 |
| 225 const base::Time expected_modification_time = |
| 226 info.last_modified - base::TimeDelta::FromMilliseconds(900); |
| 227 reader_.reset(new UploadFileElementReader( |
| 228 base::MessageLoopProxy::current().get(), temp_file_path_, 0, kuint64max, |
| 229 expected_modification_time)); |
| 230 TestCompletionCallback init_callback; |
| 231 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 232 EXPECT_EQ(OK, init_callback.WaitForResult()); |
| 233 } |
| 234 |
| 224 TEST_F(UploadFileElementReaderTest, WrongPath) { | 235 TEST_F(UploadFileElementReaderTest, WrongPath) { |
| 225 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); | 236 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); |
| 226 reader_.reset( | 237 reader_.reset( |
| 227 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 238 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 228 wrong_path, | 239 wrong_path, 0, kuint64max, base::Time())); |
| 229 0, | |
| 230 kuint64max, | |
| 231 base::Time())); | |
| 232 TestCompletionCallback init_callback; | 240 TestCompletionCallback init_callback; |
| 233 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 241 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
| 234 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 242 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
| 235 } | 243 } |
| 236 | 244 |
| 237 } // namespace net | 245 } // namespace net |
| OLD | NEW |