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

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

Issue 2038813003: Making ResourceRequestBody part of //content's public API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing... Created 4 years, 6 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/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/common/resource_request_body.h" 18 #include "content/common/resource_request_body_impl.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 #include "net/base/test_completion_callback.h" 21 #include "net/base/test_completion_callback.h"
22 #include "net/base/upload_bytes_element_reader.h" 22 #include "net/base/upload_bytes_element_reader.h"
23 #include "net/base/upload_data_stream.h" 23 #include "net/base/upload_data_stream.h"
24 #include "net/base/upload_file_element_reader.h" 24 #include "net/base/upload_file_element_reader.h"
25 #include "storage/browser/blob/blob_data_builder.h" 25 #include "storage/browser/blob/blob_data_builder.h"
26 #include "storage/browser/blob/blob_data_handle.h" 26 #include "storage/browser/blob/blob_data_handle.h"
27 #include "storage/browser/blob/blob_storage_context.h" 27 #include "storage/browser/blob/blob_storage_context.h"
28 #include "storage/browser/blob/upload_blob_element_reader.h" 28 #include "storage/browser/blob/upload_blob_element_reader.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 #include "url/gurl.h" 30 #include "url/gurl.h"
31 31
32 using storage::BlobDataBuilder; 32 using storage::BlobDataBuilder;
33 using storage::BlobDataHandle; 33 using storage::BlobDataHandle;
34 using storage::BlobStorageContext; 34 using storage::BlobStorageContext;
35 35
36 namespace content { 36 namespace content {
37 37
38 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) { 38 TEST(UploadDataStreamBuilderTest, CreateUploadDataStream) {
39 base::MessageLoop message_loop; 39 base::MessageLoop message_loop;
40 { 40 {
41 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; 41 scoped_refptr<ResourceRequestBodyImpl> request_body =
42 new ResourceRequestBodyImpl;
42 43
43 const std::string kBlob = "blobuuid"; 44 const std::string kBlob = "blobuuid";
44 const std::string kBlobData = "blobdata"; 45 const std::string kBlobData = "blobdata";
45 const char kData[] = "123"; 46 const char kData[] = "123";
46 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc"); 47 const base::FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc");
47 const uint64_t kFileOffset = 10U; 48 const uint64_t kFileOffset = 10U;
48 const uint64_t kFileLength = 100U; 49 const uint64_t kFileLength = 100U;
49 const base::Time kFileTime = base::Time::FromDoubleT(999); 50 const base::Time kFileTime = base::Time::FromDoubleT(999);
50 const int64_t kIdentifier = 12345; 51 const int64_t kIdentifier = 12345;
51 52
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 BlobStorageContext blob_storage_context; 109 BlobStorageContext blob_storage_context;
109 110
110 // A blob created from an empty file added several times. 111 // A blob created from an empty file added several times.
111 const std::string blob_id("id-0"); 112 const std::string blob_id("id-0");
112 std::unique_ptr<BlobDataBuilder> blob_data_builder( 113 std::unique_ptr<BlobDataBuilder> blob_data_builder(
113 new BlobDataBuilder(blob_id)); 114 new BlobDataBuilder(blob_id));
114 blob_data_builder->AppendFile(test_blob_path, 0, kZeroLength, blob_time); 115 blob_data_builder->AppendFile(test_blob_path, 0, kZeroLength, blob_time);
115 std::unique_ptr<BlobDataHandle> handle = 116 std::unique_ptr<BlobDataHandle> handle =
116 blob_storage_context.AddFinishedBlob(blob_data_builder.get()); 117 blob_storage_context.AddFinishedBlob(blob_data_builder.get());
117 118
118 scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody()); 119 scoped_refptr<ResourceRequestBodyImpl> request_body(
120 new ResourceRequestBodyImpl());
119 std::unique_ptr<net::UploadDataStream> upload( 121 std::unique_ptr<net::UploadDataStream> upload(
120 UploadDataStreamBuilder::Build( 122 UploadDataStreamBuilder::Build(
121 request_body.get(), &blob_storage_context, NULL, 123 request_body.get(), &blob_storage_context, NULL,
122 base::ThreadTaskRunnerHandle::Get().get())); 124 base::ThreadTaskRunnerHandle::Get().get()));
123 125
124 request_body = new ResourceRequestBody(); 126 request_body = new ResourceRequestBodyImpl();
125 request_body->AppendBlob(blob_id); 127 request_body->AppendBlob(blob_id);
126 request_body->AppendBlob(blob_id); 128 request_body->AppendBlob(blob_id);
127 request_body->AppendBlob(blob_id); 129 request_body->AppendBlob(blob_id);
128 130
129 upload = UploadDataStreamBuilder::Build( 131 upload = UploadDataStreamBuilder::Build(
130 request_body.get(), &blob_storage_context, NULL, 132 request_body.get(), &blob_storage_context, NULL,
131 base::ThreadTaskRunnerHandle::Get().get()); 133 base::ThreadTaskRunnerHandle::Get().get());
132 ASSERT_TRUE(upload->GetElementReaders()); 134 ASSERT_TRUE(upload->GetElementReaders());
133 const auto& readers = *upload->GetElementReaders(); 135 const auto& readers = *upload->GetElementReaders();
134 ASSERT_EQ(3U, readers.size()); 136 ASSERT_EQ(3U, readers.size());
(...skipping 17 matching lines...) Expand all
152 154
153 base::DeleteFile(test_blob_path, false); 155 base::DeleteFile(test_blob_path, false);
154 } 156 }
155 // Clean up for ASAN. 157 // Clean up for ASAN.
156 base::RunLoop().RunUntilIdle(); 158 base::RunLoop().RunUntilIdle();
157 } 159 }
158 160
159 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) { 161 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) {
160 base::MessageLoopForIO message_loop; 162 base::MessageLoopForIO message_loop;
161 { 163 {
162 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; 164 scoped_refptr<ResourceRequestBodyImpl> request_body =
165 new ResourceRequestBodyImpl;
163 166
164 const std::string kBlob = "blobuuid"; 167 const std::string kBlob = "blobuuid";
165 const std::string kBlobData = "blobdata"; 168 const std::string kBlobData = "blobdata";
166 const int kBlobDataLength = 8; 169 const int kBlobDataLength = 8;
167 const int64_t kIdentifier = 12345; 170 const int64_t kIdentifier = 12345;
168 171
169 BlobStorageContext blob_storage_context; 172 BlobStorageContext blob_storage_context;
170 BlobDataBuilder builder(kBlob); 173 BlobDataBuilder builder(kBlob);
171 builder.AppendData(kBlobData); 174 builder.AppendData(kBlobData);
172 std::unique_ptr<BlobDataHandle> handle = 175 std::unique_ptr<BlobDataHandle> handle =
(...skipping 28 matching lines...) Expand all
201 result = 204 result =
202 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); 205 upload->Read(buffer.get(), buffer->size(), read_callback.callback());
203 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); 206 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result));
204 EXPECT_EQ(0, 207 EXPECT_EQ(0,
205 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); 208 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size()));
206 } 209 }
207 // Clean up for ASAN. 210 // Clean up for ASAN.
208 base::RunLoop().RunUntilIdle(); 211 base::RunLoop().RunUntilIdle();
209 } 212 }
210 } // namespace content 213 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/upload_data_stream_builder.cc ('k') | content/browser/service_worker/foreign_fetch_request_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698