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

Unified Diff: content/browser/blob_storage/blob_memory_controller_unittest.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined BlobSlice & BlobFlattener files, more comments, a little cleanup. Created 4 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/blob_storage/blob_memory_controller_unittest.cc
diff --git a/content/browser/blob_storage/blob_memory_controller_unittest.cc b/content/browser/blob_storage/blob_memory_controller_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..deb6f43ad3b639a250385c5d8cd192b8c6700693
--- /dev/null
+++ b/content/browser/blob_storage/blob_memory_controller_unittest.cc
@@ -0,0 +1,143 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "storage/browser/blob/blob_memory_controller.h"
+
+#include "base/bind.h"
+#include "base/files/file_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/test/test_simple_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "storage/common/data_element.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace storage {
+namespace {
+
+using MemoryStrategyResult = BlobMemoryController::MemoryStrategyResult;
+using FileCreationInfo = BlobMemoryController::FileCreationInfo;
+using base::TestSimpleTaskRunner;
+
+const std::string kBlobStorageDirectory = "blob_storage";
+const size_t kTestBlobStorageIPCThresholdBytes = 20;
+const size_t kTestBlobStorageMaxSharedMemoryBytes = 50;
+const size_t kTestBlobStorageMaxBlobMemorySize = 400;
+const uint64_t kTestBlobStorageMaxDiskSpace = 1000;
+const size_t kTestBlobStorageInFlightMemory = 10;
+const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
+const uint64_t kTestBlobStorageMaxFileSizeBytes = 100;
+
+// void SetFileCreationInfo(BlobMemoryController::FileCreationInfo* output,
+// const BlobMemoryController::FileCreationInfo& in) {
+// *output = in;
+//}
+//
+// void SetPointer(bool* out, bool success) {
+// *out = success;
+//}
+
+class BlobMemoryControllerTest : public testing::Test {
+ protected:
+ BlobMemoryControllerTest() {}
+
+ void SetUp() override {
+ ASSERT_EQ(true, base::CreateNewTempDirectory("blob_storage", &temp_dir_));
+ };
+
+ void TearDown() override {
+ files_created_.clear();
+ // Make sure we clean up the files.
+ base::RunLoop().RunUntilIdle();
+ file_runner_->RunPendingTasks();
+ base::RunLoop().RunUntilIdle();
+ ASSERT_EQ(true, base::DeleteFile(temp_dir_, true));
+ }
+
+ void SetTestMemoryLimits(BlobMemoryController* controller) {
+ controller->SetMemoryConstantsForTesting(
+ kTestBlobStorageIPCThresholdBytes, kTestBlobStorageMaxSharedMemoryBytes,
+ kTestBlobStorageMaxBlobMemorySize, kTestBlobStorageMaxDiskSpace,
+ kTestBlobStorageInFlightMemory, kTestBlobStorageMinFileSizeBytes,
+ kTestBlobStorageMaxFileSizeBytes);
+ }
+
+ void SaveFileCreationInfo(bool success, std::vector<FileCreationInfo> info) {
+ EXPECT_EQ(quota_expected_result_, success);
+ if (success)
+ files_created_.swap(info);
+ }
+
+ base::Callback<void(bool, std::vector<FileCreationInfo>)>
+ GetFileCreationCallback() {
+ return base::Bind(&BlobMemoryControllerTest::SaveFileCreationInfo,
+ base::Unretained(this));
+ }
+
+ bool quota_expected_result_ = true;
+ base::FilePath temp_dir_;
+ std::vector<FileCreationInfo> files_created_;
+
+ scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner();
+
+ base::MessageLoop fake_io_message_loop_;
+};
+
+TEST_F(BlobMemoryControllerTest, Strategy) {
+ BlobMemoryController controller;
+ SetTestMemoryLimits(&controller);
+
+ // No transportation needed.
+ EXPECT_EQ(MemoryStrategyResult::NONE_NEEDED,
+ controller.DecideBlobTransportationMemoryStrategy(0, 0));
+
+ // IPC.
+ EXPECT_EQ(MemoryStrategyResult::IPC,
+ controller.DecideBlobTransportationMemoryStrategy(
+ 0, kTestBlobStorageIPCThresholdBytes));
+
+ // Shared Memory.
+ EXPECT_EQ(MemoryStrategyResult::SHARED_MEMORY,
+ controller.DecideBlobTransportationMemoryStrategy(
+ kTestBlobStorageIPCThresholdBytes,
+ kTestBlobStorageMaxSharedMemoryBytes));
+
+ // Not too large, as disk isn't enabled.
+ EXPECT_EQ(MemoryStrategyResult::SHARED_MEMORY,
+ controller.DecideBlobTransportationMemoryStrategy(
+ 0, kTestBlobStorageMaxBlobMemorySize +
+ kTestBlobStorageInFlightMemory));
+
+ // Too large.
+ EXPECT_EQ(MemoryStrategyResult::TOO_LARGE,
+ controller.DecideBlobTransportationMemoryStrategy(
+ 0, kTestBlobStorageMaxBlobMemorySize +
+ kTestBlobStorageInFlightMemory + 1));
+
+ // Enable disk, and check file strategies.
+ controller.EnableDisk(temp_dir_, file_runner_);
+ EXPECT_EQ(MemoryStrategyResult::FILE,
+ controller.DecideBlobTransportationMemoryStrategy(
+ 0, kTestBlobStorageMaxBlobMemorySize + 1));
+
+ // Too large for disk.
+ controller.EnableDisk(temp_dir_, file_runner_);
+ EXPECT_EQ(MemoryStrategyResult::TOO_LARGE,
+ controller.DecideBlobTransportationMemoryStrategy(
+ 0, kTestBlobStorageMaxDiskSpace + 1));
+}
+
+// TODO(dmurph):
+// * Write test for memory request when quota is available.
+// * Write test for memory request that fails because disk isn't enabled.
+// * Write test for memory request when quota isn't available and we're waiting
+// on disk paging.
+// * Same as above but then we cancel it.
+// * Write test for memory request that's pending, and then disk is disabled.
+// * Write test for file request where we have quota.
+// * Write test for file request where we don't have quota (and just fail).
+// * Write test for file request and then we disable disk.
+
+} // namespace
+} // namespace storage

Powered by Google App Engine
This is Rietveld 408576698