| OLD | NEW |
| 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 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 15 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
| 18 #include "base/test/test_file_util.h" | 19 #include "base/test/test_file_util.h" |
| 19 #include "base/test/test_simple_task_runner.h" | 20 #include "base/test/test_simple_task_runner.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/tuple.h" | |
| 22 #include "content/child/blob_storage/blob_consolidation.h" | 22 #include "content/child/blob_storage/blob_consolidation.h" |
| 23 #include "content/child/thread_safe_sender.h" | 23 #include "content/child/thread_safe_sender.h" |
| 24 #include "content/common/fileapi/webblob_messages.h" | 24 #include "content/common/fileapi/webblob_messages.h" |
| 25 #include "ipc/ipc_message.h" | 25 #include "ipc/ipc_message.h" |
| 26 #include "ipc/ipc_platform_file.h" | 26 #include "ipc/ipc_platform_file.h" |
| 27 #include "ipc/ipc_sender.h" | 27 #include "ipc/ipc_sender.h" |
| 28 #include "ipc/ipc_sync_message_filter.h" | 28 #include "ipc/ipc_sync_message_filter.h" |
| 29 #include "ipc/ipc_test_sink.h" | 29 #include "ipc/ipc_test_sink.h" |
| 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" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_RegisterBlobUUID::ID); |
| 133 const IPC::Message* start_message = | 133 const IPC::Message* start_message = |
| 134 sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID); | 134 sink_.GetUniqueMessageMatching(BlobStorageMsg_StartBuildingBlob::ID); |
| 135 ASSERT_TRUE(register_message); | 135 ASSERT_TRUE(register_message); |
| 136 ASSERT_TRUE(start_message); | 136 ASSERT_TRUE(start_message); |
| 137 base::Tuple<std::string, std::string, std::string, std::set<std::string>> | 137 std::tuple<std::string, std::string, std::string, std::set<std::string>> |
| 138 register_contents; | 138 register_contents; |
| 139 base::Tuple<std::string, std::vector<DataElement>> start_contents; | 139 std::tuple<std::string, std::vector<DataElement>> start_contents; |
| 140 BlobStorageMsg_RegisterBlobUUID::Read(register_message, ®ister_contents); | 140 BlobStorageMsg_RegisterBlobUUID::Read(register_message, ®ister_contents); |
| 141 BlobStorageMsg_StartBuildingBlob::Read(start_message, &start_contents); | 141 BlobStorageMsg_StartBuildingBlob::Read(start_message, &start_contents); |
| 142 EXPECT_EQ(expected_uuid, base::get<0>(register_contents)); | 142 EXPECT_EQ(expected_uuid, std::get<0>(register_contents)); |
| 143 EXPECT_EQ(expected_uuid, base::get<0>(start_contents)); | 143 EXPECT_EQ(expected_uuid, std::get<0>(start_contents)); |
| 144 EXPECT_EQ(expected_content_type, base::get<1>(register_contents)); | 144 EXPECT_EQ(expected_content_type, std::get<1>(register_contents)); |
| 145 if (descriptions) | 145 if (descriptions) |
| 146 *descriptions = base::get<1>(start_contents); | 146 *descriptions = std::get<1>(start_contents); |
| 147 // We don't have dispositions from the renderer. | 147 // We don't have dispositions from the renderer. |
| 148 EXPECT_TRUE(base::get<2>(register_contents).empty()); | 148 EXPECT_TRUE(std::get<2>(register_contents).empty()); |
| 149 sink_.ClearMessages(); | 149 sink_.ClearMessages(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void ExpectMemoryResponses( | 152 void ExpectMemoryResponses( |
| 153 const std::string& expected_uuid, | 153 const std::string& expected_uuid, |
| 154 std::vector<storage::BlobItemBytesResponse> expected_responses) { | 154 std::vector<storage::BlobItemBytesResponse> expected_responses) { |
| 155 const IPC::Message* responses_message = | 155 const IPC::Message* responses_message = |
| 156 sink_.GetUniqueMessageMatching(BlobStorageMsg_MemoryItemResponse::ID); | 156 sink_.GetUniqueMessageMatching(BlobStorageMsg_MemoryItemResponse::ID); |
| 157 ASSERT_TRUE(responses_message); | 157 ASSERT_TRUE(responses_message); |
| 158 base::Tuple<std::string, std::vector<storage::BlobItemBytesResponse>> | 158 std::tuple<std::string, std::vector<storage::BlobItemBytesResponse>> |
| 159 responses_content; | 159 responses_content; |
| 160 BlobStorageMsg_MemoryItemResponse::Read(responses_message, | 160 BlobStorageMsg_MemoryItemResponse::Read(responses_message, |
| 161 &responses_content); | 161 &responses_content); |
| 162 EXPECT_EQ(expected_uuid, base::get<0>(responses_content)); | 162 EXPECT_EQ(expected_uuid, std::get<0>(responses_content)); |
| 163 EXPECT_EQ(expected_responses, base::get<1>(responses_content)); | 163 EXPECT_EQ(expected_responses, std::get<1>(responses_content)); |
| 164 sink_.ClearMessages(); | 164 sink_.ClearMessages(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ExpectCancel(const std::string& expected_uuid, | 167 void ExpectCancel(const std::string& expected_uuid, |
| 168 storage::IPCBlobCreationCancelCode expected_code) { | 168 storage::IPCBlobCreationCancelCode expected_code) { |
| 169 const IPC::Message* cancel_message = | 169 const IPC::Message* cancel_message = |
| 170 sink_.GetUniqueMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID); | 170 sink_.GetUniqueMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID); |
| 171 ASSERT_TRUE(cancel_message); | 171 ASSERT_TRUE(cancel_message); |
| 172 base::Tuple<std::string, storage::IPCBlobCreationCancelCode> cancel_content; | 172 std::tuple<std::string, storage::IPCBlobCreationCancelCode> cancel_content; |
| 173 BlobStorageMsg_CancelBuildingBlob::Read(cancel_message, &cancel_content); | 173 BlobStorageMsg_CancelBuildingBlob::Read(cancel_message, &cancel_content); |
| 174 EXPECT_EQ(expected_uuid, base::get<0>(cancel_content)); | 174 EXPECT_EQ(expected_uuid, std::get<0>(cancel_content)); |
| 175 EXPECT_EQ(expected_code, base::get<1>(cancel_content)); | 175 EXPECT_EQ(expected_code, std::get<1>(cancel_content)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void TearDown() override { | 178 void TearDown() override { |
| 179 BlobTransportController::GetInstance()->CancelAllBlobTransfers(); | 179 BlobTransportController::GetInstance()->CancelAllBlobTransfers(); |
| 180 for (const FilePath& path : files_opened_) { | 180 for (const FilePath& path : files_opened_) { |
| 181 EXPECT_TRUE(base::DeleteFile(path, false)); | 181 EXPECT_TRUE(base::DeleteFile(path, false)); |
| 182 } | 182 } |
| 183 EXPECT_FALSE(io_thread_runner_->HasPendingTask()); | 183 EXPECT_FALSE(io_thread_runner_->HasPendingTask()); |
| 184 EXPECT_FALSE(file_thread_runner_->HasPendingTask()); | 184 EXPECT_FALSE(file_thread_runner_->HasPendingTask()); |
| 185 EXPECT_FALSE(main_thread_runner_->HasPendingTask()); | 185 EXPECT_FALSE(main_thread_runner_->HasPendingTask()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 EXPECT_TRUE(io_thread_runner_->HasPendingTask()); | 411 EXPECT_TRUE(io_thread_runner_->HasPendingTask()); |
| 412 // Check that we've sent the data. | 412 // Check that we've sent the data. |
| 413 ExpectRegisterAndStartMessage(kBlobUUID, kBlobContentType, | 413 ExpectRegisterAndStartMessage(kBlobUUID, kBlobContentType, |
| 414 &message_descriptions); | 414 &message_descriptions); |
| 415 main_thread_runner_->ClearPendingTasks(); | 415 main_thread_runner_->ClearPendingTasks(); |
| 416 | 416 |
| 417 // Check that we got the correct start message. | 417 // Check that we got the correct start message. |
| 418 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); | 418 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); |
| 419 io_thread_runner_->RunPendingTasks(); | 419 io_thread_runner_->RunPendingTasks(); |
| 420 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); | 420 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); |
| 421 base::Tuple<std::string, std::vector<DataElement>> message_contents; | 421 std::tuple<std::string, std::vector<DataElement>> message_contents; |
| 422 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); | 422 EXPECT_TRUE(holder->IsTransporting(kBlobUUID)); |
| 423 EXPECT_EQ(MakeBlobElement(KRefBlobUUID, 10, 10), message_descriptions[0]); | 423 EXPECT_EQ(MakeBlobElement(KRefBlobUUID, 10, 10), message_descriptions[0]); |
| 424 | 424 |
| 425 holder->OnCancel(kBlobUUID, IPCBlobCreationCancelCode::OUT_OF_MEMORY); | 425 holder->OnCancel(kBlobUUID, IPCBlobCreationCancelCode::OUT_OF_MEMORY); |
| 426 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); | 426 EXPECT_FALSE(holder->IsTransporting(kBlobUUID)); |
| 427 // Check we have the 'decrease ref' task. | 427 // Check we have the 'decrease ref' task. |
| 428 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); | 428 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); |
| 429 main_thread_runner_->ClearPendingTasks(); | 429 main_thread_runner_->ClearPendingTasks(); |
| 430 sink_.ClearMessages(); | 430 sink_.ClearMessages(); |
| 431 | 431 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 EXPECT_FALSE(main_thread_runner_->HasPendingTask()); | 474 EXPECT_FALSE(main_thread_runner_->HasPendingTask()); |
| 475 | 475 |
| 476 // Finish the second one. | 476 // Finish the second one. |
| 477 holder->OnDone(kBlob2UUID); | 477 holder->OnDone(kBlob2UUID); |
| 478 EXPECT_FALSE(holder->IsTransporting(kBlob2UUID)); | 478 EXPECT_FALSE(holder->IsTransporting(kBlob2UUID)); |
| 479 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); | 479 EXPECT_TRUE(main_thread_runner_->HasPendingTask()); |
| 480 main_thread_runner_->ClearPendingTasks(); | 480 main_thread_runner_->ClearPendingTasks(); |
| 481 } | 481 } |
| 482 | 482 |
| 483 } // namespace content | 483 } // namespace content |
| OLD | NEW |