| 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/file_util.h" | 7 #include "base/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" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class UploadFileElementReaderTest : public PlatformTest { | 19 class UploadFileElementReaderTest : public PlatformTest { |
| 20 protected: | 20 protected: |
| 21 virtual void SetUp() { | 21 virtual void SetUp() { |
| 22 PlatformTest::SetUp(); | 22 PlatformTest::SetUp(); |
| 23 // Some tests (*.ReadPartially) rely on bytes_.size() being even. | 23 // Some tests (*.ReadPartially) rely on bytes_.size() being even. |
| 24 const char kData[] = "123456789abcdefghi"; | 24 const char kData[] = "123456789abcdefghi"; |
| 25 bytes_.assign(kData, kData + arraysize(kData) - 1); | 25 bytes_.assign(kData, kData + arraysize(kData) - 1); |
| 26 | 26 |
| 27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 27 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 28 | 28 |
| 29 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 29 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
| 30 &temp_file_path_)); | 30 &temp_file_path_)); |
| 31 ASSERT_EQ( | 31 ASSERT_EQ( |
| 32 static_cast<int>(bytes_.size()), | 32 static_cast<int>(bytes_.size()), |
| 33 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); | 33 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); |
| 34 | 34 |
| 35 reader_.reset( | 35 reader_.reset( |
| 36 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 36 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 37 temp_file_path_, | 37 temp_file_path_, |
| 38 0, | 38 0, |
| 39 kuint64max, | 39 kuint64max, |
| 40 base::Time())); | 40 base::Time())); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 class UploadFileElementReaderSyncTest : public PlatformTest { | 238 class UploadFileElementReaderSyncTest : public PlatformTest { |
| 239 protected: | 239 protected: |
| 240 virtual void SetUp() OVERRIDE { | 240 virtual void SetUp() OVERRIDE { |
| 241 // Some tests (*.ReadPartially) rely on bytes_.size() being even. | 241 // Some tests (*.ReadPartially) rely on bytes_.size() being even. |
| 242 const char kData[] = "123456789abcdefghi"; | 242 const char kData[] = "123456789abcdefghi"; |
| 243 bytes_.assign(kData, kData + arraysize(kData) - 1); | 243 bytes_.assign(kData, kData + arraysize(kData) - 1); |
| 244 | 244 |
| 245 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 245 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 246 | 246 |
| 247 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 247 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), |
| 248 &temp_file_path_)); | 248 &temp_file_path_)); |
| 249 ASSERT_EQ( | 249 ASSERT_EQ( |
| 250 static_cast<int>(bytes_.size()), | 250 static_cast<int>(bytes_.size()), |
| 251 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); | 251 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); |
| 252 | 252 |
| 253 reader_.reset(new UploadFileElementReaderSync( | 253 reader_.reset(new UploadFileElementReaderSync( |
| 254 temp_file_path_, 0, kuint64max, base::Time())); | 254 temp_file_path_, 0, kuint64max, base::Time())); |
| 255 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); | 255 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); |
| 256 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); | 256 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); |
| 257 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); | 257 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); |
| 258 EXPECT_FALSE(reader_->IsInMemory()); | 258 EXPECT_FALSE(reader_->IsInMemory()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 361 } |
| 362 | 362 |
| 363 TEST_F(UploadFileElementReaderSyncTest, WrongPath) { | 363 TEST_F(UploadFileElementReaderSyncTest, WrongPath) { |
| 364 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); | 364 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); |
| 365 reader_.reset(new UploadFileElementReaderSync( | 365 reader_.reset(new UploadFileElementReaderSync( |
| 366 wrong_path, 0, kuint64max, base::Time())); | 366 wrong_path, 0, kuint64max, base::Time())); |
| 367 ASSERT_EQ(ERR_FILE_NOT_FOUND, reader_->Init(CompletionCallback())); | 367 ASSERT_EQ(ERR_FILE_NOT_FOUND, reader_->Init(CompletionCallback())); |
| 368 } | 368 } |
| 369 | 369 |
| 370 } // namespace net | 370 } // namespace net |
| OLD | NEW |