OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
6 #include <iterator> | 6 #include <iterator> |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "app/sql/connection.h" | 9 #include "app/sql/connection.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
11 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
12 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "webkit/quota/quota_database.h" | 16 #include "webkit/quota/quota_database.h" |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 const base::Time kZeroTime; | 20 const base::Time kZeroTime; |
19 | 21 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 EXPECT_TRUE(db.RegisterOrigins(origins, | 187 EXPECT_TRUE(db.RegisterOrigins(origins, |
186 kStorageTypeTemporary, | 188 kStorageTypeTemporary, |
187 base::Time())); | 189 base::Time())); |
188 | 190 |
189 used_count = -1; | 191 used_count = -1; |
190 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"), | 192 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"), |
191 kStorageTypeTemporary, | 193 kStorageTypeTemporary, |
192 &used_count)); | 194 &used_count)); |
193 EXPECT_EQ(1, used_count); | 195 EXPECT_EQ(1, used_count); |
194 } | 196 } |
| 197 |
| 198 template<typename T> |
| 199 struct EntryVerifier { |
| 200 std::set<T>* xs; |
| 201 bool Run(const T& x) { |
| 202 EXPECT_EQ(1u, xs->erase(x)); |
| 203 return true; |
| 204 } |
| 205 }; |
| 206 |
| 207 void DumpQuotaTable(const FilePath& kDbFile) { |
| 208 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry; |
| 209 typedef QuotaDatabase::QuotaTableCallback QuotaTableCallback; |
| 210 |
| 211 QuotaTableEntry kQuotaTable[] = { |
| 212 {"http://go/", kStorageTypeTemporary, 1}, |
| 213 {"http://oo/", kStorageTypeTemporary, 2}, |
| 214 {"http://gle/", kStorageTypePersistent, 3} |
| 215 }; |
| 216 |
| 217 std::set<QuotaTableEntry> quota_table( |
| 218 kQuotaTable, kQuotaTable + ARRAYSIZE_UNSAFE(kQuotaTable)); |
| 219 QuotaDatabase db(kDbFile); |
| 220 EXPECT_TRUE(db.AssignQuotaTable(quota_table)); |
| 221 |
| 222 typedef EntryVerifier<QuotaTableEntry> Verifier; |
| 223 Verifier verifier = {"a_table}; |
| 224 QuotaTableCallback callback = base::Bind(&Verifier::Run, |
| 225 base::Unretained(&verifier)); |
| 226 EXPECT_TRUE(db.DumpQuotaTable(&callback)); |
| 227 EXPECT_TRUE(quota_table.empty()); |
| 228 } |
| 229 |
| 230 void DumpAccessTable(const FilePath& kDbFile) { |
| 231 typedef QuotaDatabase::AccessTableEntry AccessTableEntry; |
| 232 typedef QuotaDatabase::AccessTableCallback AccessTableCallback; |
| 233 |
| 234 base::Time now(base::Time::Now()); |
| 235 AccessTableEntry kAccessTable[] = { |
| 236 {GURL("http://go/"), kStorageTypeTemporary, 2147483647, now}, |
| 237 {GURL("http://oo/"), kStorageTypeTemporary, 0, now}, |
| 238 {GURL("http://gle/"), kStorageTypeTemporary, 1, now}, |
| 239 }; |
| 240 |
| 241 std::set<AccessTableEntry> access_table( |
| 242 kAccessTable, kAccessTable + ARRAYSIZE_UNSAFE(kAccessTable)); |
| 243 QuotaDatabase db(kDbFile); |
| 244 EXPECT_TRUE(db.AssignAccessTable(access_table)); |
| 245 |
| 246 typedef EntryVerifier<AccessTableEntry> Verifier; |
| 247 Verifier verifier = {&access_table}; |
| 248 AccessTableCallback callback = base::Bind(&Verifier::Run, |
| 249 base::Unretained(&verifier)); |
| 250 EXPECT_TRUE(db.DumpAccessTable(&callback)); |
| 251 EXPECT_TRUE(access_table.empty()); |
| 252 } |
195 }; | 253 }; |
196 | 254 |
197 TEST_F(QuotaDatabaseTest, LazyOpen) { | 255 TEST_F(QuotaDatabaseTest, LazyOpen) { |
198 ScopedTempDir data_dir; | 256 ScopedTempDir data_dir; |
199 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | 257 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
200 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); | 258 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); |
201 LazyOpen(kDbFile); | 259 LazyOpen(kDbFile); |
202 LazyOpen(FilePath()); | 260 LazyOpen(FilePath()); |
203 } | 261 } |
204 | 262 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 EXPECT_FALSE(db.IsOriginDatabaseBootstrapped()); | 298 EXPECT_FALSE(db.IsOriginDatabaseBootstrapped()); |
241 } | 299 } |
242 | 300 |
243 TEST_F(QuotaDatabaseTest, RegisterOrigins) { | 301 TEST_F(QuotaDatabaseTest, RegisterOrigins) { |
244 ScopedTempDir data_dir; | 302 ScopedTempDir data_dir; |
245 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | 303 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
246 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); | 304 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); |
247 RegisterOrigins(kDbFile); | 305 RegisterOrigins(kDbFile); |
248 RegisterOrigins(FilePath()); | 306 RegisterOrigins(FilePath()); |
249 } | 307 } |
| 308 |
| 309 TEST_F(QuotaDatabaseTest, DumpQuotaTable) { |
| 310 ScopedTempDir data_dir; |
| 311 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
| 312 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); |
| 313 DumpQuotaTable(kDbFile); |
| 314 DumpQuotaTable(FilePath()); |
| 315 } |
| 316 |
| 317 TEST_F(QuotaDatabaseTest, DumpAccessTable) { |
| 318 ScopedTempDir data_dir; |
| 319 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
| 320 const FilePath kDbFile = data_dir.path().AppendASCII("quota_manager.db"); |
| 321 DumpAccessTable(kDbFile); |
| 322 DumpAccessTable(FilePath()); |
| 323 } |
250 } // namespace quota | 324 } // namespace quota |
OLD | NEW |