Home | History | Annotate | Download | only in quota
      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.
      4 
      5 #include <algorithm>
      6 #include <iterator>
      7 #include <set>
      8 
      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/transaction.h"
     19 #include "storage/browser/quota/quota_database.h"
     20 #include "testing/gtest/include/gtest/gtest.h"
     21 #include "url/gurl.h"
     22 
     23 using storage::kStorageTypePersistent;
     24 using storage::kStorageTypeTemporary;
     25 using storage::QuotaDatabase;
     26 
     27 namespace content {
     28 namespace {
     29 
     30 const base::Time kZeroTime;
     31 
     32 const char kDBFileName[] = "quota_manager.db";
     33 
     34 }  // namespace
     35 
     36 class QuotaDatabaseTest : public testing::Test {
     37  protected:
     38   typedef QuotaDatabase::QuotaTableEntry QuotaTableEntry;
     39   typedef QuotaDatabase::QuotaTableCallback QuotaTableCallback;
     40   typedef QuotaDatabase::OriginInfoTableCallback
     41       OriginInfoTableCallback;
     42 
     43   void LazyOpen(const base::FilePath& kDbFile) {
     44     QuotaDatabase db(kDbFile);
     45     EXPECT_FALSE(db.LazyOpen(false));
     46     ASSERT_TRUE(db.LazyOpen(true));
     47     EXPECT_TRUE(db.db_.get());
     48     EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
     49   }
     50 
     51   void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) {
     52     const QuotaTableEntry entries[] = {
     53       QuotaTableEntry("a", kStorageTypeTemporary,  1),
     54       QuotaTableEntry("b", kStorageTypeTemporary,  2),
     55       QuotaTableEntry("c", kStorageTypePersistent, 3),
     56     };
     57 
     58     CreateV2Database(kDbFile, entries, ARRAYSIZE_UNSAFE(entries));
     59 
     60     QuotaDatabase db(kDbFile);
     61     EXPECT_TRUE(db.LazyOpen(true));
     62     EXPECT_TRUE(db.db_.get());
     63 
     64     typedef EntryVerifier<QuotaTableEntry> Verifier;
     65     Verifier verifier(entries, entries + ARRAYSIZE_UNSAFE(entries));
     66     EXPECT_TRUE(db.DumpQuotaTable(
     67         base::Bind(&Verifier::Run, base::Unretained(&verifier))));
     68     EXPECT_TRUE(verifier.table.empty());
     69   }
     70 
     71   void HostQuota(const base::FilePath& kDbFile) {
     72     QuotaDatabase db(kDbFile);
     73     ASSERT_TRUE(db.LazyOpen(true));
     74 
     75     const char* kHost = "foo.com";
     76     const int kQuota1 = 13579;
     77     const int kQuota2 = kQuota1 + 1024;
     78 
     79     int64 quota = -1;
     80     EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
     81     EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
     82 
     83     // Insert quota for temporary.
     84     EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota1));
     85     EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
     86     EXPECT_EQ(kQuota1, quota);
     87 
     88     // Update quota for temporary.
     89     EXPECT_TRUE(db.SetHostQuota(kHost, kStorageTypeTemporary, kQuota2));
     90     EXPECT_TRUE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
     91     EXPECT_EQ(kQuota2, quota);
     92 
     93     // Quota for persistent must not be updated.
     94     EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypePersistent, &quota));
     95 
     96     // Delete temporary storage quota.
     97     EXPECT_TRUE(db.DeleteHostQuota(kHost, kStorageTypeTemporary));
     98     EXPECT_FALSE(db.GetHostQuota(kHost, kStorageTypeTemporary, &quota));
     99   }
    100 
    101   void GlobalQuota(const base::FilePath& kDbFile) {
    102     QuotaDatabase db(kDbFile);
    103     ASSERT_TRUE(db.LazyOpen(true));
    104 
    105     const char* kTempQuotaKey = QuotaDatabase::kTemporaryQuotaOverrideKey;
    106     const char* kAvailSpaceKey = QuotaDatabase::kDesiredAvailableSpaceKey;
    107 
    108     int64 value = 0;
    109     const int64 kValue1 = 456;
    110     const int64 kValue2 = 123000;
    111     EXPECT_FALSE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
    112     EXPECT_FALSE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
    113 
    114     EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue1));
    115     EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
    116     EXPECT_EQ(kValue1, value);
    117 
    118     EXPECT_TRUE(db.SetQuotaConfigValue(kTempQuotaKey, kValue2));
    119     EXPECT_TRUE(db.GetQuotaConfigValue(kTempQuotaKey, &value));
    120     EXPECT_EQ(kValue2, value);
    121 
    122     EXPECT_TRUE(db.SetQuotaConfigValue(kAvailSpaceKey, kValue1));
    123     EXPECT_TRUE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
    124     EXPECT_EQ(kValue1, value);
    125 
    126     EXPECT_TRUE(db.SetQuotaConfigValue(kAvailSpaceKey, kValue2));
    127     EXPECT_TRUE(db.GetQuotaConfigValue(kAvailSpaceKey, &value));
    128     EXPECT_EQ(kValue2, value);
    129   }
    130 
    131   void OriginLastAccessTimeLRU(const base::FilePath& kDbFile) {
    132     QuotaDatabase db(kDbFile);
    133     ASSERT_TRUE(db.LazyOpen(true));
    134 
    135     std::set<GURL> exceptions;
    136     GURL origin;
    137     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    138                                 NULL, &origin));
    139     EXPECT_TRUE(origin.is_empty());
    140 
    141     const GURL kOrigin1("http://a/");
    142     const GURL kOrigin2("http://b/");
    143     const GURL kOrigin3("http://c/");
    144     const GURL kOrigin4("http://p/");
    145 
    146     // Adding three temporary storages, and
    147     EXPECT_TRUE(db.SetOriginLastAccessTime(
    148         kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
    149     EXPECT_TRUE(db.SetOriginLastAccessTime(
    150         kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
    151     EXPECT_TRUE(db.SetOriginLastAccessTime(
    152         kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(30)));
    153 
    154     // one persistent.
    155     EXPECT_TRUE(db.SetOriginLastAccessTime(
    156         kOrigin4, kStorageTypePersistent, base::Time::FromInternalValue(40)));
    157 
    158     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    159                                 NULL, &origin));
    160     EXPECT_EQ(kOrigin1.spec(), origin.spec());
    161 
    162     // Test that unlimited origins are exluded from eviction, but
    163     // protected origins are not excluded.
    164     scoped_refptr<MockSpecialStoragePolicy> policy(
    165         new MockSpecialStoragePolicy);
    166     policy->AddUnlimited(kOrigin1);
    167     policy->AddProtected(kOrigin2);
    168     EXPECT_TRUE(db.GetLRUOrigin(
    169         kStorageTypeTemporary, exceptions, policy.get(), &origin));
    170     EXPECT_EQ(kOrigin2.spec(), origin.spec());
    171 
    172     exceptions.insert(kOrigin1);
    173     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    174                                 NULL, &origin));
    175     EXPECT_EQ(kOrigin2.spec(), origin.spec());
    176 
    177     exceptions.insert(kOrigin2);
    178     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    179                                 NULL, &origin));
    180     EXPECT_EQ(kOrigin3.spec(), origin.spec());
    181 
    182     exceptions.insert(kOrigin3);
    183     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    184                                 NULL, &origin));
    185     EXPECT_TRUE(origin.is_empty());
    186 
    187     EXPECT_TRUE(db.SetOriginLastAccessTime(
    188         kOrigin1, kStorageTypeTemporary, base::Time::Now()));
    189 
    190     // Delete origin/type last access time information.
    191     EXPECT_TRUE(db.DeleteOriginInfo(kOrigin3, kStorageTypeTemporary));
    192 
    193     // Querying again to see if the deletion has worked.
    194     exceptions.clear();
    195     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    196                                 NULL, &origin));
    197     EXPECT_EQ(kOrigin2.spec(), origin.spec());
    198 
    199     exceptions.insert(kOrigin1);
    200     exceptions.insert(kOrigin2);
    201     EXPECT_TRUE(db.GetLRUOrigin(kStorageTypeTemporary, exceptions,
    202                                 NULL, &origin));
    203     EXPECT_TRUE(origin.is_empty());
    204   }
    205 
    206   void OriginLastModifiedSince(const base::FilePath& kDbFile) {
    207     QuotaDatabase db(kDbFile);
    208     ASSERT_TRUE(db.LazyOpen(true));
    209 
    210     std::set<GURL> origins;
    211     EXPECT_TRUE(db.GetOriginsModifiedSince(
    212         kStorageTypeTemporary, &origins, base::Time()));
    213     EXPECT_TRUE(origins.empty());
    214 
    215     const GURL kOrigin1("http://a/");
    216     const GURL kOrigin2("http://b/");
    217     const GURL kOrigin3("http://c/");
    218 
    219     // Report last mod time for the test origins.
    220     EXPECT_TRUE(db.SetOriginLastModifiedTime(
    221         kOrigin1, kStorageTypeTemporary, base::Time::FromInternalValue(0)));
    222     EXPECT_TRUE(db.SetOriginLastModifiedTime(
    223         kOrigin2, kStorageTypeTemporary, base::Time::FromInternalValue(10)));
    224     EXPECT_TRUE(db.SetOriginLastModifiedTime(
    225         kOrigin3, kStorageTypeTemporary, base::Time::FromInternalValue(20)));
    226 
    227     EXPECT_TRUE(db.GetOriginsModifiedSince(
    228         kStorageTypeTemporary, &origins, base::Time()));
    229     EXPECT_EQ(3U, origins.size());
    230     EXPECT_EQ(1U, origins.count(kOrigin1));
    231     EXPECT_EQ(1U, origins.count(kOrigin2));
    232     EXPECT_EQ(1U, origins.count(kOrigin3));
    233 
    234     EXPECT_TRUE(db.GetOriginsModifiedSince(
    235         kStorageTypeTemporary, &origins, base::Time::FromInternalValue(5)));
    236     EXPECT_EQ(2U, origins.size());
    237     EXPECT_EQ(0U, origins.count(kOrigin1));
    238     EXPECT_EQ(1U, origins.count(kOrigin2));
    239     EXPECT_EQ(1U, origins.count(kOrigin3));
    240 
    241     EXPECT_TRUE(db.GetOriginsModifiedSince(
    242         kStorageTypeTemporary, &origins, base::Time::FromInternalValue(15)));
    243     EXPECT_EQ(1U, origins.size());
    244     EXPECT_EQ(0U, origins.count(kOrigin1));
    245     EXPECT_EQ(0U, origins.count(kOrigin2));
    246     EXPECT_EQ(1U, origins.count(kOrigin3));
    247 
    248     EXPECT_TRUE(db.GetOriginsModifiedSince(
    249         kStorageTypeTemporary, &origins, base::Time::FromInternalValue(25)));
    250     EXPECT_TRUE(origins.empty());
    251 
    252     // Update origin1's mod time but for persistent storage.
    253     EXPECT_TRUE(db.SetOriginLastModifiedTime(
    254         kOrigin1, kStorageTypePersistent, base::Time::FromInternalValue(30)));
    255 
    256     // Must have no effects on temporary origins info.
    257     EXPECT_TRUE(db.GetOriginsModifiedSince(
    258         kStorageTypeTemporary, &origins, base::Time::FromInternalValue(5)));
    259     EXPECT_EQ(2U, origins.size());
    260     EXPECT_EQ(0U, origins.count(kOrigin1));
    261     EXPECT_EQ(1U, origins.count(kOrigin2));
    262     EXPECT_EQ(1U, origins.count(kOrigin3));
    263 
    264     // One more update for persistent origin2.
    265     EXPECT_TRUE(db.SetOriginLastModifiedTime(
    266         kOrigin2, kStorageTypePersistent, base::Time::FromInternalValue(40)));
    267 
    268     EXPECT_TRUE(db.GetOriginsModifiedSince(
    269         kStorageTypePersistent, &origins, base::Time::FromInternalValue(25)));
    270     EXPECT_EQ(2U, origins.size());
    271     EXPECT_EQ(1U, origins.count(kOrigin1));
    272     EXPECT_EQ(1U, origins.count(kOrigin2));
    273     EXPECT_EQ(0U, origins.count(kOrigin3));
    274 
    275     EXPECT_TRUE(db.GetOriginsModifiedSince(
    276         kStorageTypePersistent, &origins, base::Time::FromInternalValue(35)));
    277     EXPECT_EQ(1U, origins.size());
    278     EXPECT_EQ(0U, origins.count(kOrigin1));
    279     EXPECT_EQ(1U, origins.count(kOrigin2));
    280     EXPECT_EQ(0U, origins.count(kOrigin3));
    281   }
    282 
    283   void RegisterInitialOriginInfo(const base::FilePath& kDbFile) {
    284     QuotaDatabase db(kDbFile);
    285 
    286     const GURL kOrigins[] = {
    287       GURL("http://a/"),
    288       GURL("http://b/"),
    289       GURL("http://c/") };
    290     std::set<GURL> origins(kOrigins, kOrigins + ARRAYSIZE_UNSAFE(kOrigins));
    291 
    292     EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary));
    293 
    294     int used_count = -1;
    295     EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
    296                                        kStorageTypeTemporary,
    297                                        &used_count));
    298     EXPECT_EQ(0, used_count);
    299 
    300     EXPECT_TRUE(db.SetOriginLastAccessTime(
    301         GURL("http://a/"), kStorageTypeTemporary,
    302         base::Time::FromDoubleT(1.0)));
    303     used_count = -1;
    304     EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
    305                                        kStorageTypeTemporary,
    306                                        &used_count));
    307     EXPECT_EQ(1, used_count);
    308 
    309     EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary));
    310 
    311     used_count = -1;
    312     EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
    313                                        kStorageTypeTemporary,
    314                                        &used_count));
    315     EXPECT_EQ(1, used_count);
    316   }
    317 
    318   template <typename EntryType>
    319   struct EntryVerifier {
    320     std::set<EntryType> table;
    321 
    322     template <typename Iterator>
    323     EntryVerifier(Iterator itr, Iterator end)
    324         : table(itr, end) {}
    325 
    326     bool Run(const EntryType& entry) {
    327       EXPECT_EQ(1u, table.erase(entry));
    328       return true;
    329     }
    330   };
    331 
    332   void DumpQuotaTable(const base::FilePath& kDbFile) {
    333     QuotaTableEntry kTableEntries[] = {
    334       QuotaTableEntry("http://go/", kStorageTypeTemporary, 1),
    335       QuotaTableEntry("http://oo/", kStorageTypeTemporary, 2),
    336       QuotaTableEntry("http://gle/", kStorageTypePersistent, 3)
    337     };
    338     QuotaTableEntry* begin = kTableEntries;
    339     QuotaTableEntry* end = kTableEntries + ARRAYSIZE_UNSAFE(kTableEntries);
    340 
    341     QuotaDatabase db(kDbFile);
    342     EXPECT_TRUE(db.LazyOpen(true));
    343     AssignQuotaTable(db.db_.get(), begin, end);
    344     db.Commit();
    345 
    346     typedef EntryVerifier<QuotaTableEntry> Verifier;
    347     Verifier verifier(begin, end);
    348     EXPECT_TRUE(db.DumpQuotaTable(
    349         base::Bind(&Verifier::Run, base::Unretained(&verifier))));
    350     EXPECT_TRUE(verifier.table.empty());
    351   }
    352 
    353   void DumpOriginInfoTable(const base::FilePath& kDbFile) {
    354     base::Time now(base::Time::Now());
    355     typedef QuotaDatabase::OriginInfoTableEntry Entry;
    356     Entry kTableEntries[] = {
    357       Entry(GURL("http://go/"), kStorageTypeTemporary, 2147483647, now, now),
    358       Entry(GURL("http://oo/"), kStorageTypeTemporary, 0, now, now),
    359       Entry(GURL("http://gle/"), kStorageTypeTemporary, 1, now, now),
    360     };
    361     Entry* begin = kTableEntries;
    362     Entry* end = kTableEntries + ARRAYSIZE_UNSAFE(kTableEntries);
    363 
    364     QuotaDatabase db(kDbFile);
    365     EXPECT_TRUE(db.LazyOpen(true));
    366     AssignOriginInfoTable(db.db_.get(), begin, end);
    367     db.Commit();
    368 
    369     typedef EntryVerifier<Entry> Verifier;
    370     Verifier verifier(begin, end);
    371     EXPECT_TRUE(db.DumpOriginInfoTable(
    372         base::Bind(&Verifier::Run, base::Unretained(&verifier))));
    373     EXPECT_TRUE(verifier.table.empty());
    374   }
    375 
    376  private:
    377   template <typename Iterator>
    378   void AssignQuotaTable(sql::Connection* db, Iterator itr, Iterator end) {
    379     ASSERT_NE(db, (sql::Connection*)NULL);
    380     for (; itr != end; ++itr) {
    381       const char* kSql =
    382           "INSERT INTO HostQuotaTable"
    383           " (host, type, quota)"
    384           " VALUES (?, ?, ?)";
    385       sql::Statement statement;
    386       statement.Assign(db->GetCachedStatement(SQL_FROM_HERE, kSql));
    387       ASSERT_TRUE(statement.is_valid());
    388 
    389       statement.BindString(0, itr->host);
    390       statement.BindInt(1, static_cast<int>(itr->type));
    391       statement.BindInt64(2, itr->quota);
    392       EXPECT_TRUE(statement.Run());
    393     }
    394   }
    395 
    396   template <typename Iterator>
    397   void AssignOriginInfoTable(sql::Connection* db, Iterator itr, Iterator end) {
    398     ASSERT_NE(db, (sql::Connection*)NULL);
    399     for (; itr != end; ++itr) {
    400       const char* kSql =
    401           "INSERT INTO OriginInfoTable"
    402           " (origin, type, used_count, last_access_time, last_modified_time)"
    403           " VALUES (?, ?, ?, ?, ?)";
    404       sql::Statement statement;
    405       statement.Assign(db->GetCachedStatement(SQL_FROM_HERE, kSql));
    406       ASSERT_TRUE(statement.is_valid());
    407 
    408       statement.BindString(0, itr->origin.spec());
    409       statement.BindInt(1, static_cast<int>(itr->type));
    410       statement.BindInt(2, itr->used_count);
    411       statement.BindInt64(3, itr->last_access_time.ToInternalValue());
    412       statement.BindInt64(4, itr->last_modified_time.ToInternalValue());
    413       EXPECT_TRUE(statement.Run());
    414     }
    415   }
    416 
    417   bool OpenDatabase(sql::Connection* db, const base::FilePath& kDbFile) {
    418     if (kDbFile.empty()) {
    419       return db->OpenInMemory();
    420     }
    421     if (!base::CreateDirectory(kDbFile.DirName()))
    422       return false;
    423     if (!db->Open(kDbFile))
    424       return false;
    425     db->Preload();
    426     return true;
    427   }
    428 
    429   // Create V2 database and populate some data.
    430   void CreateV2Database(
    431       const base::FilePath& kDbFile,
    432       const QuotaTableEntry* entries,
    433       size_t entries_size) {
    434     scoped_ptr<sql::Connection> db(new sql::Connection);
    435     scoped_ptr<sql::MetaTable> meta_table(new sql::MetaTable);
    436 
    437     // V2 schema definitions.
    438     static const int kCurrentVersion = 2;
    439     static const int kCompatibleVersion = 2;
    440     static const char kHostQuotaTable[] = "HostQuotaTable";
    441     static const char kOriginLastAccessTable[] = "OriginLastAccessTable";
    442     static const QuotaDatabase::TableSchema kTables[] = {
    443       { kHostQuotaTable,
    444         "(host TEXT NOT NULL,"
    445         " type INTEGER NOT NULL,"
    446         " quota INTEGER,"
    447         " UNIQUE(host, type))" },
    448       { kOriginLastAccessTable,
    449         "(origin TEXT NOT NULL,"
    450         " type INTEGER NOT NULL,"
    451         " used_count INTEGER,"
    452         " last_access_time INTEGER,"
    453         " UNIQUE(origin, type))" },
    454     };
    455     static const QuotaDatabase::IndexSchema kIndexes[] = {
    456       { "HostIndex",
    457         kHostQuotaTable,
    458         "(host)",
    459         false },
    460       { "OriginLastAccessIndex",
    461         kOriginLastAccessTable,
    462         "(origin, last_access_time)",
    463         false },
    464     };
    465 
    466     ASSERT_TRUE(OpenDatabase(db.get(), kDbFile));
    467     EXPECT_TRUE(QuotaDatabase::CreateSchema(
    468             db.get(), meta_table.get(),
    469             kCurrentVersion, kCompatibleVersion,
    470             kTables, ARRAYSIZE_UNSAFE(kTables),
    471             kIndexes, ARRAYSIZE_UNSAFE(kIndexes)));
    472 
    473     // V2 and V3 QuotaTable are compatible, so we can simply use
    474     // AssignQuotaTable to poplulate v2 database here.
    475     db->BeginTransaction();
    476     AssignQuotaTable(db.get(), entries, entries + entries_size);
    477     db->CommitTransaction();
    478   }
    479 
    480   base::MessageLoop message_loop_;
    481 };
    482 
    483 TEST_F(QuotaDatabaseTest, LazyOpen) {
    484   base::ScopedTempDir data_dir;
    485   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    486   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    487   LazyOpen(kDbFile);
    488   LazyOpen(base::FilePath());
    489 }
    490 
    491 TEST_F(QuotaDatabaseTest, UpgradeSchema) {
    492   base::ScopedTempDir data_dir;
    493   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    494   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    495   UpgradeSchemaV2toV3(kDbFile);
    496 }
    497 
    498 TEST_F(QuotaDatabaseTest, HostQuota) {
    499   base::ScopedTempDir data_dir;
    500   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    501   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    502   HostQuota(kDbFile);
    503   HostQuota(base::FilePath());
    504 }
    505 
    506 TEST_F(QuotaDatabaseTest, GlobalQuota) {
    507   base::ScopedTempDir data_dir;
    508   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    509   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    510   GlobalQuota(kDbFile);
    511   GlobalQuota(base::FilePath());
    512 }
    513 
    514 TEST_F(QuotaDatabaseTest, OriginLastAccessTimeLRU) {
    515   base::ScopedTempDir data_dir;
    516   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    517   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    518   OriginLastAccessTimeLRU(kDbFile);
    519   OriginLastAccessTimeLRU(base::FilePath());
    520 }
    521 
    522 TEST_F(QuotaDatabaseTest, OriginLastModifiedSince) {
    523   base::ScopedTempDir data_dir;
    524   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    525   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    526   OriginLastModifiedSince(kDbFile);
    527   OriginLastModifiedSince(base::FilePath());
    528 }
    529 
    530 TEST_F(QuotaDatabaseTest, BootstrapFlag) {
    531   base::ScopedTempDir data_dir;
    532   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    533 
    534   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    535   QuotaDatabase db(kDbFile);
    536 
    537   EXPECT_FALSE(db.IsOriginDatabaseBootstrapped());
    538   EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(true));
    539   EXPECT_TRUE(db.IsOriginDatabaseBootstrapped());
    540   EXPECT_TRUE(db.SetOriginDatabaseBootstrapped(false));
    541   EXPECT_FALSE(db.IsOriginDatabaseBootstrapped());
    542 }
    543 
    544 TEST_F(QuotaDatabaseTest, RegisterInitialOriginInfo) {
    545   base::ScopedTempDir data_dir;
    546   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    547   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    548   RegisterInitialOriginInfo(kDbFile);
    549   RegisterInitialOriginInfo(base::FilePath());
    550 }
    551 
    552 TEST_F(QuotaDatabaseTest, DumpQuotaTable) {
    553   base::ScopedTempDir data_dir;
    554   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    555   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    556   DumpQuotaTable(kDbFile);
    557   DumpQuotaTable(base::FilePath());
    558 }
    559 
    560 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) {
    561   base::ScopedTempDir data_dir;
    562   ASSERT_TRUE(data_dir.CreateUniqueTempDir());
    563   const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
    564   DumpOriginInfoTable(kDbFile);
    565   DumpOriginInfoTable(base::FilePath());
    566 }
    567 }  // namespace content
    568