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

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: Added back transport controller test, small cleanups Created 4 years, 6 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..5c1c138c6400d95f97f719653a0f5ccfed5fbecf
--- /dev/null
+++ b/content/browser/blob_storage/blob_memory_controller_unittest.cc
@@ -0,0 +1,97 @@
+// Copyright 2015 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/test/test_simple_task_runner.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "base/test/test_simple_task_runner.h"
+#include "base/threading/thread_task_runner_handle.h"
+
+namespace storage {
+namespace {
+
+using FileCreationInfo = BlobMemoryController::FileCreationInfo;
+using base::TestSimpleTaskRunner;
+
+const std::string kBlobStorageDirectory = "blob_storage";
+const size_t kTestBlobStorageMaxBlobMemorySize = 400;
+const size_t kTestBlobStorageMaxMemoryUsage = 500;
+const uint64_t kTestBlobStorageMaxDiskSpace = 1000;
+const size_t kTestBlobStorageInFlightMemory = 10;
+const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
+
+// 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() : thread_runner_handle_(io_runner_) {}
+
+ void SetUp() override {
+ ASSERT_EQ(true, base::CreateNewTempDirectory("blob_storage", &temp_dir_));
+ };
+
+ void TearDown() override {
+ files_created_.clear();
+ io_runner_->RunPendingTasks();
+ ASSERT_EQ(true, base::DeleteFile(temp_dir_, true));
+ }
+
+ void SetTestMemoryLimits(BlobMemoryController* controller) {
+ controller->SetMemoryLimits(
+ kTestBlobStorageMaxBlobMemorySize, kTestBlobStorageMaxMemoryUsage,
+ kTestBlobStorageMaxDiskSpace, kTestBlobStorageInFlightMemory,
+ kTestBlobStorageMinFileSizeBytes);
+ }
+
+ void SaveFileCreationInfo(FileCreationInfo info) {
+ files_created_.push_back(std::move(info));
+ }
+
+ base::Callback<void(FileCreationInfo info)> GetFileCreationCallback() {
+ return base::Bind(&BlobMemoryControllerTest::SaveFileCreationInfo,
+ base::Unretained(this));
+ }
+
+ base::FilePath temp_dir_;
+ std::vector<FileCreationInfo> files_created_;
+
+ scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner();
+ scoped_refptr<base::TestSimpleTaskRunner> io_runner_ =
+ new TestSimpleTaskRunner();
+
+ // We set this to the IO thread runner, as this is used for the
+ // OnMemoryRequest calls, which are on that thread.
+ base::ThreadTaskRunnerHandle thread_runner_handle_;
+};
+
+TEST_F(BlobMemoryControllerTest, TestBasicTempFiles) {
+ BlobMemoryController controller;
+ SetTestMemoryLimits(&controller);
+
+ // Check we can't create files.
+ controller.CreateTemporaryFileForRenderer(10ull, GetFileCreationCallback());
+
+ // Check that we can
+ controller.EnableDisk(temp_dir_, file_runner_);
+ controller.CreateTemporaryFileForRenderer(10, GetFileCreationCallback());
+ EXPECT_TRUE(file_runner_->HasPendingTask());
+ file_runner_->RunPendingTasks();
+ EXPECT_TRUE(io_runner_->HasPendingTask());
+ io_runner_->RunPendingTasks();
+
+ LOG(ERROR) << files_created_[1].error;
+}
+
+} // namespace
+} // namespace storage

Powered by Google App Engine
This is Rietveld 408576698