Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / quota / quota_database_unittest.cc
blob84af01707c26e7af10a991cb39ec72296bc736c1
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
3 // found in the LICENSE file.
5 #include <algorithm>
6 #include <iterator>
7 #include <set>
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/message_loop/message_loop.h"
14 #include "content/public/test/mock_special_storage_policy.h"
15 #include "sql/connection.h"
16 #include "sql/meta_table.h"
17 #include "sql/statement.h"
18 #include "sql/test/scoped_error_ignorer.h"
19 #include "sql/test/test_helpers.h"
20 #include "storage/browser/quota/quota_database.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h"
24 using storage::kStorageTypePersistent;
25 using storage::kStorageTypeTemporary;
26 using storage::QuotaDatabase;
28 namespace content {
29 namespace {
31 const base::Time kZeroTime;
33 const char kDBFileName[] = "quota_manager.db";
35 } // namespace
37 class QuotaDatabaseTest : public testing::Test {
38 protected:
39 typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry;
40 typedef QuotaDatabase::QuotaTableCallback QuotaTableCallback;
41 typedef QuotaDatabase::OriginInfoTableCallback
42 OriginInfoTableCallback;
44 void LazyOpen(const base::FilePath& kDbFile) {
45 QuotaDatabase db(kDbFile);
46 EXPECT_FALSE(db.LazyOpen(false));
47 ASSERT_TRUE(db.LazyOpen(true));
48 EXPECT_TRUE(db.db_.get());
49 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
52 void Reopen(const base::FilePath& kDbFile) {
53 QuotaDatabase db(kDbFile);
54 ASSERT_TRUE(db.LazyOpen(false));
55 EXPECT_TRUE(db.db_.get());
56 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
59 void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) {
60 const QuotaTableEntry entries[] = {
61 QuotaTableEntry("a", kStorageTypeTemporary, 1),
62 QuotaTableEntry("b", kStorageTypeTemporary, 2),
63 QuotaTableEntry("c", kStorageTypePersistent, 3),
66 CreateV2Database(kDbFile, entries, arraysize(entries));
68 QuotaDatabase db(kDbFile);
69 EXPECT_TRUE(db.LazyOpen(true));
70 EXPECT_TRUE(db.db_.get());
72 typedef EntryVerifier<QuotaTableEntry> Verifier;
73 Verifier verifier(entries, entries + arraysize(entries));
74 EXPECT_TRUE(db.DumpQuotaTable(
75 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
76 EXPECT_TRUE(verifier.table.empty());
79 void HostQuota(const base::FilePath& kDbFile) {
80 QuotaDatabase db(kDbFile);
81 ASSERT_TRUE(db.LazyOpen(true));
83 const char* kHost = "foo.com";
84 const int kQuota1 = 13579;
85 const int kQuota2 = kQuota1 + 1024;
87 int64 quota = -1;
88 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
89 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
91 // Insert quota for temporary.
92 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1));
93 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
94 EXPECT_EQ(kQuota1, quota);
96 // Update quota for temporary.
97 EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2));
98 EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
99 EXPECT_EQ(kQuota2, quota);
101 // Quota for persistent must not be updated.
102 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
104 // Delete temporary storage quota.
105 EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary));
106 EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
109 void GlobalQuota(const base::FilePath& kDbFile) {
110 QuotaDatabase db(kDbFile);
111 ASSERT_TRUE(db.LazyOpen(true));
113 const char* kTempQuotaKey = QuotaDatabase::kTemporaryQuotaOverrideKey;
114 const char* kAvailSpaceKey = QuotaDatabase::kDesiredAvailableSpaceKey;
116 int64 value = 0;
117 const int64 kValue1 = 456;
118 const int64 kValue2 = 123000;
119 EXPECT_FALSE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
120 EXPECT_FALSE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
122 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue1));
123 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
124 EXPECT_EQ(kValue1, value);
126 EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue2));
127 EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
128 EXPECT_EQ(kValue2, value);
130 EXPECT_TRUE(db.SetQuotaConfigValue(kAvailSpaceKey, kValue1));
131 EXPECT_TRUE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
132 EXPECT_EQ(kValue1, value);
134 EXPECT_TRUE(db.SetQuotaConfigValue(kAvailSpaceKey, kValue2));
135 EXPECT_TRUE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
136 EXPECT_EQ(kValue2, value);
139 void OriginLastAccessTimeLRU(const base::FilePath& kDbFile) {
140 QuotaDatabase db(kDbFile);
141 ASSERT_TRUE(db.LazyOpen(true));
143 std::set<GURL> exceptions;
144 GURL origin;
145 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
146 NULL, &origin));
147 EXPECT_TRUE(origin.is_empty());
149 const GURL kOrigin1("http://a/");
150 const GURL kOrigin2("http://b/");
151 const GURL kOrigin3("http://c/");
152 const GURL kOrigin4("http://p/");
154 // Adding three temporary storages, and
155 EXPECT_TRUE(db.SetOriginLastAccessTime(
156 kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
157 EXPECT_TRUE(db.SetOriginLastAccessTime(
158 kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
159 EXPECT_TRUE(db.SetOriginLastAccessTime(
160 kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(30)));
162 // one persistent.
163 EXPECT_TRUE(db.SetOriginLastAccessTime(
164 kOrigin4, kStorageTypePersistent, base::Time::FromInternalValue(40)));
166 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
167 NULL, &origin));
168 EXPECT_EQ(kOrigin1.spec(), origin.spec());
170 // Test that unlimited origins are exluded from eviction, but
171 // protected origins are not excluded.
172 scoped_refptr<MockSpecialStoragePolicy> policy(
173 new MockSpecialStoragePolicy);
174 policy->AddUnlimited(kOrigin1);
175 policy->AddProtected(kOrigin2);
176 EXPECT_TRUE(db.GetLRUOrigin(
177 kStorageTypeTemporary, exceptions, policy.get(), &origin));
178 EXPECT_EQ(kOrigin2.spec(), origin.spec());
180 // Test that durable origins are excluded from eviction.
181 policy->AddDurable(kOrigin2);
182 EXPECT_TRUE(db.GetLRUOrigin(
183 kStorageTypeTemporary, exceptions, policy.get(), &origin));
184 EXPECT_EQ(kOrigin3.spec(), origin.spec());
186 exceptions.insert(kOrigin1);
187 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
188 NULL, &origin));
189 EXPECT_EQ(kOrigin2.spec(), origin.spec());
191 exceptions.insert(kOrigin2);
192 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
193 NULL, &origin));
194 EXPECT_EQ(kOrigin3.spec(), origin.spec());
196 exceptions.insert(kOrigin3);
197 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
198 NULL, &origin));
199 EXPECT_TRUE(origin.is_empty());
201 EXPECT_TRUE(db.SetOriginLastAccessTime(
202 kOrigin1, kStorageTypeTemporary, base::Time::Now()));
204 // Delete origin/type last access time information.
205 EXPECT_TRUE(db.DeleteOriginInfo(kOrigin3, kStorageTypeTemporary));
207 // Querying again to see if the deletion has worked.
208 exceptions.clear();
209 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
210 NULL, &origin));
211 EXPECT_EQ(kOrigin2.spec(), origin.spec());
213 exceptions.insert(kOrigin1);
214 exceptions.insert(kOrigin2);
215 EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
216 NULL, &origin));
217 EXPECT_TRUE(origin.is_empty());
220 void OriginLastModifiedSince(const base::FilePath& kDbFile) {
221 QuotaDatabase db(kDbFile);
222 ASSERT_TRUE(db.LazyOpen(true));
224 std::set<GURL> origins;
225 EXPECT_TRUE(db.GetOriginsModifiedSince(
226 kStorageTypeTemporary, &origins, base::Time()));
227 EXPECT_TRUE(origins.empty());
229 const GURL kOrigin1("http://a/");
230 const GURL kOrigin2("http://b/");
231 const GURL kOrigin3("http://c/");
233 // Report last mod time for the test origins.
234 EXPECT_TRUE(db.SetOriginLastModifiedTime(
235 kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(0)));
236 EXPECT_TRUE(db.SetOriginLastModifiedTime(
237 kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
238 EXPECT_TRUE(db.SetOriginLastModifiedTime(
239 kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
241 EXPECT_TRUE(db.GetOriginsModifiedSince(
242 kStorageTypeTemporary, &origins, base::Time()));
243 EXPECT_EQ(3U, origins.size());
244 EXPECT_EQ(1U, origins.count(kOrigin1));
245 EXPECT_EQ(1U, origins.count(kOrigin2));
246 EXPECT_EQ(1U, origins.count(kOrigin3));
248 EXPECT_TRUE(db.GetOriginsModifiedSince(
249 kStorageTypeTemporary, &origins, base::Time::FromInternalValue(5)));
250 EXPECT_EQ(2U, origins.size());
251 EXPECT_EQ(0U, origins.count(kOrigin1));
252 EXPECT_EQ(1U, origins.count(kOrigin2));
253 EXPECT_EQ(1U, origins.count(kOrigin3));
255 EXPECT_TRUE(db.GetOriginsModifiedSince(
256 kStorageTypeTemporary, &origins, base::Time::FromInternalValue(15)));
257 EXPECT_EQ(1U, origins.size());
258 EXPECT_EQ(0U, origins.count(kOrigin1));
259 EXPECT_EQ(0U, origins.count(kOrigin2));
260 EXPECT_EQ(1U, origins.count(kOrigin3));
262 EXPECT_TRUE(db.GetOriginsModifiedSince(
263 kStorageTypeTemporary, &origins, base::Time::FromInternalValue(25)));
264 EXPECT_TRUE(origins.empty());
266 // Update origin1's mod time but for persistent storage.
267 EXPECT_TRUE(db.SetOriginLastModifiedTime(
268 kOrigin1, kStorageTypePersistent, base::Time::FromInternalValue(30)));
270 // Must have no effects on temporary origins info.
271 EXPECT_TRUE(db.GetOriginsModifiedSince(
272 kStorageTypeTemporary, &origins, base::Time::FromInternalValue(5)));
273 EXPECT_EQ(2U, origins.size());
274 EXPECT_EQ(0U, origins.count(kOrigin1));
275 EXPECT_EQ(1U, origins.count(kOrigin2));
276 EXPECT_EQ(1U, origins.count(kOrigin3));
278 // One more update for persistent origin2.
279 EXPECT_TRUE(db.SetOriginLastModifiedTime(
280 kOrigin2, kStorageTypePersistent, base::Time::FromInternalValue(40)));
282 EXPECT_TRUE(db.GetOriginsModifiedSince(
283 kStorageTypePersistent, &origins, base::Time::FromInternalValue(25)));
284 EXPECT_EQ(2U, origins.size());
285 EXPECT_EQ(1U, origins.count(kOrigin1));
286 EXPECT_EQ(1U, origins.count(kOrigin2));
287 EXPECT_EQ(0U, origins.count(kOrigin3));
289 EXPECT_TRUE(db.GetOriginsModifiedSince(
290 kStorageTypePersistent, &origins, base::Time::FromInternalValue(35)));
291 EXPECT_EQ(1U, origins.size());
292 EXPECT_EQ(0U, origins.count(kOrigin1));
293 EXPECT_EQ(1U, origins.count(kOrigin2));
294 EXPECT_EQ(0U, origins.count(kOrigin3));
297 void RegisterInitialOriginInfo(const base::FilePath& kDbFile) {
298 QuotaDatabase db(kDbFile);
300 const GURL kOrigins[] = {
301 GURL("http://a/"),
302 GURL("http://b/"),
303 GURL("http://c/") };
304 std::set<GURL> origins(kOrigins, kOrigins + arraysize(kOrigins));
306 EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary));
308 int used_count = -1;
309 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
310 kStorageTypeTemporary,
311 &used_count));
312 EXPECT_EQ(0, used_count);
314 EXPECT_TRUE(db.SetOriginLastAccessTime(
315 GURL("http://a/"), kStorageTypeTemporary,
316 base::Time::FromDoubleT(1.0)));
317 used_count = -1;
318 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
319 kStorageTypeTemporary,
320 &used_count));
321 EXPECT_EQ(1, used_count);
323 EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary));
325 used_count = -1;
326 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
327 kStorageTypeTemporary,
328 &used_count));
329 EXPECT_EQ(1, used_count);
332 template <typename EntryType>
333 struct EntryVerifier {
334 std::set<EntryType> table;
336 template <typename Iterator>
337 EntryVerifier(Iterator itr, Iterator end)
338 : table(itr, end) {}
340 bool Run(const EntryType& entry) {
341 EXPECT_EQ(1u, table.erase(entry));
342 return true;
346 void DumpQuotaTable(const base::FilePath& kDbFile) {
347 QuotaTableEntry kTableEntries[] = {
348 QuotaTableEntry("http://go/", kStorageTypeTemporary, 1),
349 QuotaTableEntry("http://oo/", kStorageTypeTemporary, 2),
350 QuotaTableEntry("http://gle/", kStorageTypePersistent, 3)
352 QuotaTableEntry* begin = kTableEntries;
353 QuotaTableEntry* end = kTableEntries + arraysize(kTableEntries);
355 QuotaDatabase db(kDbFile);
356 EXPECT_TRUE(db.LazyOpen(true));
357 AssignQuotaTable(db.db_.get(), begin, end);
358 db.Commit();
360 typedef EntryVerifier<QuotaTableEntry> Verifier;
361 Verifier verifier(begin, end);
362 EXPECT_TRUE(db.DumpQuotaTable(
363 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
364 EXPECT_TRUE(verifier.table.empty());
367 void DumpOriginInfoTable(const base::FilePath& kDbFile) {
368 base::Time now(base::Time::Now());
369 typedef QuotaDatabase::OriginInfoTableEntry Entry;
370 Entry kTableEntries[] = {
371 Entry(GURL("http://go/"), kStorageTypeTemporary, 2147483647, now, now),
372 Entry(GURL("http://oo/"), kStorageTypeTemporary, 0, now, now),
373 Entry(GURL("http://gle/"), kStorageTypeTemporary, 1, now, now),
375 Entry* begin = kTableEntries;
376 Entry* end = kTableEntries + arraysize(kTableEntries);
378 QuotaDatabase db(kDbFile);
379 EXPECT_TRUE(db.LazyOpen(true));
380 AssignOriginInfoTable(db.db_.get(), begin, end);
381 db.Commit();
383 typedef EntryVerifier<Entry> Verifier;
384 Verifier verifier(begin, end);
385 EXPECT_TRUE(db.DumpOriginInfoTable(
386 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
387 EXPECT_TRUE(verifier.table.empty());
390 private:
391 template <typename Iterator>
392 void AssignQuotaTable(sql::Connection* db, Iterator itr, Iterator end) {
393 ASSERT_NE(db, (sql::Connection*)NULL);
394 for (; itr != end; ++itr) {
395 const char* kSql =
396 "INSERT INTO HostQuotaTable"
397 " (host, type, quota)"
398 " VALUES (?, ?, ?)";
399 sql::Statement statement;
400 statement.Assign(db->GetCachedStatement(SQL_FROM_HERE, kSql));
401 ASSERT_TRUE(statement.is_valid());
403 statement.BindString(0, itr->host);
404 statement.BindInt(1, static_cast<int>(itr->type));
405 statement.BindInt64(2, itr->quota);
406 EXPECT_TRUE(statement.Run());
410 template <typename Iterator>
411 void AssignOriginInfoTable(sql::Connection* db, Iterator itr, Iterator end) {
412 ASSERT_NE(db, (sql::Connection*)NULL);
413 for (; itr != end; ++itr) {
414 const char* kSql =
415 "INSERT INTO OriginInfoTable"
416 " (origin, type, used_count, last_access_time, last_modified_time)"
417 " VALUES (?, ?, ?, ?, ?)";
418 sql::Statement statement;
419 statement.Assign(db->GetCachedStatement(SQL_FROM_HERE, kSql));
420 ASSERT_TRUE(statement.is_valid());
422 statement.BindString(0, itr->origin.spec());
423 statement.BindInt(1, static_cast<int>(itr->type));
424 statement.BindInt(2, itr->used_count);
425 statement.BindInt64(3, itr->last_access_time.ToInternalValue());
426 statement.BindInt64(4, itr->last_modified_time.ToInternalValue());
427 EXPECT_TRUE(statement.Run());
431 bool OpenDatabase(sql::Connection* db, const base::FilePath& kDbFile) {
432 if (kDbFile.empty()) {
433 return db->OpenInMemory();
435 if (!base::CreateDirectory(kDbFile.DirName()))
436 return false;
437 if (!db->Open(kDbFile))
438 return false;
439 db->Preload();
440 return true;
443 // Create V2 database and populate some data.
444 void CreateV2Database(
445 const base::FilePath& kDbFile,
446 const QuotaTableEntry* entries,
447 size_t entries_size) {
448 scoped_ptr<sql::Connection> db(new sql::Connection);
449 scoped_ptr<sql::MetaTable> meta_table(new sql::MetaTable);
451 // V2 schema definitions.
452 static const int kCurrentVersion = 2;
453 static const int kCompatibleVersion = 2;
454 static const char kHostQuotaTable[] = "HostQuotaTable";
455 static const char kOriginLastAccessTable[] = "OriginLastAccessTable";
456 static const QuotaDatabase::TableSchema kTables[] = {
457 { kHostQuotaTable,
458 "(host TEXT NOT NULL,"
459 " type INTEGER NOT NULL,"
460 " quota INTEGER,"
461 " UNIQUE(host, type))" },
462 { kOriginLastAccessTable,
463 "(origin TEXT NOT NULL,"
464 " type INTEGER NOT NULL,"
465 " used_count INTEGER,"
466 " last_access_time INTEGER,"
467 " UNIQUE(origin, type))" },
469 static const QuotaDatabase::IndexSchema kIndexes[] = {
470 { "HostIndex",
471 kHostQuotaTable,
472 "(host)",
473 false },
474 { "OriginLastAccessIndex",
475 kOriginLastAccessTable,
476 "(origin, last_access_time)",
477 false },
480 ASSERT_TRUE(OpenDatabase(db.get(), kDbFile));
481 EXPECT_TRUE(QuotaDatabase::CreateSchema(
482 db.get(), meta_table.get(),
483 kCurrentVersion, kCompatibleVersion,
484 kTables, arraysize(kTables),
485 kIndexes, arraysize(kIndexes)));
487 // V2 and V3 QuotaTable are compatible, so we can simply use
488 // AssignQuotaTable to poplulate v2 database here.
489 db->BeginTransaction();
490 AssignQuotaTable(db.get(), entries, entries + entries_size);
491 db->CommitTransaction();
494 base::MessageLoop message_loop_;
497 TEST_F(QuotaDatabaseTest, LazyOpen) {
498 base::ScopedTempDir data_dir;
499 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
500 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
501 LazyOpen(kDbFile);
502 LazyOpen(base::FilePath());
505 TEST_F(QuotaDatabaseTest, UpgradeSchema) {
506 base::ScopedTempDir data_dir;
507 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
508 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
509 UpgradeSchemaV2toV3(kDbFile);
512 TEST_F(QuotaDatabaseTest, HostQuota) {
513 base::ScopedTempDir data_dir;
514 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
515 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
516 HostQuota(kDbFile);
517 HostQuota(base::FilePath());
520 TEST_F(QuotaDatabaseTest, GlobalQuota) {
521 base::ScopedTempDir data_dir;
522 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
523 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
524 GlobalQuota(kDbFile);
525 GlobalQuota(base::FilePath());
528 TEST_F(QuotaDatabaseTest, OriginLastAccessTimeLRU) {
529 base::ScopedTempDir data_dir;
530 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
531 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
532 OriginLastAccessTimeLRU(kDbFile);
533 OriginLastAccessTimeLRU(base::FilePath());
536 TEST_F(QuotaDatabaseTest, OriginLastModifiedSince) {
537 base::ScopedTempDir data_dir;
538 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
539 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
540 OriginLastModifiedSince(kDbFile);
541 OriginLastModifiedSince(base::FilePath());
544 TEST_F(QuotaDatabaseTest, BootstrapFlag) {
545 base::ScopedTempDir data_dir;
546 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
548 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
549 QuotaDatabase db(kDbFile);
551 EXPECT_FALSE(db.IsOriginDatabaseBootstrapped());
552 EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(true));
553 EXPECT_TRUE(db.IsOriginDatabaseBootstrapped());
554 EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(false));
555 EXPECT_FALSE(db.IsOriginDatabaseBootstrapped());
558 TEST_F(QuotaDatabaseTest, RegisterInitialOriginInfo) {
559 base::ScopedTempDir data_dir;
560 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
561 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
562 RegisterInitialOriginInfo(kDbFile);
563 RegisterInitialOriginInfo(base::FilePath());
566 TEST_F(QuotaDatabaseTest, DumpQuotaTable) {
567 base::ScopedTempDir data_dir;
568 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
569 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
570 DumpQuotaTable(kDbFile);
571 DumpQuotaTable(base::FilePath());
574 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) {
575 base::ScopedTempDir data_dir;
576 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
577 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
578 DumpOriginInfoTable(kDbFile);
579 DumpOriginInfoTable(base::FilePath());
582 TEST_F(QuotaDatabaseTest, OpenCorruptedDatabase) {
583 base::ScopedTempDir data_dir;
584 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
585 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
586 LazyOpen(kDbFile);
587 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile));
588 sql::ScopedErrorIgnorer ignore_errors;
589 ignore_errors.IgnoreError(SQLITE_CORRUPT);
590 Reopen(kDbFile);
591 EXPECT_TRUE(ignore_errors.CheckIgnoredErrors());
594 } // namespace content