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/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 class UploadFileElementReaderTest : public PlatformTest { | 17 class UploadFileElementReaderTest : public PlatformTest { |
18 protected: | 18 protected: |
(...skipping 13 matching lines...) Expand all Loading... |
32 reader_.reset(new UploadFileElementReader( | 32 reader_.reset(new UploadFileElementReader( |
33 temp_file_path_, 0, kuint64max, base::Time())); | 33 temp_file_path_, 0, kuint64max, base::Time())); |
34 ASSERT_EQ(OK, reader_->InitSync()); | 34 ASSERT_EQ(OK, reader_->InitSync()); |
35 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); | 35 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); |
36 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); | 36 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); |
37 EXPECT_FALSE(reader_->IsInMemory()); | 37 EXPECT_FALSE(reader_->IsInMemory()); |
38 } | 38 } |
39 | 39 |
40 std::vector<char> bytes_; | 40 std::vector<char> bytes_; |
41 scoped_ptr<UploadElementReader> reader_; | 41 scoped_ptr<UploadElementReader> reader_; |
42 ScopedTempDir temp_dir_; | 42 base::ScopedTempDir temp_dir_; |
43 FilePath temp_file_path_; | 43 FilePath temp_file_path_; |
44 }; | 44 }; |
45 | 45 |
46 TEST_F(UploadFileElementReaderTest, ReadPartially) { | 46 TEST_F(UploadFileElementReaderTest, ReadPartially) { |
47 const size_t kHalfSize = bytes_.size() / 2; | 47 const size_t kHalfSize = bytes_.size() / 2; |
48 ASSERT_EQ(bytes_.size(), kHalfSize * 2); | 48 ASSERT_EQ(bytes_.size(), kHalfSize * 2); |
49 std::vector<char> buf(kHalfSize); | 49 std::vector<char> buf(kHalfSize); |
50 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); | 50 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); |
51 EXPECT_EQ(static_cast<int>(buf.size()), | 51 EXPECT_EQ(static_cast<int>(buf.size()), |
52 reader_->ReadSync(wrapped_buffer, buf.size())); | 52 reader_->ReadSync(wrapped_buffer, buf.size())); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 TEST_F(UploadFileElementReaderTest, WrongPath) { | 251 TEST_F(UploadFileElementReaderTest, WrongPath) { |
252 const FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); | 252 const FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); |
253 reader_.reset(new UploadFileElementReader( | 253 reader_.reset(new UploadFileElementReader( |
254 wrong_path, 0, kuint64max, base::Time())); | 254 wrong_path, 0, kuint64max, base::Time())); |
255 ASSERT_EQ(OK, reader_->InitSync()); | 255 ASSERT_EQ(OK, reader_->InitSync()); |
256 EXPECT_EQ(0U, reader_->GetContentLength()); | 256 EXPECT_EQ(0U, reader_->GetContentLength()); |
257 EXPECT_EQ(0U, reader_->BytesRemaining()); | 257 EXPECT_EQ(0U, reader_->BytesRemaining()); |
258 } | 258 } |
259 | 259 |
260 } // namespace net | 260 } // namespace net |
OLD | NEW |