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

Side by Side Diff: content/child/blob_storage/blob_transport_controller_unittest.cc

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: comments Created 4 years, 1 month 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 "content/child/blob_storage/blob_transport_controller.h" 5 #include "content/child/blob_storage/blob_transport_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 19 matching lines...) Expand all
30 #include "storage/common/blob_storage/blob_item_bytes_request.h" 30 #include "storage/common/blob_storage/blob_item_bytes_request.h"
31 #include "storage/common/blob_storage/blob_item_bytes_response.h" 31 #include "storage/common/blob_storage/blob_item_bytes_response.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 using base::File; 35 using base::File;
36 using base::FilePath; 36 using base::FilePath;
37 using base::TestSimpleTaskRunner; 37 using base::TestSimpleTaskRunner;
38 using storage::BlobItemBytesRequest; 38 using storage::BlobItemBytesRequest;
39 using storage::BlobItemBytesResponse; 39 using storage::BlobItemBytesResponse;
40 using storage::BlobStatus;
40 using storage::DataElement; 41 using storage::DataElement;
41 using storage::IPCBlobCreationCancelCode;
42 42
43 namespace content { 43 namespace content {
44 namespace { 44 namespace {
45 45
46 class OtherThreadTestSimpleTaskRunner : public base::TestSimpleTaskRunner { 46 class OtherThreadTestSimpleTaskRunner : public base::TestSimpleTaskRunner {
47 public: 47 public:
48 bool RunsTasksOnCurrentThread() const override { return false; } 48 bool RunsTasksOnCurrentThread() const override { return false; }
49 49
50 protected: 50 protected:
51 ~OtherThreadTestSimpleTaskRunner() override {} 51 ~OtherThreadTestSimpleTaskRunner() override {}
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 FilePath path; 122 FilePath path;
123 EXPECT_TRUE(base::CreateTemporaryFile(&path)); 123 EXPECT_TRUE(base::CreateTemporaryFile(&path));
124 files_opened_.push_back(path); 124 files_opened_.push_back(path);
125 return path; 125 return path;
126 } 126 }
127 127
128 void ExpectRegisterAndStartMessage(const std::string& expected_uuid, 128 void ExpectRegisterAndStartMessage(const std::string& expected_uuid,
129 const std::string& expected_content_type, 129 const std::string& expected_content_type,
130 std::vector<DataElement>* descriptions) { 130 std::vector<DataElement>* descriptions) {
131 const IPC::Message* register_message = 131 const IPC::Message* register_message =
132 sink_.GetUniqueMessageMatching(BlobStorageMsg_RegisterBlobUUID::ID); 132 sink_.GetUniqueMessageMatching(BlobStorageMsg_RegisterBlob::ID);
133 const IPC::Message* start_message =
134 sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID);
135 ASSERT_TRUE(register_message); 133 ASSERT_TRUE(register_message);
136 ASSERT_TRUE(start_message); 134 std::tuple<std::string, std::string, std::string, std::vector<DataElement>>
137 std::tuple<std::string, std::string, std::string, std::set<std::string>>
138 register_contents; 135 register_contents;
139 std::tuple<std::string, std::vector<DataElement>> start_contents; 136 BlobStorageMsg_RegisterBlob::Read(register_message, &register_contents);
140 BlobStorageMsg_RegisterBlobUUID::Read(register_message, &register_contents);
141 BlobStorageMsg_StartBuildingBlob::Read(start_message, &start_contents);
142 EXPECT_EQ(expected_uuid, std::get<0>(register_contents)); 137 EXPECT_EQ(expected_uuid, std::get<0>(register_contents));
143 EXPECT_EQ(expected_uuid, std::get<0>(start_contents));
144 EXPECT_EQ(expected_content_type, std::get<1>(register_contents)); 138 EXPECT_EQ(expected_content_type, std::get<1>(register_contents));
145 if (descriptions) 139 if (descriptions)
146 *descriptions = std::get<1>(start_contents); 140 *descriptions = std::get<3>(register_contents);
147 // We don't have dispositions from the renderer. 141 // We don't have dispositions from the renderer.
148 EXPECT_TRUE(std::get<2>(register_contents).empty()); 142 EXPECT_TRUE(std::get<2>(register_contents).empty());
149 sink_.ClearMessages(); 143 sink_.ClearMessages();
150 } 144 }
151 145
152 void ExpectMemoryResponses( 146 void ExpectMemoryResponses(
153 const std::string& expected_uuid, 147 const std::string& expected_uuid,
154 std::vector<storage::BlobItemBytesResponse> expected_responses) { 148 std::vector<storage::BlobItemBytesResponse> expected_responses) {
155 const IPC::Message* responses_message = 149 const IPC::Message* responses_message =
156 sink_.GetUniqueMessageMatching(BlobStorageMsg_MemoryItemResponse::ID); 150 sink_.GetUniqueMessageMatching(BlobStorageMsg_MemoryItemResponse::ID);
157 ASSERT_TRUE(responses_message); 151 ASSERT_TRUE(responses_message);
158 std::tuple<std::string, std::vector<storage::BlobItemBytesResponse>> 152 std::tuple<std::string, std::vector<storage::BlobItemBytesResponse>>
159 responses_content; 153 responses_content;
160 BlobStorageMsg_MemoryItemResponse::Read(responses_message, 154 BlobStorageMsg_MemoryItemResponse::Read(responses_message,
161 &responses_content); 155 &responses_content);
162 EXPECT_EQ(expected_uuid, std::get<0>(responses_content)); 156 EXPECT_EQ(expected_uuid, std::get<0>(responses_content));
163 EXPECT_EQ(expected_responses, std::get<1>(responses_content)); 157 EXPECT_EQ(expected_responses, std::get<1>(responses_content));
164 sink_.ClearMessages(); 158 sink_.ClearMessages();
165 } 159 }
166 160
167 void ExpectCancel(const std::string& expected_uuid, 161 void ExpectCancel(const std::string& expected_uuid,
168 storage::IPCBlobCreationCancelCode expected_code) { 162 storage::BlobStatus expected_code) {
169 const IPC::Message* cancel_message = 163 const IPC::Message* cancel_message =
170 sink_.GetUniqueMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID); 164 sink_.GetUniqueMessageMatching(BlobStorageMsg_SendBlobStatus::ID);
171 ASSERT_TRUE(cancel_message); 165 ASSERT_TRUE(cancel_message);
172 std::tuple<std::string, storage::IPCBlobCreationCancelCode> cancel_content; 166 std::tuple<std::string, storage::BlobStatus> cancel_content;
173 BlobStorageMsg_CancelBuildingBlob::Read(cancel_message, &cancel_content); 167 BlobStorageMsg_SendBlobStatus::Read(cancel_message, &cancel_content);
174 EXPECT_EQ(expected_uuid, std::get<0>(cancel_content)); 168 EXPECT_EQ(expected_uuid, std::get<0>(cancel_content));
175 EXPECT_EQ(expected_code, std::get<1>(cancel_content)); 169 EXPECT_EQ(expected_code, std::get<1>(cancel_content));
176 } 170 }
177 171
178 void TearDown() override { 172 void TearDown() override {
179 BlobTransportController::GetInstance()->CancelAllBlobTransfers(); 173 BlobTransportController::GetInstance()->CancelAllBlobTransfers();
180 for (const FilePath& path : files_opened_) { 174 for (const FilePath& path : files_opened_) {
181 EXPECT_TRUE(base::DeleteFile(path, false)); 175 EXPECT_TRUE(base::DeleteFile(path, false));
182 } 176 }
183 EXPECT_FALSE(io_thread_runner_->HasPendingTask()); 177 EXPECT_FALSE(io_thread_runner_->HasPendingTask());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 EXPECT_FALSE(file2.IsValid()); 371 EXPECT_FALSE(file2.IsValid());
378 file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file2))); 372 file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file2)));
379 OnMemoryRequest(holder, kBlobUUID, requests, &memory_handles, file_handles); 373 OnMemoryRequest(holder, kBlobUUID, requests, &memory_handles, file_handles);
380 EXPECT_TRUE(file_thread_runner_->HasPendingTask()); 374 EXPECT_TRUE(file_thread_runner_->HasPendingTask());
381 file_thread_runner_->RunPendingTasks(); 375 file_thread_runner_->RunPendingTasks();
382 EXPECT_TRUE(io_thread_runner_->HasPendingTask()); 376 EXPECT_TRUE(io_thread_runner_->HasPendingTask());
383 io_thread_runner_->RunPendingTasks(); 377 io_thread_runner_->RunPendingTasks();
384 // Clear the main thread task, as it has the AddRef job. 378 // Clear the main thread task, as it has the AddRef job.
385 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); 379 EXPECT_TRUE(main_thread_runner_->HasPendingTask());
386 main_thread_runner_->ClearPendingTasks(); 380 main_thread_runner_->ClearPendingTasks();
387 ExpectCancel(kBlobUUID, IPCBlobCreationCancelCode::FILE_WRITE_FAILED); 381 ExpectCancel(kBlobUUID, BlobStatus::ERR_FILE_WRITE_FAILED);
388 } 382 }
389 383
390 TEST_F(BlobTransportControllerTest, PublicMethods) { 384 TEST_F(BlobTransportControllerTest, PublicMethods) {
391 const std::string kBlobUUID = "uuid"; 385 const std::string kBlobUUID = "uuid";
392 const std::string kBlobContentType = "content_type"; 386 const std::string kBlobContentType = "content_type";
393 const std::string kBlob2UUID = "uuid2"; 387 const std::string kBlob2UUID = "uuid2";
394 const std::string kBlob2ContentType = "content_type2"; 388 const std::string kBlob2ContentType = "content_type2";
395 const std::string KRefBlobUUID = "refuuid"; 389 const std::string KRefBlobUUID = "refuuid";
396 const std::string kDataPart1 = "Hello"; 390 const std::string kDataPart1 = "Hello";
397 const std::string kDataPart2 = "Hello2"; 391 const std::string kDataPart2 = "Hello2";
(...skipping 18 matching lines...) Expand all
416 main_thread_runner_->ClearPendingTasks(); 410 main_thread_runner_->ClearPendingTasks();
417 411
418 // Check that we got the correct start message. 412 // Check that we got the correct start message.
419 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); 413 EXPECT_FALSE(holder->IsTransporting(kBlobUUID));
420 io_thread_runner_->RunPendingTasks(); 414 io_thread_runner_->RunPendingTasks();
421 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); 415 EXPECT_TRUE(holder->IsTransporting(kBlobUUID));
422 std::tuple<std::string, std::vector<DataElement>> message_contents; 416 std::tuple<std::string, std::vector<DataElement>> message_contents;
423 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); 417 EXPECT_TRUE(holder->IsTransporting(kBlobUUID));
424 EXPECT_EQ(MakeBlobElement(KRefBlobUUID, 10, 10), message_descriptions[0]); 418 EXPECT_EQ(MakeBlobElement(KRefBlobUUID, 10, 10), message_descriptions[0]);
425 419
426 holder->OnCancel(kBlobUUID, IPCBlobCreationCancelCode::OUT_OF_MEMORY); 420 holder->OnBlobFinalStatus(kBlobUUID, BlobStatus::ERR_OUT_OF_MEMORY);
427 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); 421 EXPECT_FALSE(holder->IsTransporting(kBlobUUID));
428 // Check we have the 'decrease ref' task. 422 // Check we have the 'decrease ref' task.
429 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); 423 EXPECT_TRUE(main_thread_runner_->HasPendingTask());
430 main_thread_runner_->ClearPendingTasks(); 424 main_thread_runner_->ClearPendingTasks();
431 sink_.ClearMessages(); 425 sink_.ClearMessages();
432 426
433 // Add the second. 427 // Add the second.
434 scoped_refptr<BlobConsolidation> consolidation2 = new BlobConsolidation(); 428 scoped_refptr<BlobConsolidation> consolidation2 = new BlobConsolidation();
435 consolidation2->AddBlobItem(KRefBlobUUID, 10, 10); 429 consolidation2->AddBlobItem(KRefBlobUUID, 10, 10);
436 // These items should be combined. 430 // These items should be combined.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 OnMemoryRequest(holder, kBlob2UUID, requests, &memory_handles, file_handles); 462 OnMemoryRequest(holder, kBlob2UUID, requests, &memory_handles, file_handles);
469 463
470 std::vector<BlobItemBytesResponse> expected_responses; 464 std::vector<BlobItemBytesResponse> expected_responses;
471 BlobItemBytesResponse expected(0); 465 BlobItemBytesResponse expected(0);
472 expected.inline_data = std::vector<char>(kData.begin(), kData.end()); 466 expected.inline_data = std::vector<char>(kData.begin(), kData.end());
473 expected_responses.push_back(expected); 467 expected_responses.push_back(expected);
474 ExpectMemoryResponses(kBlob2UUID, expected_responses); 468 ExpectMemoryResponses(kBlob2UUID, expected_responses);
475 EXPECT_FALSE(main_thread_runner_->HasPendingTask()); 469 EXPECT_FALSE(main_thread_runner_->HasPendingTask());
476 470
477 // Finish the second one. 471 // Finish the second one.
478 holder->OnDone(kBlob2UUID); 472 holder->OnBlobFinalStatus(kBlob2UUID, BlobStatus::DONE);
479 EXPECT_FALSE(holder->IsTransporting(kBlob2UUID)); 473 EXPECT_FALSE(holder->IsTransporting(kBlob2UUID));
480 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); 474 EXPECT_TRUE(main_thread_runner_->HasPendingTask());
481 main_thread_runner_->ClearPendingTasks(); 475 main_thread_runner_->ClearPendingTasks();
482 } 476 }
483 477
484 } // namespace content 478 } // namespace content
OLDNEW
« no previous file with comments | « content/child/blob_storage/blob_transport_controller.cc ('k') | content/child/blob_storage/webblobregistry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698