Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/browser/loader/upload_data_stream_builder_unittest.cc

Issue 2954343005: Merge ResourceRequestBodyImpl and ResourceRequestBody. (Closed)
Patch Set: Remove comment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/loader/upload_data_stream_builder.h" 5 #include "content/browser/loader/upload_data_stream_builder.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "content/common/resource_request_body_impl.h" 19 #include "content/public/common/resource_request_body.h"
20 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
23 #include "net/base/upload_bytes_element_reader.h" 23 #include "net/base/upload_bytes_element_reader.h"
24 #include "net/base/upload_data_stream.h" 24 #include "net/base/upload_data_stream.h"
25 #include "net/base/upload_file_element_reader.h" 25 #include "net/base/upload_file_element_reader.h"
26 #include "net/log/net_log_with_source.h" 26 #include "net/log/net_log_with_source.h"
27 #include "storage/browser/blob/blob_data_builder.h" 27 #include "storage/browser/blob/blob_data_builder.h"
28 #include "storage/browser/blob/blob_data_handle.h" 28 #include "storage/browser/blob/blob_data_handle.h"
29 #include "storage/browser/blob/blob_storage_context.h" 29 #include "storage/browser/blob/blob_storage_context.h"
30 #include "storage/browser/blob/upload_blob_element_reader.h" 30 #include "storage/browser/blob/upload_blob_element_reader.h"
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/gurl.h" 32 #include "url/gurl.h"
33 33
34 using storage::BlobDataBuilder; 34 using storage::BlobDataBuilder;
35 using storage::BlobDataHandle; 35 using storage::BlobDataHandle;
36 using storage::BlobStorageContext; 36 using storage::BlobStorageContext;
37 37
38 namespace content { 38 namespace content {
39 39
40 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) { 40 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) {
41 base::MessageLoop message_loop; 41 base::MessageLoop message_loop;
42 { 42 {
43 scoped_refptr<ResourceRequestBodyImpl> request_body = 43 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
44 new ResourceRequestBodyImpl;
45 44
46 const std::string kBlob = "blobuuid"; 45 const std::string kBlob = "blobuuid";
47 const std::string kBlobData = "blobdata"; 46 const std::string kBlobData = "blobdata";
48 const char kData[] = "123"; 47 const char kData[] = "123";
49 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc"); 48 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc");
50 const uint64_t kFileOffset = 10U; 49 const uint64_t kFileOffset = 10U;
51 const uint64_t kFileLength = 100U; 50 const uint64_t kFileLength = 100U;
52 const base::Time kFileTime = base::Time::FromDoubleT(999); 51 const base::Time kFileTime = base::Time::FromDoubleT(999);
53 const int64_t kIdentifier = 12345; 52 const int64_t kIdentifier = 12345;
54 53
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 BlobStorageContext blob_storage_context; 111 BlobStorageContext blob_storage_context;
113 112
114 // A blob created from an empty file added several times. 113 // A blob created from an empty file added several times.
115 const std::string blob_id("id-0"); 114 const std::string blob_id("id-0");
116 std::unique_ptr<BlobDataBuilder> blob_data_builder( 115 std::unique_ptr<BlobDataBuilder> blob_data_builder(
117 new BlobDataBuilder(blob_id)); 116 new BlobDataBuilder(blob_id));
118 blob_data_builder->AppendFile(test_blob_path, 0, kZeroLength, blob_time); 117 blob_data_builder->AppendFile(test_blob_path, 0, kZeroLength, blob_time);
119 std::unique_ptr<BlobDataHandle> handle = 118 std::unique_ptr<BlobDataHandle> handle =
120 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); 119 blob_storage_context.AddFinishedBlob(blob_data_builder.get());
121 120
122 scoped_refptr<ResourceRequestBodyImpl> request_body( 121 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody());
123 new ResourceRequestBodyImpl());
124 std::unique_ptr<net::UploadDataStream> upload( 122 std::unique_ptr<net::UploadDataStream> upload(
125 UploadDataStreamBuilder::Build( 123 UploadDataStreamBuilder::Build(
126 request_body.get(), &blob_storage_context, NULL, 124 request_body.get(), &blob_storage_context, NULL,
127 base::ThreadTaskRunnerHandle::Get().get())); 125 base::ThreadTaskRunnerHandle::Get().get()));
128 126
129 request_body = new ResourceRequestBodyImpl(); 127 request_body = new ResourceRequestBody();
130 request_body->AppendBlob(blob_id); 128 request_body->AppendBlob(blob_id);
131 request_body->AppendBlob(blob_id); 129 request_body->AppendBlob(blob_id);
132 request_body->AppendBlob(blob_id); 130 request_body->AppendBlob(blob_id);
133 131
134 upload = UploadDataStreamBuilder::Build( 132 upload = UploadDataStreamBuilder::Build(
135 request_body.get(), &blob_storage_context, NULL, 133 request_body.get(), &blob_storage_context, NULL,
136 base::ThreadTaskRunnerHandle::Get().get()); 134 base::ThreadTaskRunnerHandle::Get().get());
137 ASSERT_TRUE(upload->GetElementReaders()); 135 ASSERT_TRUE(upload->GetElementReaders());
138 const auto& readers = *upload->GetElementReaders(); 136 const auto& readers = *upload->GetElementReaders();
139 ASSERT_EQ(3U, readers.size()); 137 ASSERT_EQ(3U, readers.size());
(...skipping 18 matching lines...) Expand all
158 156
159 base::DeleteFile(test_blob_path, false); 157 base::DeleteFile(test_blob_path, false);
160 } 158 }
161 // Clean up for ASAN. 159 // Clean up for ASAN.
162 base::RunLoop().RunUntilIdle(); 160 base::RunLoop().RunUntilIdle();
163 } 161 }
164 162
165 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) { 163 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) {
166 base::MessageLoopForIO message_loop; 164 base::MessageLoopForIO message_loop;
167 { 165 {
168 scoped_refptr<ResourceRequestBodyImpl> request_body = 166 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
169 new ResourceRequestBodyImpl;
170 167
171 const std::string kBlob = "blobuuid"; 168 const std::string kBlob = "blobuuid";
172 const std::string kBlobData = "blobdata"; 169 const std::string kBlobData = "blobdata";
173 const int kBlobDataLength = 8; 170 const int kBlobDataLength = 8;
174 const int64_t kIdentifier = 12345; 171 const int64_t kIdentifier = 12345;
175 172
176 BlobStorageContext blob_storage_context; 173 BlobStorageContext blob_storage_context;
177 BlobDataBuilder builder(kBlob); 174 BlobDataBuilder builder(kBlob);
178 builder.AppendData(kBlobData); 175 builder.AppendData(kBlobData);
179 std::unique_ptr<BlobDataHandle> handle = 176 std::unique_ptr<BlobDataHandle> handle =
(...skipping 30 matching lines...) Expand all
210 result = 207 result =
211 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); 208 upload->Read(buffer.get(), buffer->size(), read_callback.callback());
212 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); 209 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result));
213 EXPECT_EQ(0, 210 EXPECT_EQ(0,
214 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); 211 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size()));
215 } 212 }
216 // Clean up for ASAN. 213 // Clean up for ASAN.
217 base::RunLoop().RunUntilIdle(); 214 base::RunLoop().RunUntilIdle();
218 } 215 }
219 } // namespace content 216 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/upload_data_stream_builder.cc ('k') | content/browser/security_exploit_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698