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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_quota_helper_unittest.cc

Issue 492873002: Collapse fileapi, webkit_blob, webkit_database, quota, and webkit_common namespaces into single sto… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos build Created 6 years, 3 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 16 matching lines...) Expand all
27 27
28 BrowsingDataQuotaHelperTest() 28 BrowsingDataQuotaHelperTest()
29 : fetching_completed_(true), 29 : fetching_completed_(true),
30 quota_(-1), 30 quota_(-1),
31 weak_factory_(this) {} 31 weak_factory_(this) {}
32 32
33 virtual ~BrowsingDataQuotaHelperTest() {} 33 virtual ~BrowsingDataQuotaHelperTest() {}
34 34
35 virtual void SetUp() OVERRIDE { 35 virtual void SetUp() OVERRIDE {
36 EXPECT_TRUE(dir_.CreateUniqueTempDir()); 36 EXPECT_TRUE(dir_.CreateUniqueTempDir());
37 quota_manager_ = new quota::QuotaManager( 37 quota_manager_ = new storage::QuotaManager(
38 false, 38 false,
39 dir_.path(), 39 dir_.path(),
40 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), 40 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
41 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), 41 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(),
42 NULL); 42 NULL);
43 helper_ = new BrowsingDataQuotaHelperImpl( 43 helper_ = new BrowsingDataQuotaHelperImpl(
44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(), 44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI).get(),
45 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), 45 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(),
46 quota_manager_.get()); 46 quota_manager_.get());
47 } 47 }
(...skipping 16 matching lines...) Expand all
64 64
65 void StartFetching() { 65 void StartFetching() {
66 fetching_completed_ = false; 66 fetching_completed_ = false;
67 helper_->StartFetching( 67 helper_->StartFetching(
68 base::Bind(&BrowsingDataQuotaHelperTest::FetchCompleted, 68 base::Bind(&BrowsingDataQuotaHelperTest::FetchCompleted,
69 weak_factory_.GetWeakPtr())); 69 weak_factory_.GetWeakPtr()));
70 } 70 }
71 71
72 void RegisterClient(const MockOriginData* data, std::size_t data_len) { 72 void RegisterClient(const MockOriginData* data, std::size_t data_len) {
73 MockStorageClient* client = 73 MockStorageClient* client =
74 new MockStorageClient( 74 new MockStorageClient(quota_manager_->proxy(),
75 quota_manager_->proxy(), data, quota::QuotaClient::kFileSystem, 75 data,
76 data_len); 76 storage::QuotaClient::kFileSystem,
77 data_len);
77 quota_manager_->proxy()->RegisterClient(client); 78 quota_manager_->proxy()->RegisterClient(client);
78 client->TouchAllOriginsAndNotify(); 79 client->TouchAllOriginsAndNotify();
79 } 80 }
80 81
81 void SetPersistentHostQuota(const std::string& host, int64 quota) { 82 void SetPersistentHostQuota(const std::string& host, int64 quota) {
82 quota_ = -1; 83 quota_ = -1;
83 quota_manager_->SetPersistentHostQuota( 84 quota_manager_->SetPersistentHostQuota(
84 host, quota, 85 host, quota,
85 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota, 86 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota,
86 weak_factory_.GetWeakPtr())); 87 weak_factory_.GetWeakPtr()));
87 } 88 }
88 89
89 void GetPersistentHostQuota(const std::string& host) { 90 void GetPersistentHostQuota(const std::string& host) {
90 quota_ = -1; 91 quota_ = -1;
91 quota_manager_->GetPersistentHostQuota( 92 quota_manager_->GetPersistentHostQuota(
92 host, 93 host,
93 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota, 94 base::Bind(&BrowsingDataQuotaHelperTest::GotPersistentHostQuota,
94 weak_factory_.GetWeakPtr())); 95 weak_factory_.GetWeakPtr()));
95 } 96 }
96 97
97 void GotPersistentHostQuota(quota::QuotaStatusCode status, 98 void GotPersistentHostQuota(storage::QuotaStatusCode status, int64 quota) {
98 int64 quota) { 99 EXPECT_EQ(storage::kQuotaStatusOk, status);
99 EXPECT_EQ(quota::kQuotaStatusOk, status);
100 quota_ = quota; 100 quota_ = quota;
101 } 101 }
102 102
103 void RevokeHostQuota(const std::string& host) { 103 void RevokeHostQuota(const std::string& host) {
104 helper_->RevokeHostQuota(host); 104 helper_->RevokeHostQuota(host);
105 } 105 }
106 106
107 int64 quota() { 107 int64 quota() {
108 return quota_; 108 return quota_;
109 } 109 }
110 110
111 private: 111 private:
112 void FetchCompleted(const QuotaInfoArray& quota_info) { 112 void FetchCompleted(const QuotaInfoArray& quota_info) {
113 quota_info_ = quota_info; 113 quota_info_ = quota_info;
114 fetching_completed_ = true; 114 fetching_completed_ = true;
115 } 115 }
116 116
117 content::TestBrowserThreadBundle thread_bundle_; 117 content::TestBrowserThreadBundle thread_bundle_;
118 scoped_refptr<quota::QuotaManager> quota_manager_; 118 scoped_refptr<storage::QuotaManager> quota_manager_;
119 119
120 base::ScopedTempDir dir_; 120 base::ScopedTempDir dir_;
121 scoped_refptr<BrowsingDataQuotaHelper> helper_; 121 scoped_refptr<BrowsingDataQuotaHelper> helper_;
122 122
123 bool fetching_completed_; 123 bool fetching_completed_;
124 QuotaInfoArray quota_info_; 124 QuotaInfoArray quota_info_;
125 int64 quota_; 125 int64 quota_;
126 base::WeakPtrFactory<BrowsingDataQuotaHelperTest> weak_factory_; 126 base::WeakPtrFactory<BrowsingDataQuotaHelperTest> weak_factory_;
127 127
128 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); 128 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest);
129 }; 129 };
130 130
131 TEST_F(BrowsingDataQuotaHelperTest, Empty) { 131 TEST_F(BrowsingDataQuotaHelperTest, Empty) {
132 StartFetching(); 132 StartFetching();
133 base::MessageLoop::current()->RunUntilIdle(); 133 base::MessageLoop::current()->RunUntilIdle();
134 EXPECT_TRUE(fetching_completed()); 134 EXPECT_TRUE(fetching_completed());
135 EXPECT_TRUE(quota_info().empty()); 135 EXPECT_TRUE(quota_info().empty());
136 } 136 }
137 137
138 TEST_F(BrowsingDataQuotaHelperTest, FetchData) { 138 TEST_F(BrowsingDataQuotaHelperTest, FetchData) {
139 const MockOriginData kOrigins[] = { 139 const MockOriginData kOrigins[] = {
140 {"http://example.com/", quota::kStorageTypeTemporary, 1}, 140 {"http://example.com/", storage::kStorageTypeTemporary, 1},
141 {"https://example.com/", quota::kStorageTypeTemporary, 10}, 141 {"https://example.com/", storage::kStorageTypeTemporary, 10},
142 {"http://example.com/", quota::kStorageTypePersistent, 100}, 142 {"http://example.com/", storage::kStorageTypePersistent, 100},
143 {"https://example.com/", quota::kStorageTypeSyncable, 1}, 143 {"https://example.com/", storage::kStorageTypeSyncable, 1},
144 {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, 144 {"http://example2.com/", storage::kStorageTypeTemporary, 1000},
145 }; 145 };
146 146
147 RegisterClient(kOrigins, arraysize(kOrigins)); 147 RegisterClient(kOrigins, arraysize(kOrigins));
148 StartFetching(); 148 StartFetching();
149 base::MessageLoop::current()->RunUntilIdle(); 149 base::MessageLoop::current()->RunUntilIdle();
150 EXPECT_TRUE(fetching_completed()); 150 EXPECT_TRUE(fetching_completed());
151 151
152 std::set<QuotaInfo> expected, actual; 152 std::set<QuotaInfo> expected, actual;
153 actual.insert(quota_info().begin(), quota_info().end()); 153 actual.insert(quota_info().begin(), quota_info().end());
154 expected.insert(QuotaInfo("example.com", 11, 100, 1)); 154 expected.insert(QuotaInfo("example.com", 11, 100, 1));
155 expected.insert(QuotaInfo("example2.com", 1000, 0, 0)); 155 expected.insert(QuotaInfo("example2.com", 1000, 0, 0));
156 EXPECT_TRUE(expected == actual); 156 EXPECT_TRUE(expected == actual);
157 } 157 }
158 158
159 TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensionsAndDevTools) { 159 TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensionsAndDevTools) {
160 const MockOriginData kOrigins[] = { 160 const MockOriginData kOrigins[] = {
161 {"http://example.com/", quota::kStorageTypeTemporary, 1}, 161 {"http://example.com/", storage::kStorageTypeTemporary, 1},
162 {"https://example.com/", quota::kStorageTypeTemporary, 10}, 162 {"https://example.com/", storage::kStorageTypeTemporary, 10},
163 {"http://example.com/", quota::kStorageTypePersistent, 100}, 163 {"http://example.com/", storage::kStorageTypePersistent, 100},
164 {"https://example.com/", quota::kStorageTypeSyncable, 1}, 164 {"https://example.com/", storage::kStorageTypeSyncable, 1},
165 {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, 165 {"http://example2.com/", storage::kStorageTypeTemporary, 1000},
166 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/", 166 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/",
167 quota::kStorageTypeTemporary, 10000}, 167 storage::kStorageTypeTemporary, 10000},
168 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/", 168 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/",
169 quota::kStorageTypePersistent, 100000}, 169 storage::kStorageTypePersistent, 100000},
170 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", 170 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/",
171 quota::kStorageTypeTemporary, 10000}, 171 storage::kStorageTypeTemporary, 10000},
172 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", 172 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/",
173 quota::kStorageTypePersistent, 100000}, 173 storage::kStorageTypePersistent, 100000},
174 }; 174 };
175 175
176 RegisterClient(kOrigins, arraysize(kOrigins)); 176 RegisterClient(kOrigins, arraysize(kOrigins));
177 StartFetching(); 177 StartFetching();
178 base::MessageLoop::current()->RunUntilIdle(); 178 base::MessageLoop::current()->RunUntilIdle();
179 EXPECT_TRUE(fetching_completed()); 179 EXPECT_TRUE(fetching_completed());
180 180
181 std::set<QuotaInfo> expected, actual; 181 std::set<QuotaInfo> expected, actual;
182 actual.insert(quota_info().begin(), quota_info().end()); 182 actual.insert(quota_info().begin(), quota_info().end());
183 expected.insert(QuotaInfo("example.com", 11, 100, 1)); 183 expected.insert(QuotaInfo("example.com", 11, 100, 1));
(...skipping 13 matching lines...) Expand all
197 base::MessageLoop::current()->RunUntilIdle(); 197 base::MessageLoop::current()->RunUntilIdle();
198 198
199 GetPersistentHostQuota(kHost1); 199 GetPersistentHostQuota(kHost1);
200 base::MessageLoop::current()->RunUntilIdle(); 200 base::MessageLoop::current()->RunUntilIdle();
201 EXPECT_EQ(0, quota()); 201 EXPECT_EQ(0, quota());
202 202
203 GetPersistentHostQuota(kHost2); 203 GetPersistentHostQuota(kHost2);
204 base::MessageLoop::current()->RunUntilIdle(); 204 base::MessageLoop::current()->RunUntilIdle();
205 EXPECT_EQ(10, quota()); 205 EXPECT_EQ(10, quota());
206 } 206 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_quota_helper_impl.cc ('k') | chrome/browser/browsing_data/browsing_data_remover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698