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