Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / fileapi / file_system_quota_client_unittest.cc
blob747c6626d6ee92608f0d5cfce8fdc1e75fe7ac42
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.
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"
23 using content::AsyncFileTestHelper;
24 using storage::FileSystemQuotaClient;
25 using storage::FileSystemURL;
27 namespace content {
28 namespace {
30 const char kDummyURL1[] = "http://www.dummy.org";
31 const char kDummyURL2[] = "http://www.example.com";
32 const char kDummyURL3[] = "http://www.bleh";
34 // Declared to shorten the variable names.
35 const storage::StorageType kTemporary = storage::kStorageTypeTemporary;
36 const storage::StorageType kPersistent = storage::kStorageTypePersistent;
38 } // namespace
40 class FileSystemQuotaClientTest : public testing::Test {
41 public:
42 FileSystemQuotaClientTest()
43 : weak_factory_(this),
44 additional_callback_count_(0),
45 deletion_status_(storage::kQuotaStatusUnknown) {}
47 void SetUp() override {
48 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
49 file_system_context_ = CreateFileSystemContextForTesting(
50 NULL, data_dir_.path());
53 struct TestFile {
54 bool isDirectory;
55 const char* name;
56 int64 size;
57 const char* origin_url;
58 storage::StorageType type;
61 protected:
62 FileSystemQuotaClient* NewQuotaClient(bool is_incognito) {
63 return new FileSystemQuotaClient(file_system_context_.get(), is_incognito);
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()));
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_;
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_;
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_;
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()));
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);
123 base::File::Error result =
124 AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), url);
125 return result == base::File::FILE_OK;
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;
135 storage::FileSystemType type =
136 storage::QuotaStorageTypeToFileSystemType(storage_type);
137 FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
138 GURL(origin_url), type, file_path);
140 base::File::Error result =
141 AsyncFileTestHelper::CreateFile(file_system_context_.get(), url);
142 if (result != base::File::FILE_OK)
143 return false;
145 result = AsyncFileTestHelper::TruncateFile(
146 file_system_context_.get(), url, file_size);
147 return result == base::File::FILE_OK;
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));
167 } else {
168 ASSERT_TRUE(CreateFileSystemFile(
169 path, files[i].size, files[i].origin_url, files[i].type));
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);
193 return file_paths_cost;
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()));
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;
213 private:
214 void OnGetUsage(int64 usage) {
215 usage_ = usage;
218 void OnGetOrigins(const std::set<GURL>& origins) {
219 origins_ = origins;
222 void OnGetAdditionalUsage(int64 usage_unused) {
223 ++additional_callback_count_;
226 void OnDeleteOrigin(storage::QuotaStatusCode status) {
227 deletion_status_ = status;
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_;
239 DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaClientTest);
242 TEST_F(FileSystemQuotaClientTest, NoFileSystemTest) {
243 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
245 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
248 TEST_F(FileSystemQuotaClientTest, NoFileTest) {
249 scoped_ptr<FileSystemQuotaClient> quota_client(NewQuotaClient(false));
250 const TestFile kFiles[] = {
251 {true, NULL, 0, kDummyURL1, kTemporary},
253 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
255 for (int i = 0; i < 2; i++) {
256 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
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},
266 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
267 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
268 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
270 for (int i = 0; i < 2; i++) {
271 EXPECT_EQ(4921 + file_paths_cost,
272 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
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},
283 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
284 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
285 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
287 for (int i = 0; i < 2; i++) {
288 EXPECT_EQ(10310 + 41 + file_paths_cost,
289 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
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},
301 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
302 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
303 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
305 for (int i = 0; i < 2; i++) {
306 EXPECT_EQ(file_paths_cost,
307 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
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},
319 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
320 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
321 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
323 for (int i = 0; i < 2; i++) {
324 EXPECT_EQ(11921 + 4814 + file_paths_cost,
325 GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
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},
341 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
342 const int64 file_paths_cost_temporary = ComputeFilePathsCostForOriginAndType(
343 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
344 const int64 file_paths_cost_persistent = ComputeFilePathsCostForOriginAndType(
345 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
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));
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},
375 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
376 const int64 file_paths_cost_temporary1 = ComputeFilePathsCostForOriginAndType(
377 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
378 const int64 file_paths_cost_persistent1 =
379 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
380 kDummyURL1, kPersistent);
381 const int64 file_paths_cost_temporary2 = ComputeFilePathsCostForOriginAndType(
382 kFiles, arraysize(kFiles), kDummyURL2, kTemporary);
383 const int64 file_paths_cost_persistent2 =
384 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
385 kDummyURL2, kPersistent);
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));
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},
406 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
407 const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
408 kFiles, arraysize(kFiles), kDummyURL1, kTemporary);
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());
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());
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},
436 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
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());
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},
459 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
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.
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},
477 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
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));
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());
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},
508 InitializeOriginFiles(quota_client.get(), kFiles, arraysize(kFiles));
509 const int64 file_paths_cost_temporary_foo_https =
510 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
511 "https://foo.com/", kTemporary);
512 const int64 file_paths_cost_persistent_foo =
513 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
514 "http://foo.com/", kPersistent);
515 const int64 file_paths_cost_temporary_bar =
516 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
517 "http://bar.com/", kTemporary);
518 const int64 file_paths_cost_temporary_bar_https =
519 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
520 "https://bar.com/", kTemporary);
521 const int64 file_paths_cost_persistent_bar_https =
522 ComputeFilePathsCostForOriginAndType(kFiles, arraysize(kFiles),
523 "https://bar.com/", kPersistent);
525 DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary);
526 base::RunLoop().RunUntilIdle();
527 EXPECT_EQ(storage::kQuotaStatusOk, status());
529 DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent);
530 base::RunLoop().RunUntilIdle();
531 EXPECT_EQ(storage::kQuotaStatusOk, status());
533 DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary);
534 base::RunLoop().RunUntilIdle();
535 EXPECT_EQ(storage::kQuotaStatusOk, status());
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));
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));
566 } // namespace content