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 "storage/browser/blob/blob_memory_controller.h" | 5 #include "storage/browser/blob/blob_memory_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 EXPECT_EQ(0u, controller.memory_usage()); | 211 EXPECT_EQ(0u, controller.memory_usage()); |
212 } | 212 } |
213 | 213 |
214 TEST_F(BlobMemoryControllerTest, PageToDisk) { | 214 TEST_F(BlobMemoryControllerTest, PageToDisk) { |
215 const std::string kId = "id"; | 215 const std::string kId = "id"; |
216 const std::string kId2 = "id2"; | 216 const std::string kId2 = "id2"; |
217 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); | 217 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); |
218 SetTestMemoryLimits(&controller); | 218 SetTestMemoryLimits(&controller); |
219 | 219 |
220 char kData[kTestBlobStorageMaxBlobMemorySize]; | 220 char kData[kTestBlobStorageMaxBlobMemorySize]; |
221 std::memset(kData, kTestBlobStorageMaxBlobMemorySize, 'e'); | 221 std::memset(kData, 'e', kTestBlobStorageMaxBlobMemorySize); |
222 | 222 |
223 // Add memory item that is the memory quota. | 223 // Add memory item that is the memory quota. |
224 BlobDataBuilder builder(kId); | 224 BlobDataBuilder builder(kId); |
225 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); | 225 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); |
226 | 226 |
227 std::vector<scoped_refptr<ShareableBlobDataItem>> items = | 227 std::vector<scoped_refptr<ShareableBlobDataItem>> items = |
228 CreateSharedDataItems(builder); | 228 CreateSharedDataItems(builder); |
229 | 229 |
230 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); | 230 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); |
231 EXPECT_TRUE(memory_quota_result_); | 231 EXPECT_TRUE(memory_quota_result_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 EXPECT_FALSE(controller.CanReserveQuota(kTestBlobStorageMaxDiskSpace + 1)); | 299 EXPECT_FALSE(controller.CanReserveQuota(kTestBlobStorageMaxDiskSpace + 1)); |
300 } | 300 } |
301 | 301 |
302 TEST_F(BlobMemoryControllerTest, CancelMemoryRequest) { | 302 TEST_F(BlobMemoryControllerTest, CancelMemoryRequest) { |
303 const std::string kId = "id"; | 303 const std::string kId = "id"; |
304 const std::string kId2 = "id2"; | 304 const std::string kId2 = "id2"; |
305 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); | 305 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); |
306 SetTestMemoryLimits(&controller); | 306 SetTestMemoryLimits(&controller); |
307 | 307 |
308 char kData[kTestBlobStorageMaxBlobMemorySize]; | 308 char kData[kTestBlobStorageMaxBlobMemorySize]; |
309 std::memset(kData, kTestBlobStorageMaxBlobMemorySize, 'e'); | 309 std::memset(kData, 'e', kTestBlobStorageMaxBlobMemorySize); |
310 | 310 |
311 // Add memory item that is the memory quota. | 311 // Add memory item that is the memory quota. |
312 BlobDataBuilder builder(kId); | 312 BlobDataBuilder builder(kId); |
313 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); | 313 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); |
314 | 314 |
315 std::vector<scoped_refptr<ShareableBlobDataItem>> items = | 315 std::vector<scoped_refptr<ShareableBlobDataItem>> items = |
316 CreateSharedDataItems(builder); | 316 CreateSharedDataItems(builder); |
317 | 317 |
318 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); | 318 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); |
319 | 319 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 359 } |
360 | 360 |
361 TEST_F(BlobMemoryControllerTest, FileRequest) { | 361 TEST_F(BlobMemoryControllerTest, FileRequest) { |
362 const std::string kId = "id"; | 362 const std::string kId = "id"; |
363 const size_t kBlobSize = kTestBlobStorageMaxBlobMemorySize + 1; | 363 const size_t kBlobSize = kTestBlobStorageMaxBlobMemorySize + 1; |
364 | 364 |
365 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); | 365 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); |
366 SetTestMemoryLimits(&controller); | 366 SetTestMemoryLimits(&controller); |
367 | 367 |
368 char kData[kBlobSize]; | 368 char kData[kBlobSize]; |
369 std::memset(kData, kBlobSize, 'e'); | 369 std::memset(kData, 'e', kBlobSize); |
370 | 370 |
371 // Add item that is the file quota. | 371 // Add item that is the file quota. |
372 BlobDataBuilder builder(kId); | 372 BlobDataBuilder builder(kId); |
373 builder.AppendFutureFile(0, kBlobSize, 0); | 373 builder.AppendFutureFile(0, kBlobSize, 0); |
374 | 374 |
375 std::vector<scoped_refptr<ShareableBlobDataItem>> items = | 375 std::vector<scoped_refptr<ShareableBlobDataItem>> items = |
376 CreateSharedDataItems(builder); | 376 CreateSharedDataItems(builder); |
377 | 377 |
378 file_quota_result_ = false; | 378 file_quota_result_ = false; |
379 base::WeakPtr<QuotaAllocationTask> task = | 379 base::WeakPtr<QuotaAllocationTask> task = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 | 417 |
418 TEST_F(BlobMemoryControllerTest, CancelFileRequest) { | 418 TEST_F(BlobMemoryControllerTest, CancelFileRequest) { |
419 const std::string kId = "id"; | 419 const std::string kId = "id"; |
420 const size_t kBlobSize = kTestBlobStorageMaxBlobMemorySize + 1; | 420 const size_t kBlobSize = kTestBlobStorageMaxBlobMemorySize + 1; |
421 | 421 |
422 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); | 422 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); |
423 SetTestMemoryLimits(&controller); | 423 SetTestMemoryLimits(&controller); |
424 | 424 |
425 char kData[kBlobSize]; | 425 char kData[kBlobSize]; |
426 std::memset(kData, kBlobSize, 'e'); | 426 std::memset(kData, 'e', kBlobSize); |
427 | 427 |
428 // Add memory item that is the memory quota. | 428 // Add memory item that is the memory quota. |
429 BlobDataBuilder builder(kId); | 429 BlobDataBuilder builder(kId); |
430 builder.AppendFutureFile(0, kBlobSize, 0); | 430 builder.AppendFutureFile(0, kBlobSize, 0); |
431 | 431 |
432 std::vector<scoped_refptr<ShareableBlobDataItem>> items = | 432 std::vector<scoped_refptr<ShareableBlobDataItem>> items = |
433 CreateSharedDataItems(builder); | 433 CreateSharedDataItems(builder); |
434 | 434 |
435 base::WeakPtr<QuotaAllocationTask> task = | 435 base::WeakPtr<QuotaAllocationTask> task = |
436 controller.ReserveFileQuota(items, GetFileCreationCallback()); | 436 controller.ReserveFileQuota(items, GetFileCreationCallback()); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 const uint64_t kFirstMemorySize = kTestBlobStorageMaxBlobMemorySize; | 600 const uint64_t kFirstMemorySize = kTestBlobStorageMaxBlobMemorySize; |
601 const std::string kSecondMemoryId = "id2"; | 601 const std::string kSecondMemoryId = "id2"; |
602 const uint64_t kSecondMemorySize = 1; | 602 const uint64_t kSecondMemorySize = 1; |
603 const std::string kFileId = "id2"; | 603 const std::string kFileId = "id2"; |
604 const uint64_t kFileBlobSize = kTestBlobStorageMaxBlobMemorySize; | 604 const uint64_t kFileBlobSize = kTestBlobStorageMaxBlobMemorySize; |
605 | 605 |
606 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); | 606 BlobMemoryController controller(temp_dir_.GetPath(), file_runner_); |
607 SetTestMemoryLimits(&controller); | 607 SetTestMemoryLimits(&controller); |
608 | 608 |
609 char kDataMemoryData[kFirstMemorySize]; | 609 char kDataMemoryData[kFirstMemorySize]; |
610 std::memset(kDataMemoryData, kFirstMemorySize, 'e'); | 610 std::memset(kDataMemoryData, 'e', kFirstMemorySize); |
611 | 611 |
612 // Add first memory item to fill up some memory quota. | 612 // Add first memory item to fill up some memory quota. |
613 BlobDataBuilder builder(kFirstMemoryId); | 613 BlobDataBuilder builder(kFirstMemoryId); |
614 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); | 614 builder.AppendFutureData(kTestBlobStorageMaxBlobMemorySize); |
615 | 615 |
616 std::vector<scoped_refptr<ShareableBlobDataItem>> items = | 616 std::vector<scoped_refptr<ShareableBlobDataItem>> items = |
617 CreateSharedDataItems(builder); | 617 CreateSharedDataItems(builder); |
618 | 618 |
619 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); | 619 controller.ReserveMemoryQuota(items, GetMemoryRequestCallback()); |
620 | 620 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 file_items.clear(); | 672 file_items.clear(); |
673 items.clear(); | 673 items.clear(); |
674 | 674 |
675 RunFileThreadTasks(); | 675 RunFileThreadTasks(); |
676 base::RunLoop().RunUntilIdle(); | 676 base::RunLoop().RunUntilIdle(); |
677 | 677 |
678 EXPECT_EQ(0ull, controller.disk_usage()); | 678 EXPECT_EQ(0ull, controller.disk_usage()); |
679 EXPECT_EQ(0ull, controller.memory_usage()); | 679 EXPECT_EQ(0ull, controller.memory_usage()); |
680 } | 680 } |
681 } // namespace storage | 681 } // namespace storage |
OLD | NEW |