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