Home | History | Annotate | Download | only in fileapi
      1 // Copyright 2013 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 "base/basictypes.h"
      6 #include "base/bind.h"
      7 #include "base/files/file_util.h"
      8 #include "base/files/scoped_temp_dir.h"
      9 #include "base/message_loop/message_loop_proxy.h"
     10 #include "base/run_loop.h"
     11 #include "content/public/test/async_file_test_helper.h"
     12 #include "content/public/test/test_file_system_context.h"
     13 #include "storage/browser/fileapi/file_system_context.h"
     14 #include "storage/browser/fileapi/file_system_quota_client.h"
     15 #include "storage/browser/fileapi/file_system_usage_cache.h"
     16 #include "storage/browser/fileapi/obfuscated_file_util.h"
     17 #include "storage/common/fileapi/file_system_types.h"
     18 #include "storage/common/fileapi/file_system_util.h"
     19 #include "storage/common/quota/quota_types.h"
     20 #include "testing/gtest/include/gtest/gtest.h"
     21 #include "url/gurl.h"
     22 
     23 using content::AsyncFileTestHelper;
     24 using storage::FileSystemQuotaClient;
     25 using storage::FileSystemURL;
     26 
     27 namespace content {
     28 namespace {
     29 
     30 const char kDummyURL1[] = "http://www.dummy.org";
     31 const char kDummyURL2[] = "http://www.example.com";
     32 const char kDummyURL3[] = "http://www.bleh";
     33 
     34 // Declared to shorten the variable names.
     35 const storage::StorageType kTemporary = storage::kStorageTypeTemporary;
     36 const storage::StorageType kPersistent = storage::kStorageTypePersistent;
     37 
     38 }  // namespace
     39 
     40 class FileSystemQuotaClientTest : public testing::Test {
     41  public:
     42   FileSystemQuotaClientTest()
     43       : weak_factory_(this),
     44         additional_callback_count_(0),
     45         deletion_status_(storage::kQuotaStatusUnknown) {}
     46 
     47   virtual void SetUp() {
     48     ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
     49     file_system_context_ = CreateFileSystemContextForTesting(
     50             NULL, data_dir_.path());
     51   }
     52 
     53   struct TestFile {
     54     bool isDirectory;
     55     const char* name;
     56     int64 size;
     57     const char* origin_url;
     58     storage::StorageType type;
     59   };
     60 
     61  protected:
     62   FileSystemQuotaClient* NewQuotaClient(bool is_incognito) {
     63     return new FileSystemQuotaClient(file_system_context_.get(), is_incognito);
     64   }
     65 
     66   void GetOriginUsageAsync(FileSystemQuotaClient* quota_client,
     67                            const std::string& origin_url,
     68                            storage::StorageType type) {
     69     quota_client->GetOriginUsage(
     70         GURL(origin_url), type,
     71         base::Bind(&FileSystemQuotaClientTest::OnGetUsage,
     72                    weak_factory_.GetWeakPtr()));
     73   }
     74 
     75   int64 GetOriginUsage(FileSystemQuotaClient* quota_client,
     76                        const std::string& origin_url,
     77                        storage::StorageType type) {
     78     GetOriginUsageAsync(quota_client, origin_url, type);
     79     base::RunLoop().RunUntilIdle();
     80     return usage_;
     81   }
     82 
     83   const std::set<GURL>& GetOriginsForType(FileSystemQuotaClient* quota_client,
     84                                           storage::StorageType type) {
     85     origins_.clear();
     86     quota_client->GetOriginsForType(
     87         type,
     88         base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
     89                    weak_factory_.GetWeakPtr()));
     90     base::RunLoop().RunUntilIdle();
     91     return origins_;
     92   }
     93 
     94   const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client,
     95                                           storage::StorageType type,
     96                                           const std::string& host) {
     97     origins_.clear();
     98     quota_client->GetOriginsForHost(
     99         type, host,
    100         base::Bind(&FileSystemQuotaClientTest::OnGetOrigins,
    101                    weak_factory_.GetWeakPtr()));
    102     base::RunLoop().RunUntilIdle();
    103     return origins_;
    104   }
    105 
    106   void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client,
    107                                     const std::string& origin_url,
    108                                     storage::StorageType type) {
    109     quota_client->GetOriginUsage(
    110         GURL(origin_url), type,
    111         base::Bind(&FileSystemQuotaClientTest::OnGetAdditionalUsage,
    112                    weak_factory_.GetWeakPtr()));
    113   }
    114 
    115   bool CreateFileSystemDirectory(const base::FilePath& file_path,
    116                                  const std::string& origin_url,
    117                                  storage::StorageType storage_type) {
    118     storage::FileSystemType type =
    119         storage::QuotaStorageTypeToFileSystemType(storage_type);
    120     FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
    121         GURL(origin_url), type, file_path);
    122 
    123     base::File::Error result =
    124         AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), url);
    125     return result == base::File::FILE_OK;
    126   }
    127 
    128   bool CreateFileSystemFile(const base::FilePath& file_path,
    129                             int64 file_size,
    130                             const std::string& origin_url,
    131                             storage::StorageType storage_type) {
    132     if (file_path.empty())
    133       return false;
    134 
    135     storage::FileSystemType type =
    136         storage::QuotaStorageTypeToFileSystemType(storage_type);
    137     FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
    138         GURL(origin_url), type, file_path);
    139 
    140     base::File::Error result =
    141         AsyncFileTestHelper::CreateFile(file_system_context_.get(), url);
    142     if (result != base::File::FILE_OK)
    143       return false;
    144 
    145     result = AsyncFileTestHelper::TruncateFile(
    146         file_system_context_.get(), url, file_size);
    147     return result == base::File::FILE_OK;
    148   }
    149 
    150   void InitializeOriginFiles(FileSystemQuotaClient* quota_client,
    151                              const TestFile* files,
    152                              int num_files) {
    153     for (int i = 0; i < num_files; i++) {
    154       base::FilePath path = base::FilePath().AppendASCII(files[i].name);
    155       if (files[i].isDirectory) {
    156         ASSERT_TRUE(CreateFileSystemDirectory(
    157             path, files[i].origin_url, files[i].type));
    158         if (path.empty()) {
    159           // Create the usage cache.
    160           // HACK--we always create the root [an empty path] first.  If we
    161           // create it later, this will fail due to a quota mismatch.  If we
    162           // call this before we create the root, it succeeds, but hasn't
    163           // actually created the cache.
    164           ASSERT_EQ(0, GetOriginUsage(
    165               quota_client, files[i].origin_url, files[i].type));
    166         }
    167       } else {
    168         ASSERT_TRUE(CreateFileSystemFile(
    169             path, files[i].size, files[i].origin_url, files[i].type));
    170       }
    171     }
    172   }
    173 
    174   // This is a bit fragile--it depends on the test data always creating a
    175   // directory before adding a file or directory to it, so that we can just
    176   // count the basename of each addition.  A recursive creation of a path, which
    177   // created more than one directory in a single shot, would break this.
    178   int64 ComputeFilePathsCostForOriginAndType(const TestFile* files,
    179                                              int num_files,
    180                                              const std::string& origin_url,
    181                                              storage::StorageType type) {
    182     int64 file_paths_cost = 0;
    183     for (int i = 0; i < num_files; i++) {
    184       if (files[i].type == type &&
    185           GURL(files[i].origin_url) == GURL(origin_url)) {
    186         base::FilePath path = base::FilePath().AppendASCII(files[i].name);
    187         if (!path.empty()) {
    188           file_paths_cost +=
    189               storage::ObfuscatedFileUtil::ComputeFilePathCost(path);
    190         }
    191       }
    192     }
    193     return file_paths_cost;
    194   }
    195 
    196   void DeleteOriginData(FileSystemQuotaClient* quota_client,
    197                         const std::string& origin,
    198                         storage::StorageType type) {
    199     deletion_status_ = storage::kQuotaStatusUnknown;
    200     quota_client->DeleteOriginData(
    201         GURL(origin), type,
    202         base::Bind(&FileSystemQuotaClientTest::OnDeleteOrigin,
    203                    weak_factory_.GetWeakPtr()));
    204   }
    205 
    206   int64 usage() const { return usage_; }
    207   storage::QuotaStatusCode status() { return deletion_status_; }
    208   int additional_callback_count() const { return additional_callback_count_; }
    209   void set_additional_callback_count(int count) {
    210     additional_callback_count_ = count;
    211   }
    212 
    213  private:
    214   void OnGetUsage(int64 usage) {
    215     usage_ = usage;
    216   }
    217 
    218   void OnGetOrigins(const std::set<GURL>& origins) {
    219     origins_ = origins;
    220   }
    221 
    222   void OnGetAdditionalUsage(int64 usage_unused) {
    223     ++additional_callback_count_;
    224   }
    225 
    226   void OnDeleteOrigin(storage::QuotaStatusCode status) {
    227     deletion_status_ = status;
    228   }
    229 
    230   base::ScopedTempDir data_dir_;
    231   base::MessageLoop message_loop_;
    232   scoped_refptr<storage::FileSystemContext> file_system_context_;
    233   base::WeakPtrFactory<FileSystemQuotaClientTest> weak_factory_;
    234   int64 usage_;
    235   int additional_callback_count_;
    236   std::set<GURL> origins_;
    237   storage::QuotaStatusCode deletion_status_;
    238 
    239   DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest);
    240 };
    241 
    242 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) {
    243   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    244 
    245   EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    246 }
    247 
    248 TEST_F(FileSystemQuotaClientTest, NoFileTest) {
    249   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    250   const TestFile kFiles[] = {
    251     {true, NULL, 0, kDummyURL1, kTemporary},
    252   };
    253   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    254 
    255   for (int i = 0; i < 2; i++) {
    256     EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    257   }
    258 }
    259 
    260 TEST_F(FileSystemQuotaClientTest, OneFileTest) {
    261   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    262   const TestFile kFiles[] = {
    263     {true, NULL, 0, kDummyURL1, kTemporary},
    264     {false, "foo", 4921, kDummyURL1, kTemporary},
    265   };
    266   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    267   const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
    268       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    269 
    270   for (int i = 0; i < 2; i++) {
    271     EXPECT_EQ(4921 + file_paths_cost,
    272         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    273   }
    274 }
    275 
    276 TEST_F(FileSystemQuotaClientTest, TwoFilesTest) {
    277   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    278   const TestFile kFiles[] = {
    279     {true, NULL, 0, kDummyURL1, kTemporary},
    280     {false, "foo", 10310, kDummyURL1, kTemporary},
    281     {false, "bar", 41, kDummyURL1, kTemporary},
    282   };
    283   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    284   const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
    285       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    286 
    287   for (int i = 0; i < 2; i++) {
    288     EXPECT_EQ(10310 + 41 + file_paths_cost,
    289         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    290   }
    291 }
    292 
    293 TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) {
    294   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    295   const TestFile kFiles[] = {
    296     {true, NULL, 0, kDummyURL1, kTemporary},
    297     {false, "foo", 0, kDummyURL1, kTemporary},
    298     {false, "bar", 0, kDummyURL1, kTemporary},
    299     {false, "baz", 0, kDummyURL1, kTemporary},
    300   };
    301   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    302   const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
    303       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    304 
    305   for (int i = 0; i < 2; i++) {
    306     EXPECT_EQ(file_paths_cost,
    307         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    308   }
    309 }
    310 
    311 TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) {
    312   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    313   const TestFile kFiles[] = {
    314     {true, NULL, 0, kDummyURL1, kTemporary},
    315     {true, "dirtest", 0, kDummyURL1, kTemporary},
    316     {false, "dirtest/foo", 11921, kDummyURL1, kTemporary},
    317     {false, "bar", 4814, kDummyURL1, kTemporary},
    318   };
    319   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    320   const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
    321       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    322 
    323   for (int i = 0; i < 2; i++) {
    324     EXPECT_EQ(11921 + 4814 + file_paths_cost,
    325         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    326   }
    327 }
    328 
    329 TEST_F(FileSystemQuotaClientTest, MultiTypeTest) {
    330   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    331   const TestFile kFiles[] = {
    332     {true, NULL, 0, kDummyURL1, kTemporary},
    333     {true, "dirtest", 0, kDummyURL1, kTemporary},
    334     {false, "dirtest/foo", 133, kDummyURL1, kTemporary},
    335     {false, "bar", 14, kDummyURL1, kTemporary},
    336     {true, NULL, 0, kDummyURL1, kPersistent},
    337     {true, "dirtest", 0, kDummyURL1, kPersistent},
    338     {false, "dirtest/foo", 193, kDummyURL1, kPersistent},
    339     {false, "bar", 9, kDummyURL1, kPersistent},
    340   };
    341   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    342   const int64 file_paths_cost_temporary = ComputeFilePathsCostForOriginAndType(
    343       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    344   const int64 file_paths_cost_persistent = ComputeFilePathsCostForOriginAndType(
    345       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    346 
    347   for (int i = 0; i < 2; i++) {
    348     EXPECT_EQ(133 + 14 + file_paths_cost_temporary,
    349         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    350     EXPECT_EQ(193 + 9 + file_paths_cost_persistent,
    351         GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
    352   }
    353 }
    354 
    355 TEST_F(FileSystemQuotaClientTest, MultiDomainTest) {
    356   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    357   const TestFile kFiles[] = {
    358     {true, NULL, 0, kDummyURL1, kTemporary},
    359     {true, "dir1", 0, kDummyURL1, kTemporary},
    360     {false, "dir1/foo", 1331, kDummyURL1, kTemporary},
    361     {false, "bar", 134, kDummyURL1, kTemporary},
    362     {true, NULL, 0, kDummyURL1, kPersistent},
    363     {true, "dir2", 0, kDummyURL1, kPersistent},
    364     {false, "dir2/foo", 1903, kDummyURL1, kPersistent},
    365     {false, "bar", 19, kDummyURL1, kPersistent},
    366     {true, NULL, 0, kDummyURL2, kTemporary},
    367     {true, "dom", 0, kDummyURL2, kTemporary},
    368     {false, "dom/fan", 1319, kDummyURL2, kTemporary},
    369     {false, "bar", 113, kDummyURL2, kTemporary},
    370     {true, NULL, 0, kDummyURL2, kPersistent},
    371     {true, "dom", 0, kDummyURL2, kPersistent},
    372     {false, "dom/fan", 2013, kDummyURL2, kPersistent},
    373     {false, "baz", 18, kDummyURL2, kPersistent},
    374   };
    375   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    376   const int64 file_paths_cost_temporary1 = ComputeFilePathsCostForOriginAndType(
    377       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    378   const int64 file_paths_cost_persistent1 =
    379       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    380           kDummyURL1, kPersistent);
    381   const int64 file_paths_cost_temporary2 = ComputeFilePathsCostForOriginAndType(
    382       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL2, kTemporary);
    383   const int64 file_paths_cost_persistent2 =
    384       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    385           kDummyURL2, kPersistent);
    386 
    387   for (int i = 0; i < 2; i++) {
    388     EXPECT_EQ(1331 + 134 + file_paths_cost_temporary1,
    389         GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    390     EXPECT_EQ(1903 + 19 + file_paths_cost_persistent1,
    391         GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
    392     EXPECT_EQ(1319 + 113 + file_paths_cost_temporary2,
    393         GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary));
    394     EXPECT_EQ(2013 + 18 + file_paths_cost_persistent2,
    395         GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent));
    396   }
    397 }
    398 
    399 TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
    400   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    401   const TestFile kFiles[] = {
    402     {true, NULL, 0, kDummyURL1, kTemporary},
    403     {false, "foo",   11, kDummyURL1, kTemporary},
    404     {false, "bar",   22, kDummyURL1, kTemporary},
    405   };
    406   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    407   const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
    408       kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
    409 
    410   // Dispatching three GetUsage tasks.
    411   set_additional_callback_count(0);
    412   GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary);
    413   RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
    414   RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
    415   base::RunLoop().RunUntilIdle();
    416   EXPECT_EQ(11 + 22 + file_paths_cost, usage());
    417   EXPECT_EQ(2, additional_callback_count());
    418 
    419   // Once more, in a different order.
    420   set_additional_callback_count(0);
    421   RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
    422   GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary);
    423   RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
    424   base::RunLoop().RunUntilIdle();
    425   EXPECT_EQ(11 + 22 + file_paths_cost, usage());
    426   EXPECT_EQ(2, additional_callback_count());
    427 }
    428 
    429 TEST_F(FileSystemQuotaClientTest, GetOriginsForType) {
    430   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    431   const TestFile kFiles[] = {
    432     {true, NULL, 0, kDummyURL1, kTemporary},
    433     {true, NULL, 0, kDummyURL2, kTemporary},
    434     {true, NULL, 0, kDummyURL3, kPersistent},
    435   };
    436   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    437 
    438   std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary);
    439   EXPECT_EQ(2U, origins.size());
    440   EXPECT_TRUE(origins.find(GURL(kDummyURL1)) != origins.end());
    441   EXPECT_TRUE(origins.find(GURL(kDummyURL2)) != origins.end());
    442   EXPECT_TRUE(origins.find(GURL(kDummyURL3)) == origins.end());
    443 }
    444 
    445 TEST_F(FileSystemQuotaClientTest, GetOriginsForHost) {
    446   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    447   const char* kURL1 = "http://foo.com/";
    448   const char* kURL2 = "https://foo.com/";
    449   const char* kURL3 = "http://foo.com:1/";
    450   const char* kURL4 = "http://foo2.com/";
    451   const char* kURL5 = "http://foo.com:2/";
    452   const TestFile kFiles[] = {
    453     {true, NULL, 0, kURL1, kTemporary},
    454     {true, NULL, 0, kURL2, kTemporary},
    455     {true, NULL, 0, kURL3, kTemporary},
    456     {true, NULL, 0, kURL4, kTemporary},
    457     {true, NULL, 0, kURL5, kPersistent},
    458   };
    459   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    460 
    461   std::set<GURL> origins = GetOriginsForHost(
    462       quota_client.get(), kTemporary, "foo.com");
    463   EXPECT_EQ(3U, origins.size());
    464   EXPECT_TRUE(origins.find(GURL(kURL1)) != origins.end());
    465   EXPECT_TRUE(origins.find(GURL(kURL2)) != origins.end());
    466   EXPECT_TRUE(origins.find(GURL(kURL3)) != origins.end());
    467   EXPECT_TRUE(origins.find(GURL(kURL4)) == origins.end());  // Different host.
    468   EXPECT_TRUE(origins.find(GURL(kURL5)) == origins.end());  // Different type.
    469 }
    470 
    471 TEST_F(FileSystemQuotaClientTest, IncognitoTest) {
    472   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(true));
    473   const TestFile kFiles[] = {
    474     {true, NULL, 0, kDummyURL1, kTemporary},
    475     {false, "foo", 10, kDummyURL1, kTemporary},
    476   };
    477   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    478 
    479   // Having files in the usual directory wouldn't affect the result
    480   // queried in incognito mode.
    481   EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
    482   EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
    483 
    484   std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary);
    485   EXPECT_EQ(0U, origins.size());
    486   origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org");
    487   EXPECT_EQ(0U, origins.size());
    488 }
    489 
    490 TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) {
    491   scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
    492   const TestFile kFiles[] = {
    493     {true, NULL,  0, "http://foo.com/",  kTemporary},
    494     {false, "a",  1, "http://foo.com/",  kTemporary},
    495     {true, NULL,  0, "https://foo.com/", kTemporary},
    496     {false, "b",  2, "https://foo.com/", kTemporary},
    497     {true, NULL,  0, "http://foo.com/",  kPersistent},
    498     {false, "c",  4, "http://foo.com/",  kPersistent},
    499     {true, NULL,  0, "http://bar.com/",  kTemporary},
    500     {false, "d",  8, "http://bar.com/",  kTemporary},
    501     {true, NULL,  0, "http://bar.com/",  kPersistent},
    502     {false, "e", 16, "http://bar.com/",  kPersistent},
    503     {true, NULL,  0, "https://bar.com/", kPersistent},
    504     {false, "f", 32, "https://bar.com/", kPersistent},
    505     {true, NULL,  0, "https://bar.com/", kTemporary},
    506     {false, "g", 64, "https://bar.com/", kTemporary},
    507   };
    508   InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
    509   const int64 file_paths_cost_temporary_foo_https =
    510       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    511           "https://foo.com/", kTemporary);
    512   const int64 file_paths_cost_persistent_foo =
    513       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    514           "http://foo.com/", kPersistent);
    515   const int64 file_paths_cost_temporary_bar =
    516       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    517           "http://bar.com/", kTemporary);
    518   const int64 file_paths_cost_temporary_bar_https =
    519       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    520           "https://bar.com/", kTemporary);
    521   const int64 file_paths_cost_persistent_bar_https =
    522       ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
    523           "https://bar.com/", kPersistent);
    524 
    525   DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary);
    526   base::RunLoop().RunUntilIdle();
    527   EXPECT_EQ(storage::kQuotaStatusOk, status());
    528 
    529   DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent);
    530   base::RunLoop().RunUntilIdle();
    531   EXPECT_EQ(storage::kQuotaStatusOk, status());
    532 
    533   DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary);
    534   base::RunLoop().RunUntilIdle();
    535   EXPECT_EQ(storage::kQuotaStatusOk, status());
    536 
    537   EXPECT_EQ(0, GetOriginUsage(
    538       quota_client.get(), "http://foo.com/", kTemporary));
    539   EXPECT_EQ(0, GetOriginUsage(
    540       quota_client.get(), "http://bar.com/", kPersistent));
    541   EXPECT_EQ(0, GetOriginUsage(
    542       quota_client.get(), "http://buz.com/", kTemporary));
    543 
    544   EXPECT_EQ(2 + file_paths_cost_temporary_foo_https,
    545             GetOriginUsage(quota_client.get(),
    546                            "https://foo.com/",
    547                            kTemporary));
    548   EXPECT_EQ(4 + file_paths_cost_persistent_foo,
    549             GetOriginUsage(quota_client.get(),
    550                            "http://foo.com/",
    551                            kPersistent));
    552   EXPECT_EQ(8 + file_paths_cost_temporary_bar,
    553             GetOriginUsage(quota_client.get(),
    554                            "http://bar.com/",
    555                            kTemporary));
    556   EXPECT_EQ(32 + file_paths_cost_persistent_bar_https,
    557             GetOriginUsage(quota_client.get(),
    558                            "https://bar.com/",
    559                            kPersistent));
    560   EXPECT_EQ(64 + file_paths_cost_temporary_bar_https,
    561             GetOriginUsage(quota_client.get(),
    562                            "https://bar.com/",
    563                            kTemporary));
    564 }
    565 
    566 }  // namespace content
    567