OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/glue/resource_request_body.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/time.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/upload_data.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace webkit_glue { |
| 15 |
| 16 TEST(ResourceRequestBodyTest, CreateUploadDataTest) { |
| 17 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; |
| 18 |
| 19 const char kData[] = "123"; |
| 20 const FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc"); |
| 21 const uint64 kFileOffset = 10U; |
| 22 const uint64 kFileLength = 100U; |
| 23 const base::Time kFileTime = base::Time::FromDoubleT(999); |
| 24 const int64 kIdentifier = 12345; |
| 25 |
| 26 request_body->AppendBytes(kData, arraysize(kData) - 1); |
| 27 request_body->AppendFileRange(FilePath(kFilePath), |
| 28 kFileOffset, kFileLength, kFileTime); |
| 29 request_body->set_identifier(kIdentifier); |
| 30 |
| 31 scoped_refptr<net::UploadData> upload = request_body->CreateUploadData(); |
| 32 |
| 33 EXPECT_EQ(kIdentifier, upload->identifier()); |
| 34 ASSERT_EQ(request_body->elements()->size(), upload->elements()->size()); |
| 35 |
| 36 const net::UploadData::Element& e1 = upload->elements()->at(0); |
| 37 EXPECT_EQ(net::UploadData::TYPE_BYTES, e1.type()); |
| 38 EXPECT_EQ(kData, std::string(e1.bytes(), e1.bytes_length())); |
| 39 |
| 40 const net::UploadData::Element& e2 = upload->elements()->at(1); |
| 41 EXPECT_EQ(net::UploadData::TYPE_FILE, e2.type()); |
| 42 EXPECT_EQ(kFilePath, e2.file_path().value()); |
| 43 EXPECT_EQ(kFileOffset, e2.file_range_offset()); |
| 44 EXPECT_EQ(kFileLength, e2.file_range_length()); |
| 45 EXPECT_EQ(kFileTime, e2.expected_file_modification_time()); |
| 46 } |
| 47 |
| 48 } // namespace webkit_glue |
OLD | NEW |