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(new UploadFileElementReader( | 213 reader_.reset( |
214 base::MessageLoopProxy::current().get(), temp_file_path_, 0, kuint64max, | 214 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
215 expected_modification_time)); | 215 temp_file_path_, |
| 216 0, |
| 217 kuint64max, |
| 218 expected_modification_time)); |
216 TestCompletionCallback init_callback; | 219 TestCompletionCallback init_callback; |
217 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 220 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
218 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); | 221 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); |
219 } | 222 } |
220 | 223 |
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 | |
235 TEST_F(UploadFileElementReaderTest, WrongPath) { | 224 TEST_F(UploadFileElementReaderTest, WrongPath) { |
236 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); | 225 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); |
237 reader_.reset( | 226 reader_.reset( |
238 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 227 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
239 wrong_path, 0, kuint64max, base::Time())); | 228 wrong_path, |
| 229 0, |
| 230 kuint64max, |
| 231 base::Time())); |
240 TestCompletionCallback init_callback; | 232 TestCompletionCallback init_callback; |
241 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); | 233 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); |
242 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); | 234 EXPECT_EQ(ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); |
243 } | 235 } |
244 | 236 |
245 } // namespace net | 237 } // namespace net |
OLD | NEW |