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

Side by Side 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: fixes, working w/ Layout tests 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "storage/browser/blob/blob_memory_controller.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/test/test_simple_task_runner.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "base/test/test_simple_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h"
13
14 namespace storage {
15 namespace {
16
17 using FileCreationInfo = BlobMemoryController::FileCreationInfo;
18 using base::TestSimpleTaskRunner;
19
20 const std::string kBlobStorageDirectory = "blob_storage";
21 const size_t kTestBlobStorageMaxBlobMemorySize = 400;
22 const size_t kTestBlobStorageMaxMemoryUsage = 500;
23 const uint64_t kTestBlobStorageMaxDiskSpace = 1000;
24 const size_t kTestBlobStorageInFlightMemory = 10;
25 const uint64_t kTestBlobStorageMinFileSizeBytes = 10;
26
27 // void SetFileCreationInfo(BlobMemoryController::FileCreationInfo* output,
28 // const BlobMemoryController::FileCreationInfo& in) {
29 // *output = in;
30 //}
31 //
32 // void SetPointer(bool* out, bool success) {
33 // *out = success;
34 //}
35
36 class BlobMemoryControllerTest : public testing::Test {
37 protected:
38 BlobMemoryControllerTest() : thread_runner_handle_(io_runner_) {}
39
40 void SetUp() override {
41 ASSERT_EQ(true, base::CreateNewTempDirectory("blob_storage", &temp_dir_));
42 };
43
44 void TearDown() override {
45 files_created_.clear();
46 io_runner_->RunPendingTasks();
47 ASSERT_EQ(true, base::DeleteFile(temp_dir_, true));
48 }
49
50 void SetTestMemoryLimits(BlobMemoryController* controller) {
51 controller->SetMemoryLimits(
52 kTestBlobStorageMaxBlobMemorySize, kTestBlobStorageMaxMemoryUsage,
53 kTestBlobStorageMaxDiskSpace, kTestBlobStorageInFlightMemory,
54 kTestBlobStorageMinFileSizeBytes);
55 }
56
57 void SaveFileCreationInfo(const FileCreationInfo& info) {
58 files_created_.push_back(info);
59 }
60
61 base::Callback<void(const FileCreationInfo& info)> GetFileCreationCallback() {
62 return base::Bind(&BlobMemoryControllerTest::SaveFileCreationInfo,
63 base::Unretained(this));
64 }
65
66 base::FilePath temp_dir_;
67 std::vector<FileCreationInfo> files_created_;
68
69 scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner();
70 scoped_refptr<base::TestSimpleTaskRunner> io_runner_ =
71 new TestSimpleTaskRunner();
72
73 // We set this to the IO thread runner, as this is used for the
74 // OnMemoryRequest calls, which are on that thread.
75 base::ThreadTaskRunnerHandle thread_runner_handle_;
76 };
77
78 TEST_F(BlobMemoryControllerTest, TestBasicTempFiles) {
79 BlobMemoryController controller;
80 SetTestMemoryLimits(&controller);
81
82 // Check we can't create files.
83 controller.CreateTemporaryFileForRenderer(10ull, GetFileCreationCallback());
84
85 // Check that we can
86 controller.EnableDisk(temp_dir_, file_runner_);
87 controller.CreateTemporaryFileForRenderer(10, GetFileCreationCallback());
88 EXPECT_TRUE(file_runner_->HasPendingTask());
89 file_runner_->RunPendingTasks();
90 EXPECT_TRUE(io_runner_->HasPendingTask());
91 io_runner_->RunPendingTasks();
92
93 LOG(ERROR) << files_created_[1].error;
94 }
95
96 } // namespace
97 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698