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

Side by Side Diff: content/browser/database_quota_client_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, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/browser/database/database_quota_client.h" 15 #include "webkit/browser/database/database_quota_client.h"
16 #include "webkit/browser/database/database_tracker.h" 16 #include "webkit/browser/database/database_tracker.h"
17 #include "webkit/browser/database/database_util.h" 17 #include "webkit/browser/database/database_util.h"
18 #include "webkit/common/database/database_identifier.h" 18 #include "webkit/common/database/database_identifier.h"
19 19
20 using webkit_database::DatabaseQuotaClient; 20 using storage::DatabaseQuotaClient;
21 using webkit_database::DatabaseTracker; 21 using storage::DatabaseTracker;
22 using webkit_database::OriginInfo; 22 using storage::OriginInfo;
23 23
24 namespace content { 24 namespace content {
25 25
26 // Declared to shorten the line lengths. 26 // Declared to shorten the line lengths.
27 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; 27 static const storage::StorageType kTemp = storage::kStorageTypeTemporary;
28 static const quota::StorageType kPerm = quota::kStorageTypePersistent; 28 static const storage::StorageType kPerm = storage::kStorageTypePersistent;
29 29
30 // Mock tracker class the mocks up those methods of the tracker 30 // Mock tracker class the mocks up those methods of the tracker
31 // that are used by the QuotaClient. 31 // that are used by the QuotaClient.
32 class MockDatabaseTracker : public DatabaseTracker { 32 class MockDatabaseTracker : public DatabaseTracker {
33 public: 33 public:
34 MockDatabaseTracker() 34 MockDatabaseTracker()
35 : DatabaseTracker(base::FilePath(), false, NULL, NULL, NULL), 35 : DatabaseTracker(base::FilePath(), false, NULL, NULL, NULL),
36 delete_called_count_(0), 36 delete_called_count_(0),
37 async_delete_(false) {} 37 async_delete_(false) {}
38 38
39 virtual bool GetOriginInfo( 39 virtual bool GetOriginInfo(
40 const std::string& origin_identifier, 40 const std::string& origin_identifier,
41 OriginInfo* info) OVERRIDE { 41 OriginInfo* info) OVERRIDE {
42 std::map<GURL, MockOriginInfo>::const_iterator found = 42 std::map<GURL, MockOriginInfo>::const_iterator found =
43 mock_origin_infos_.find( 43 mock_origin_infos_.find(
44 webkit_database::GetOriginFromIdentifier(origin_identifier)); 44 storage::GetOriginFromIdentifier(origin_identifier));
45 if (found == mock_origin_infos_.end()) 45 if (found == mock_origin_infos_.end())
46 return false; 46 return false;
47 *info = OriginInfo(found->second); 47 *info = OriginInfo(found->second);
48 return true; 48 return true;
49 } 49 }
50 50
51 virtual bool GetAllOriginIdentifiers( 51 virtual bool GetAllOriginIdentifiers(
52 std::vector<std::string>* origins_identifiers) OVERRIDE { 52 std::vector<std::string>* origins_identifiers) OVERRIDE {
53 std::map<GURL, MockOriginInfo>::const_iterator iter; 53 std::map<GURL, MockOriginInfo>::const_iterator iter;
54 for (iter = mock_origin_infos_.begin(); 54 for (iter = mock_origin_infos_.begin();
(...skipping 28 matching lines...) Expand all
83 } 83 }
84 return net::OK; 84 return net::OK;
85 } 85 }
86 86
87 void AsyncDeleteDataForOrigin(const net::CompletionCallback& callback) { 87 void AsyncDeleteDataForOrigin(const net::CompletionCallback& callback) {
88 callback.Run(net::OK); 88 callback.Run(net::OK);
89 } 89 }
90 90
91 void AddMockDatabase(const GURL& origin, const char* name, int size) { 91 void AddMockDatabase(const GURL& origin, const char* name, int size) {
92 MockOriginInfo& info = mock_origin_infos_[origin]; 92 MockOriginInfo& info = mock_origin_infos_[origin];
93 info.set_origin(webkit_database::GetIdentifierFromOrigin(origin)); 93 info.set_origin(storage::GetIdentifierFromOrigin(origin));
94 info.AddMockDatabase(base::ASCIIToUTF16(name), size); 94 info.AddMockDatabase(base::ASCIIToUTF16(name), size);
95 } 95 }
96 96
97 int delete_called_count() { return delete_called_count_; } 97 int delete_called_count() { return delete_called_count_; }
98 bool async_delete() { return async_delete_; } 98 bool async_delete() { return async_delete_; }
99 void set_async_delete(bool async) { async_delete_ = async; } 99 void set_async_delete(bool async) { async_delete_ = async; }
100 100
101 protected: 101 protected:
102 virtual ~MockDatabaseTracker() {} 102 virtual ~MockDatabaseTracker() {}
103 103
(...skipping 26 matching lines...) Expand all
130 130
131 DatabaseQuotaClientTest() 131 DatabaseQuotaClientTest()
132 : kOriginA("http://host"), 132 : kOriginA("http://host"),
133 kOriginB("http://host:8000"), 133 kOriginB("http://host:8000"),
134 kOriginOther("http://other"), 134 kOriginOther("http://other"),
135 usage_(0), 135 usage_(0),
136 mock_tracker_(new MockDatabaseTracker), 136 mock_tracker_(new MockDatabaseTracker),
137 weak_factory_(this) { 137 weak_factory_(this) {
138 } 138 }
139 139
140 int64 GetOriginUsage( 140 int64 GetOriginUsage(storage::QuotaClient* client,
141 quota::QuotaClient* client, 141 const GURL& origin,
142 const GURL& origin, 142 storage::StorageType type) {
143 quota::StorageType type) {
144 usage_ = 0; 143 usage_ = 0;
145 client->GetOriginUsage( 144 client->GetOriginUsage(
146 origin, type, 145 origin, type,
147 base::Bind(&DatabaseQuotaClientTest::OnGetOriginUsageComplete, 146 base::Bind(&DatabaseQuotaClientTest::OnGetOriginUsageComplete,
148 weak_factory_.GetWeakPtr())); 147 weak_factory_.GetWeakPtr()));
149 base::RunLoop().RunUntilIdle(); 148 base::RunLoop().RunUntilIdle();
150 return usage_; 149 return usage_;
151 } 150 }
152 151
153 const std::set<GURL>& GetOriginsForType( 152 const std::set<GURL>& GetOriginsForType(storage::QuotaClient* client,
154 quota::QuotaClient* client, 153 storage::StorageType type) {
155 quota::StorageType type) {
156 origins_.clear(); 154 origins_.clear();
157 client->GetOriginsForType( 155 client->GetOriginsForType(
158 type, 156 type,
159 base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete, 157 base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete,
160 weak_factory_.GetWeakPtr())); 158 weak_factory_.GetWeakPtr()));
161 base::RunLoop().RunUntilIdle(); 159 base::RunLoop().RunUntilIdle();
162 return origins_; 160 return origins_;
163 } 161 }
164 162
165 const std::set<GURL>& GetOriginsForHost( 163 const std::set<GURL>& GetOriginsForHost(storage::QuotaClient* client,
166 quota::QuotaClient* client, 164 storage::StorageType type,
167 quota::StorageType type, 165 const std::string& host) {
168 const std::string& host) {
169 origins_.clear(); 166 origins_.clear();
170 client->GetOriginsForHost( 167 client->GetOriginsForHost(
171 type, host, 168 type, host,
172 base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete, 169 base::Bind(&DatabaseQuotaClientTest::OnGetOriginsComplete,
173 weak_factory_.GetWeakPtr())); 170 weak_factory_.GetWeakPtr()));
174 base::RunLoop().RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
175 return origins_; 172 return origins_;
176 } 173 }
177 174
178 bool DeleteOriginData( 175 bool DeleteOriginData(storage::QuotaClient* client,
179 quota::QuotaClient* client, 176 storage::StorageType type,
180 quota::StorageType type, 177 const GURL& origin) {
181 const GURL& origin) { 178 delete_status_ = storage::kQuotaStatusUnknown;
182 delete_status_ = quota::kQuotaStatusUnknown;
183 client->DeleteOriginData( 179 client->DeleteOriginData(
184 origin, type, 180 origin, type,
185 base::Bind(&DatabaseQuotaClientTest::OnDeleteOriginDataComplete, 181 base::Bind(&DatabaseQuotaClientTest::OnDeleteOriginDataComplete,
186 weak_factory_.GetWeakPtr())); 182 weak_factory_.GetWeakPtr()));
187 base::RunLoop().RunUntilIdle(); 183 base::RunLoop().RunUntilIdle();
188 return delete_status_ == quota::kQuotaStatusOk; 184 return delete_status_ == storage::kQuotaStatusOk;
189 } 185 }
190 186
191 MockDatabaseTracker* mock_tracker() { return mock_tracker_.get(); } 187 MockDatabaseTracker* mock_tracker() { return mock_tracker_.get(); }
192 188
193 189
194 private: 190 private:
195 void OnGetOriginUsageComplete(int64 usage) { 191 void OnGetOriginUsageComplete(int64 usage) {
196 usage_ = usage; 192 usage_ = usage;
197 } 193 }
198 194
199 void OnGetOriginsComplete(const std::set<GURL>& origins) { 195 void OnGetOriginsComplete(const std::set<GURL>& origins) {
200 origins_ = origins; 196 origins_ = origins;
201 } 197 }
202 198
203 void OnDeleteOriginDataComplete(quota::QuotaStatusCode status) { 199 void OnDeleteOriginDataComplete(storage::QuotaStatusCode status) {
204 delete_status_ = status; 200 delete_status_ = status;
205 } 201 }
206 202
207 base::MessageLoop message_loop_; 203 base::MessageLoop message_loop_;
208 int64 usage_; 204 int64 usage_;
209 std::set<GURL> origins_; 205 std::set<GURL> origins_;
210 quota::QuotaStatusCode delete_status_; 206 storage::QuotaStatusCode delete_status_;
211 scoped_refptr<MockDatabaseTracker> mock_tracker_; 207 scoped_refptr<MockDatabaseTracker> mock_tracker_;
212 base::WeakPtrFactory<DatabaseQuotaClientTest> weak_factory_; 208 base::WeakPtrFactory<DatabaseQuotaClientTest> weak_factory_;
213 }; 209 };
214 210
215 211
216 TEST_F(DatabaseQuotaClientTest, GetOriginUsage) { 212 TEST_F(DatabaseQuotaClientTest, GetOriginUsage) {
217 DatabaseQuotaClient client(base::MessageLoopProxy::current().get(), 213 DatabaseQuotaClient client(base::MessageLoopProxy::current().get(),
218 mock_tracker()); 214 mock_tracker());
219 215
220 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp)); 216 EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kTemp));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 mock_tracker()->set_async_delete(false); 276 mock_tracker()->set_async_delete(false);
281 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); 277 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA));
282 EXPECT_EQ(1, mock_tracker()->delete_called_count()); 278 EXPECT_EQ(1, mock_tracker()->delete_called_count());
283 279
284 mock_tracker()->set_async_delete(true); 280 mock_tracker()->set_async_delete(true);
285 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); 281 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA));
286 EXPECT_EQ(2, mock_tracker()->delete_called_count()); 282 EXPECT_EQ(2, mock_tracker()->delete_called_count());
287 } 283 }
288 284
289 } // namespace content 285 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_security_policy_unittest.cc ('k') | content/browser/database_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698