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

Side by Side Diff: webkit/quota/quota_temporary_storage_evictor_unittest.cc

Issue 7002024: Implement QuotaTemporaryStorageEvictor. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Extracted. Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h"
6
7 #include <set>
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_temp_dir.h"
13 #include "base/message_loop.h"
14 #include "base/message_loop_proxy.h"
15 #include "webkit/quota/mock_storage_client.h"
16 #include "webkit/quota/quota_manager.h"
17 #include "webkit/quota/quota_temporary_storage_evictor.h"
18
19 namespace quota {
20
21 namespace {
22
23 // TODO(dmikurube): Add an interface between QuotaManager and Evictor.
24 // Do not use mock, and implement the interface here.
25 class MockQuotaManager : public quota::QuotaEvictionHandler {
26 public:
27 MockQuotaManager(const FilePath& profile_path, int64 usage, int64 quota)
28 : test_profile_path_(profile_path),
29 usage_(usage),
30 quota_(quota) {}
31
32 virtual void DeleteOriginData(
33 const GURL& origin,
34 StorageType type,
35 DeleteOriginDataCallback* callback) {
36 LOG(ERROR) << "MockQM::DeleteOriginData";
37 callback->Run(quota::kQuotaStatusOk, 3000, 100000, 1000000000);
38 delete callback;
39 }
40
41 virtual void GetUsageAndQuotaForEviction(
42 DeleteOriginDataCallback* callback) {
43 LOG(ERROR) << "MockQM::GetUsageAndQuotaForEviction";
44 callback->Run(quota::kQuotaStatusOk, 3000, 100000, 1000000000);
45 delete callback;
46 }
47
48 virtual void GetLRUOrigin(
49 StorageType type,
50 GetLRUOriginCallback* callback) {
51 callback->Run(GURL("http://www.example.com"));
52 }
53
54 void set_usage(int64 usage) { usage_ = usage; }
55 void set_quota(int64 quota) { quota_ = quota; }
56
57 private:
58 FilePath test_profile_path_;
59 int64 usage_;
60 int64 quota_;
61 };
62
63 } // anonymous namespace
64
65 class QuotaTemporaryStorageEvictorTest : public testing::Test {
66 public:
67 QuotaTemporaryStorageEvictorTest() {}
68
69 void SetUp() {
70 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
71
72 quota_manager_.reset(new MockQuotaManager(data_dir_.path(), 0, 1000));
73
74 temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor(
75 10000000, 3000, base::MessageLoopProxy::CreateForCurrentThread());
76
77 temporary_storage_evictor_->RegisterQuotaManagerOnIOThread(
78 quota_manager_.get());
79
80 additional_callback_count_ = 0;
81 }
82
83 void TearDown() {
84 temporary_storage_evictor_ = NULL;
85 quota_manager_.reset(NULL);
86 MessageLoop::current()->RunAllPending();
87 }
88
89 protected:
90 /*
91 MockStorageClient* CreateClient(
92 const MockOriginData* mock_data, size_t mock_data_size) {
93 MockStorageClient* client = new MockStorageClient(quota_manager_->proxy());
94 for (size_t i = 0; i < mock_data_size; ++i) {
95 client->AddMockOriginData(GURL(mock_data[i].origin),
96 mock_data[i].type,
97 mock_data[i].usage);
98 }
99 return client;
100 }
101 */
102
103 void StartEviction() {
104 temporary_storage_evictor_->Start();
105 }
106
107 MockQuotaManager* quota_manager() const {
108 return static_cast<MockQuotaManager*>(quota_manager_.get());
109 }
110
111 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const {
112 return temporary_storage_evictor_.get();
113 }
114
115 private:
116 ScopedTempDir data_dir_;
117
118 scoped_ptr<QuotaEvictionHandler> quota_manager_;
119 scoped_refptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_;
120
121 QuotaStatusCode quota_status_;
122 std::string host_;
123 int64 usage_;
124 int64 quota_;
125
126 int additional_callback_count_;
127
128 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest);
129 };
130
131 TEST_F(QuotaTemporaryStorageEvictorTest, Simple) {
132 StartEviction();
133 MessageLoop::current()->RunAllPending();
134 }
135
136 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698