| 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 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 std::vector<base::SharedMemoryHandle> memory_handles; | 235 std::vector<base::SharedMemoryHandle> memory_handles; |
| 236 std::vector<IPC::PlatformFileForTransit> file_handles; | 236 std::vector<IPC::PlatformFileForTransit> file_handles; |
| 237 std::vector<storage::BlobItemBytesResponse> output; | 237 std::vector<storage::BlobItemBytesResponse> output; |
| 238 | 238 |
| 239 // Request for all data in shared memory | 239 // Request for all data in shared memory |
| 240 requests.push_back( | 240 requests.push_back( |
| 241 BlobItemBytesRequest::CreateSharedMemoryRequest(0, 1, 0, 11, 0, 0)); | 241 BlobItemBytesRequest::CreateSharedMemoryRequest(0, 1, 0, 11, 0, 0)); |
| 242 requests.push_back( | 242 requests.push_back( |
| 243 BlobItemBytesRequest::CreateSharedMemoryRequest(1, 3, 0, 6, 0, 11)); | 243 BlobItemBytesRequest::CreateSharedMemoryRequest(1, 3, 0, 6, 0, 11)); |
| 244 base::SharedMemory memory; | 244 base::SharedMemory memory; |
| 245 memory.CreateAndMapAnonymous(11 + 6); | 245 memory.CreateAnonymous(11 + 6); |
| 246 base::SharedMemoryHandle handle = | 246 base::SharedMemoryHandle handle = |
| 247 base::SharedMemory::DuplicateHandle(memory.handle()); | 247 base::SharedMemory::DuplicateHandle(memory.handle()); |
| 248 CHECK(base::SharedMemory::NULLHandle() != handle); | 248 CHECK(base::SharedMemory::NULLHandle() != handle); |
| 249 memory_handles.push_back(handle); | 249 memory_handles.push_back(handle); |
| 250 | 250 |
| 251 EXPECT_EQ(ResponsesStatus::SUCCESS, | 251 EXPECT_EQ(ResponsesStatus::SUCCESS, |
| 252 holder->GetResponses(kBlobUUID, requests, &memory_handles, | 252 holder->GetResponses(kBlobUUID, requests, &memory_handles, |
| 253 file_handles, &output)); | 253 file_handles, &output)); |
| 254 EXPECT_EQ(2u, output.size()); | 254 EXPECT_EQ(2u, output.size()); |
| 255 std::vector<storage::BlobItemBytesResponse> expected; | 255 std::vector<storage::BlobItemBytesResponse> expected; |
| 256 expected.push_back(BlobItemBytesResponse(0)); | 256 expected.push_back(BlobItemBytesResponse(0)); |
| 257 expected.push_back(BlobItemBytesResponse(1)); | 257 expected.push_back(BlobItemBytesResponse(1)); |
| 258 EXPECT_EQ(expected, output); | 258 EXPECT_EQ(expected, output); |
| 259 std::string expected_memory = "HelloHello2Hello3"; | 259 std::string expected_memory = "HelloHello2Hello3"; |
| 260 memory.Map(11 + 6); |
| 260 const char* mem_location = static_cast<const char*>(memory.memory()); | 261 const char* mem_location = static_cast<const char*>(memory.memory()); |
| 261 std::vector<char> value(mem_location, mem_location + memory.requested_size()); | 262 std::vector<char> value(mem_location, mem_location + memory.requested_size()); |
| 262 EXPECT_THAT(value, testing::ElementsAreArray(expected_memory.c_str(), | 263 EXPECT_THAT(value, testing::ElementsAreArray(expected_memory.c_str(), |
| 263 expected_memory.size())); | 264 expected_memory.size())); |
| 264 } | 265 } |
| 265 | 266 |
| 266 TEST_F(BlobTransportControllerTest, TestPublicMethods) { | 267 TEST_F(BlobTransportControllerTest, TestPublicMethods) { |
| 267 const std::string kBlobUUID = "uuid"; | 268 const std::string kBlobUUID = "uuid"; |
| 268 const std::string kBlobContentType = "content_type"; | 269 const std::string kBlobContentType = "content_type"; |
| 269 const std::string kBlob2UUID = "uuid2"; | 270 const std::string kBlob2UUID = "uuid2"; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 std::vector<storage::BlobItemBytesResponse> output; | 340 std::vector<storage::BlobItemBytesResponse> output; |
| 340 | 341 |
| 341 // Error conditions | 342 // Error conditions |
| 342 EXPECT_EQ(ResponsesStatus::BLOB_NOT_FOUND, | 343 EXPECT_EQ(ResponsesStatus::BLOB_NOT_FOUND, |
| 343 holder->GetResponses(kBadBlobUUID, requests, &memory_handles, | 344 holder->GetResponses(kBadBlobUUID, requests, &memory_handles, |
| 344 file_handles, &output)); | 345 file_handles, &output)); |
| 345 EXPECT_EQ(0u, output.size()); | 346 EXPECT_EQ(0u, output.size()); |
| 346 } | 347 } |
| 347 | 348 |
| 348 } // namespace content | 349 } // namespace content |
| OLD | NEW |