| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/blob_storage/blob_dispatcher_host.h" | 5 #include "content/browser/blob_storage/blob_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; | 52 const uint64_t kTestBlobStorageMaxFileSizeBytes = 100; |
| 53 | 53 |
| 54 void ConstructionCompletePopulator(bool* succeeded_pointer, | 54 void ConstructionCompletePopulator(bool* succeeded_pointer, |
| 55 IPCBlobCreationCancelCode* reason_pointer, | 55 IPCBlobCreationCancelCode* reason_pointer, |
| 56 bool succeeded, | 56 bool succeeded, |
| 57 IPCBlobCreationCancelCode reason) { | 57 IPCBlobCreationCancelCode reason) { |
| 58 *succeeded_pointer = succeeded; | 58 *succeeded_pointer = succeeded; |
| 59 *reason_pointer = reason; | 59 *reason_pointer = reason; |
| 60 } | 60 } |
| 61 | 61 |
| 62 // TODO(dmurph): Create file test that verifies security policy. |
| 62 class TestableBlobDispatcherHost : public BlobDispatcherHost { | 63 class TestableBlobDispatcherHost : public BlobDispatcherHost { |
| 63 public: | 64 public: |
| 64 TestableBlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context, | 65 TestableBlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context, |
| 65 IPC::TestSink* sink) | 66 IPC::TestSink* sink) |
| 66 : BlobDispatcherHost(blob_storage_context), sink_(sink) { | 67 : BlobDispatcherHost( |
| 68 0 /* process_id */, blob_storage_context), sink_(sink) { |
| 67 this->SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes, | 69 this->SetMemoryConstantsForTesting(kTestBlobStorageIPCThresholdBytes, |
| 68 kTestBlobStorageMaxSharedMemoryBytes, | 70 kTestBlobStorageMaxSharedMemoryBytes, |
| 69 kTestBlobStorageMaxFileSizeBytes); | 71 kTestBlobStorageMaxFileSizeBytes); |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool Send(IPC::Message* message) override { return sink_->Send(message); } | 74 bool Send(IPC::Message* message) override { return sink_->Send(message); } |
| 73 | 75 |
| 74 void ShutdownForBadMessage() override { shutdown_for_bad_message_ = true; } | 76 void ShutdownForBadMessage() override { shutdown_for_bad_message_ = true; } |
| 75 | 77 |
| 76 bool shutdown_for_bad_message_ = false; | 78 bool shutdown_for_bad_message_ = false; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 281 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 280 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 282 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 281 EXPECT_TRUE(handle); | 283 EXPECT_TRUE(handle); |
| 282 | 284 |
| 283 DataElement expected; | 285 DataElement expected; |
| 284 expected.SetToBytes(kData, kDataSize); | 286 expected.SetToBytes(kData, kDataSize); |
| 285 std::vector<DataElement> elements = {expected}; | 287 std::vector<DataElement> elements = {expected}; |
| 286 ExpectHandleEqualsData(handle.get(), elements); | 288 ExpectHandleEqualsData(handle.get(), elements); |
| 287 } | 289 } |
| 288 | 290 |
| 291 |
| 292 TEST_F(BlobDispatcherHostTest, File) { |
| 293 const std::string kId = "uuid1"; |
| 294 sink_.ClearMessages(); |
| 295 host_->OnRegisterBlobUUID(id, std::string(kContentType), |
| 296 std::string(kContentDisposition), |
| 297 std::set<std::string>()); |
| 298 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 299 DataElement element; |
| 300 element.SetToFile() |
| 301 std::vector<DataElement> elements = {element}; |
| 302 host_->OnStartBuildingBlob(id, elements); |
| 303 EXPECT_FALSE(host_->shutdown_for_bad_message_); |
| 304 ExpectDone(id); |
| 305 sink_.ClearMessages(); |
| 306 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 307 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 308 EXPECT_TRUE(handle); |
| 309 |
| 310 DataElement expected; |
| 311 expected.SetToBytes(kData, kDataSize); |
| 312 std::vector<DataElement> elements = {expected}; |
| 313 ExpectHandleEqualsData(handle.get(), elements); |
| 314 } |
| 315 |
| 316 |
| 289 TEST_F(BlobDispatcherHostTest, RegularTransfer) { | 317 TEST_F(BlobDispatcherHostTest, RegularTransfer) { |
| 290 const std::string kId = "uuid1"; | 318 const std::string kId = "uuid1"; |
| 291 AsyncBlobTransfer(kId); | 319 AsyncBlobTransfer(kId); |
| 292 EXPECT_TRUE(context_->registry().HasEntry(kId)); | 320 EXPECT_TRUE(context_->registry().HasEntry(kId)); |
| 293 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); | 321 std::unique_ptr<BlobDataHandle> handle = context_->GetBlobDataFromUUID(kId); |
| 294 EXPECT_TRUE(handle); | 322 EXPECT_TRUE(handle); |
| 295 | 323 |
| 296 DataElement expected; | 324 DataElement expected; |
| 297 expected.SetToBytes(kData, kDataSize); | 325 expected.SetToBytes(kData, kDataSize); |
| 298 std::vector<DataElement> elements = {expected}; | 326 std::vector<DataElement> elements = {expected}; |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1220 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, |
| 1193 same_host_error_code); | 1221 same_host_error_code); |
| 1194 EXPECT_FALSE(other_host_built); | 1222 EXPECT_FALSE(other_host_built); |
| 1195 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, | 1223 EXPECT_EQ(IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT, |
| 1196 other_host_error_code); | 1224 other_host_error_code); |
| 1197 | 1225 |
| 1198 sink_.ClearMessages(); | 1226 sink_.ClearMessages(); |
| 1199 } | 1227 } |
| 1200 | 1228 |
| 1201 } // namespace content | 1229 } // namespace content |
| OLD | NEW |