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

Side by Side Diff: content/browser/blob_storage/blob_async_builder_host_unittest.cc

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "storage/browser/blob/blob_async_builder_host.h" 5 #include "storage/browser/blob/blob_async_builder_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 host_.SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes, 79 host_.SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes,
80 kTestBlobStorageMaxSharedMemoryBytes, 80 kTestBlobStorageMaxSharedMemoryBytes,
81 kTestBlobStorageMaxFileSizeBytes); 81 kTestBlobStorageMaxFileSizeBytes);
82 BlobDataBuilder builder(kCompletedBlobUUID); 82 BlobDataBuilder builder(kCompletedBlobUUID);
83 builder.AppendData(kCompletedBlobData); 83 builder.AppendData(kCompletedBlobData);
84 completed_blob_handle_ = context_.AddFinishedBlob(builder); 84 completed_blob_handle_ = context_.AddFinishedBlob(builder);
85 completed_blob_uuid_set_ = {kCompletedBlobUUID}; 85 completed_blob_uuid_set_ = {kCompletedBlobUUID};
86 } 86 }
87 87
88 void RequestMemoryCallback( 88 void RequestMemoryCallback(
89 scoped_ptr<std::vector<storage::BlobItemBytesRequest>> requests, 89 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests,
90 scoped_ptr<std::vector<base::SharedMemoryHandle>> shared_memory_handles, 90 std::unique_ptr<std::vector<base::SharedMemoryHandle>>
91 scoped_ptr<std::vector<base::File>> files) { 91 shared_memory_handles,
92 std::unique_ptr<std::vector<base::File>> files) {
92 requests_ = std::move(*requests); 93 requests_ = std::move(*requests);
93 memory_handles_ = std::move(*shared_memory_handles); 94 memory_handles_ = std::move(*shared_memory_handles);
94 request_called_ = true; 95 request_called_ = true;
95 } 96 }
96 97
97 BlobTransportResult BuildBlobAsync( 98 BlobTransportResult BuildBlobAsync(
98 const std::vector<DataElement>& descriptions, 99 const std::vector<DataElement>& descriptions,
99 const std::set<std::string>& referenced_blob_uuids, 100 const std::set<std::string>& referenced_blob_uuids,
100 size_t memory_available) { 101 size_t memory_available) {
101 request_called_ = false; 102 request_called_ = false;
(...skipping 20 matching lines...) Expand all
122 content::TestBrowserThreadBundle browser_thread_bundle_; 123 content::TestBrowserThreadBundle browser_thread_bundle_;
123 BlobStorageContext context_; 124 BlobStorageContext context_;
124 BlobAsyncBuilderHost host_; 125 BlobAsyncBuilderHost host_;
125 IPCBlobCreationCancelCode cancel_code_; 126 IPCBlobCreationCancelCode cancel_code_;
126 127
127 bool request_called_; 128 bool request_called_;
128 std::vector<storage::BlobItemBytesRequest> requests_; 129 std::vector<storage::BlobItemBytesRequest> requests_;
129 std::vector<base::SharedMemoryHandle> memory_handles_; 130 std::vector<base::SharedMemoryHandle> memory_handles_;
130 std::set<std::string> completed_blob_uuid_set_; 131 std::set<std::string> completed_blob_uuid_set_;
131 132
132 scoped_ptr<BlobDataHandle> completed_blob_handle_; 133 std::unique_ptr<BlobDataHandle> completed_blob_handle_;
133 }; 134 };
134 135
135 // The 'shortcut' method is when the data is included in the initial IPCs and 136 // The 'shortcut' method is when the data is included in the initial IPCs and
136 // the browser uses that instead of requesting the memory. 137 // the browser uses that instead of requesting the memory.
137 TEST_F(BlobAsyncBuilderHostTest, TestShortcut) { 138 TEST_F(BlobAsyncBuilderHostTest, TestShortcut) {
138 std::vector<DataElement> descriptions; 139 std::vector<DataElement> descriptions;
139 140
140 AddShortcutMemoryItem(10, &descriptions); 141 AddShortcutMemoryItem(10, &descriptions);
141 AddBlobItem(&descriptions); 142 AddBlobItem(&descriptions);
142 AddShortcutMemoryItem(5000, &descriptions); 143 AddShortcutMemoryItem(5000, &descriptions);
143 144
144 BlobDataBuilder expected(kBlobUUID); 145 BlobDataBuilder expected(kBlobUUID);
145 expected.set_content_type(kContentType); 146 expected.set_content_type(kContentType);
146 expected.set_content_disposition(kContentDisposition); 147 expected.set_content_disposition(kContentDisposition);
147 AddShortcutMemoryItem(10, &expected); 148 AddShortcutMemoryItem(10, &expected);
148 expected.AppendData(kCompletedBlobData); 149 expected.AppendData(kCompletedBlobData);
149 AddShortcutMemoryItem(5000, &expected); 150 AddShortcutMemoryItem(5000, &expected);
150 151
151 EXPECT_EQ(BlobTransportResult::DONE, 152 EXPECT_EQ(BlobTransportResult::DONE,
152 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 153 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
153 154
154 EXPECT_FALSE(request_called_); 155 EXPECT_FALSE(request_called_);
155 EXPECT_EQ(0u, host_.blob_building_count()); 156 EXPECT_EQ(0u, host_.blob_building_count());
156 scoped_ptr<BlobDataHandle> handle = context_.GetBlobDataFromUUID(kBlobUUID); 157 std::unique_ptr<BlobDataHandle> handle =
158 context_.GetBlobDataFromUUID(kBlobUUID);
157 EXPECT_FALSE(handle->IsBeingBuilt()); 159 EXPECT_FALSE(handle->IsBeingBuilt());
158 EXPECT_FALSE(handle->IsBroken()); 160 EXPECT_FALSE(handle->IsBroken());
159 scoped_ptr<BlobDataSnapshot> data = handle->CreateSnapshot(); 161 std::unique_ptr<BlobDataSnapshot> data = handle->CreateSnapshot();
160 EXPECT_EQ(expected, *data); 162 EXPECT_EQ(expected, *data);
161 data.reset(); 163 data.reset();
162 handle.reset(); 164 handle.reset();
163 base::RunLoop().RunUntilIdle(); 165 base::RunLoop().RunUntilIdle();
164 }; 166 };
165 167
166 TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) { 168 TEST_F(BlobAsyncBuilderHostTest, TestShortcutNoRoom) {
167 std::vector<DataElement> descriptions; 169 std::vector<DataElement> descriptions;
168 170
169 AddShortcutMemoryItem(10, &descriptions); 171 AddShortcutMemoryItem(10, &descriptions);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 requests_.at(0)); 252 requests_.at(0));
251 253
252 memset(shared_memory.memory(), kSecondBlockByte, 1); 254 memset(shared_memory.memory(), kSecondBlockByte, 1);
253 255
254 response.request_number = 1; 256 response.request_number = 1;
255 responses[0] = response; 257 responses[0] = response;
256 EXPECT_EQ(BlobTransportResult::DONE, 258 EXPECT_EQ(BlobTransportResult::DONE,
257 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 259 host_.OnMemoryResponses(kBlobUUID, responses, &context_));
258 EXPECT_FALSE(request_called_); 260 EXPECT_FALSE(request_called_);
259 EXPECT_EQ(0u, host_.blob_building_count()); 261 EXPECT_EQ(0u, host_.blob_building_count());
260 scoped_ptr<BlobDataHandle> blob_handle = 262 std::unique_ptr<BlobDataHandle> blob_handle =
261 context_.GetBlobDataFromUUID(kBlobUUID); 263 context_.GetBlobDataFromUUID(kBlobUUID);
262 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 264 EXPECT_FALSE(blob_handle->IsBeingBuilt());
263 EXPECT_FALSE(blob_handle->IsBroken()); 265 EXPECT_FALSE(blob_handle->IsBroken());
264 scoped_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot(); 266 std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot();
265 EXPECT_EQ(expected, *blob_data); 267 EXPECT_EQ(expected, *blob_data);
266 }; 268 };
267 269
268 TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) { 270 TEST_F(BlobAsyncBuilderHostTest, TestBasicIPCAndStopBuilding) {
269 std::vector<DataElement> descriptions; 271 std::vector<DataElement> descriptions;
270 272
271 AddMemoryItem(2, &descriptions); 273 AddMemoryItem(2, &descriptions);
272 AddBlobItem(&descriptions); 274 AddBlobItem(&descriptions);
273 AddMemoryItem(2, &descriptions); 275 AddMemoryItem(2, &descriptions);
274 276
275 BlobDataBuilder expected(kBlobUUID); 277 BlobDataBuilder expected(kBlobUUID);
276 expected.set_content_type(kContentType); 278 expected.set_content_type(kContentType);
277 expected.set_content_disposition(kContentDisposition); 279 expected.set_content_disposition(kContentDisposition);
278 AddShortcutMemoryItem(2, &expected); 280 AddShortcutMemoryItem(2, &expected);
279 expected.AppendData(kCompletedBlobData); 281 expected.AppendData(kCompletedBlobData);
280 AddShortcutMemoryItem(2, &expected); 282 AddShortcutMemoryItem(2, &expected);
281 283
282 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 284 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
283 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010)); 285 BuildBlobAsync(descriptions, completed_blob_uuid_set_, 5010));
284 host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN, 286 host_.CancelBuildingBlob(kBlobUUID, IPCBlobCreationCancelCode::UNKNOWN,
285 &context_); 287 &context_);
286 288
287 // Check that we're broken, and then remove the blob. 289 // Check that we're broken, and then remove the blob.
288 scoped_ptr<BlobDataHandle> blob_handle = 290 std::unique_ptr<BlobDataHandle> blob_handle =
289 context_.GetBlobDataFromUUID(kBlobUUID); 291 context_.GetBlobDataFromUUID(kBlobUUID);
290 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 292 EXPECT_FALSE(blob_handle->IsBeingBuilt());
291 EXPECT_TRUE(blob_handle->IsBroken()); 293 EXPECT_TRUE(blob_handle->IsBroken());
292 blob_handle.reset(); 294 blob_handle.reset();
293 DecrementBlobRefCount(kBlobUUID); 295 DecrementBlobRefCount(kBlobUUID);
294 base::RunLoop().RunUntilIdle(); 296 base::RunLoop().RunUntilIdle();
295 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID); 297 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID);
296 EXPECT_FALSE(blob_handle.get()); 298 EXPECT_FALSE(blob_handle.get());
297 299
298 // This should succeed because we've removed all references to the blob. 300 // This should succeed because we've removed all references to the blob.
(...skipping 10 matching lines...) Expand all
309 PopulateBytes(response2.allocate_mutable_data(2), 2); 311 PopulateBytes(response2.allocate_mutable_data(2), 2);
310 std::vector<BlobItemBytesResponse> responses = {response1, response2}; 312 std::vector<BlobItemBytesResponse> responses = {response1, response2};
311 313
312 EXPECT_EQ(BlobTransportResult::DONE, 314 EXPECT_EQ(BlobTransportResult::DONE,
313 host_.OnMemoryResponses(kBlobUUID, responses, &context_)); 315 host_.OnMemoryResponses(kBlobUUID, responses, &context_));
314 EXPECT_FALSE(request_called_); 316 EXPECT_FALSE(request_called_);
315 EXPECT_EQ(0u, host_.blob_building_count()); 317 EXPECT_EQ(0u, host_.blob_building_count());
316 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID); 318 blob_handle = context_.GetBlobDataFromUUID(kBlobUUID);
317 EXPECT_FALSE(blob_handle->IsBeingBuilt()); 319 EXPECT_FALSE(blob_handle->IsBeingBuilt());
318 EXPECT_FALSE(blob_handle->IsBroken()); 320 EXPECT_FALSE(blob_handle->IsBroken());
319 scoped_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot(); 321 std::unique_ptr<BlobDataSnapshot> blob_data = blob_handle->CreateSnapshot();
320 EXPECT_EQ(expected, *blob_data); 322 EXPECT_EQ(expected, *blob_data);
321 }; 323 };
322 324
323 TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) { 325 TEST_F(BlobAsyncBuilderHostTest, TestBreakingAllBuilding) {
324 const std::string& kBlob1 = "blob1"; 326 const std::string& kBlob1 = "blob1";
325 const std::string& kBlob2 = "blob2"; 327 const std::string& kBlob2 = "blob2";
326 const std::string& kBlob3 = "blob3"; 328 const std::string& kBlob3 = "blob3";
327 329
328 // Register blobs. 330 // Register blobs.
329 EXPECT_EQ(BlobTransportResult::DONE, 331 EXPECT_EQ(BlobTransportResult::DONE,
330 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition, 332 host_.RegisterBlobUUID(kBlob1, kContentType, kContentDisposition,
331 std::set<std::string>(), &context_)); 333 std::set<std::string>(), &context_));
332 EXPECT_EQ(BlobTransportResult::DONE, 334 EXPECT_EQ(BlobTransportResult::DONE,
333 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 335 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
334 std::set<std::string>(), &context_)); 336 std::set<std::string>(), &context_));
335 EXPECT_EQ(BlobTransportResult::DONE, 337 EXPECT_EQ(BlobTransportResult::DONE,
336 host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition, 338 host_.RegisterBlobUUID(kBlob3, kContentType, kContentDisposition,
337 std::set<std::string>(), &context_)); 339 std::set<std::string>(), &context_));
338 340
339 // Start building one of them. 341 // Start building one of them.
340 std::vector<DataElement> descriptions; 342 std::vector<DataElement> descriptions;
341 AddMemoryItem(2, &descriptions); 343 AddMemoryItem(2, &descriptions);
342 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES, 344 EXPECT_EQ(BlobTransportResult::PENDING_RESPONSES,
343 host_.StartBuildingBlob( 345 host_.StartBuildingBlob(
344 kBlob1, descriptions, 2, &context_, 346 kBlob1, descriptions, 2, &context_,
345 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback, 347 base::Bind(&BlobAsyncBuilderHostTest::RequestMemoryCallback,
346 base::Unretained(this)))); 348 base::Unretained(this))));
347 EXPECT_TRUE(request_called_); 349 EXPECT_TRUE(request_called_);
348 350
349 scoped_ptr<BlobDataHandle> blob_handle1 = 351 std::unique_ptr<BlobDataHandle> blob_handle1 =
350 context_.GetBlobDataFromUUID(kBlob1); 352 context_.GetBlobDataFromUUID(kBlob1);
351 scoped_ptr<BlobDataHandle> blob_handle2 = 353 std::unique_ptr<BlobDataHandle> blob_handle2 =
352 context_.GetBlobDataFromUUID(kBlob2); 354 context_.GetBlobDataFromUUID(kBlob2);
353 scoped_ptr<BlobDataHandle> blob_handle3 = 355 std::unique_ptr<BlobDataHandle> blob_handle3 =
354 context_.GetBlobDataFromUUID(kBlob2); 356 context_.GetBlobDataFromUUID(kBlob2);
355 EXPECT_TRUE(blob_handle1->IsBeingBuilt() && blob_handle2->IsBeingBuilt() && 357 EXPECT_TRUE(blob_handle1->IsBeingBuilt() && blob_handle2->IsBeingBuilt() &&
356 blob_handle3->IsBeingBuilt()); 358 blob_handle3->IsBeingBuilt());
357 EXPECT_FALSE(blob_handle1->IsBroken() || blob_handle2->IsBroken() || 359 EXPECT_FALSE(blob_handle1->IsBroken() || blob_handle2->IsBroken() ||
358 blob_handle3->IsBroken()); 360 blob_handle3->IsBroken());
359 361
360 host_.CancelAll(&context_); 362 host_.CancelAll(&context_);
361 363
362 EXPECT_FALSE(blob_handle1->IsBeingBuilt() || blob_handle2->IsBeingBuilt() || 364 EXPECT_FALSE(blob_handle1->IsBeingBuilt() || blob_handle2->IsBeingBuilt() ||
363 blob_handle3->IsBeingBuilt()); 365 blob_handle3->IsBeingBuilt());
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 &context_); 608 &context_);
607 EXPECT_EQ(BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN, 609 EXPECT_EQ(BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN,
608 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition, 610 host_.RegisterBlobUUID(kBlob2, kContentType, kContentDisposition,
609 {kBlob1}, &context_)); 611 {kBlob1}, &context_));
610 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2)); 612 EXPECT_FALSE(host_.IsBeingBuilt(kBlob2));
611 EXPECT_FALSE(IsBeingBuiltInContext(kBlob2)); 613 EXPECT_FALSE(IsBeingBuiltInContext(kBlob2));
612 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken()); 614 EXPECT_TRUE(context_.GetBlobDataFromUUID(kBlob2)->IsBroken());
613 }; 615 };
614 616
615 } // namespace storage 617 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698