OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/scoped_callback_factory.h" | 7 #include "base/memory/scoped_callback_factory.h" |
8 #include "base/memory/scoped_temp_dir.h" | 8 #include "base/memory/scoped_temp_dir.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const char kDummyURL2[] = "http://www.example.com"; | 26 const char kDummyURL2[] = "http://www.example.com"; |
27 const char kDummyURL3[] = "http://www.bleh"; | 27 const char kDummyURL3[] = "http://www.bleh"; |
28 | 28 |
29 // Declared to shorten the variable names. | 29 // Declared to shorten the variable names. |
30 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; | 30 const quota::StorageType kTemporary = quota::kStorageTypeTemporary; |
31 const quota::StorageType kPersistent = quota::kStorageTypePersistent; | 31 const quota::StorageType kPersistent = quota::kStorageTypePersistent; |
32 const int kUsageFileSize = FileSystemUsageCache::kUsageFileSize; | 32 const int kUsageFileSize = FileSystemUsageCache::kUsageFileSize; |
33 | 33 |
34 class MockFileSystemPathManager : public FileSystemPathManager { | 34 class MockFileSystemPathManager : public FileSystemPathManager { |
35 public: | 35 public: |
36 MockFileSystemPathManager(const FilePath& filesystem_path) | 36 explicit MockFileSystemPathManager(const FilePath& filesystem_path) |
37 : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(), | 37 : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(), |
38 filesystem_path, NULL, false, true) {} | 38 filesystem_path, NULL, false, true) {} |
39 }; | 39 }; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 class SandboxQuotaClientTest : public testing::Test { | 43 class SandboxQuotaClientTest : public testing::Test { |
44 public: | 44 public: |
45 SandboxQuotaClientTest() | 45 SandboxQuotaClientTest() |
46 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 46 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
47 additional_callback_count_(0) { | 47 additional_callback_count_(0), |
| 48 deletion_status_(quota::kQuotaStatusUnknown) { |
48 } | 49 } |
49 | 50 |
50 void SetUp() { | 51 void SetUp() { |
51 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 52 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
52 file_system_context_ = | 53 file_system_context_ = |
53 new FileSystemContext( | 54 new FileSystemContext( |
54 base::MessageLoopProxy::CreateForCurrentThread(), | 55 base::MessageLoopProxy::CreateForCurrentThread(), |
55 base::MessageLoopProxy::CreateForCurrentThread(), | 56 base::MessageLoopProxy::CreateForCurrentThread(), |
56 NULL, NULL, | 57 NULL, NULL, |
57 FilePath(), false /* is_incognito */, | 58 FilePath(), false /* is_incognito */, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 if (files[i].isDirectory) { | 171 if (files[i].isDirectory) { |
171 ASSERT_TRUE(CreateFileSystemDirectory( | 172 ASSERT_TRUE(CreateFileSystemDirectory( |
172 files[i].name, files[i].origin_url, files[i].type)); | 173 files[i].name, files[i].origin_url, files[i].type)); |
173 } else { | 174 } else { |
174 ASSERT_TRUE(CreateFileSystemFile( | 175 ASSERT_TRUE(CreateFileSystemFile( |
175 files[i].name, files[i].size, files[i].origin_url, files[i].type)); | 176 files[i].name, files[i].size, files[i].origin_url, files[i].type)); |
176 } | 177 } |
177 } | 178 } |
178 } | 179 } |
179 | 180 |
| 181 void DeleteOriginData(SandboxQuotaClient* quota_client, |
| 182 const char* origin, |
| 183 quota::StorageType type) { |
| 184 deletion_status_ = quota::kQuotaStatusUnknown; |
| 185 quota_client->DeleteOriginData( |
| 186 GURL(origin), type, |
| 187 callback_factory_.NewCallback( |
| 188 &SandboxQuotaClientTest::OnDeleteOrigin)); |
| 189 } |
| 190 |
180 int64 usage() const { return usage_; } | 191 int64 usage() const { return usage_; } |
| 192 quota::QuotaStatusCode status() { return deletion_status_; } |
181 int additional_callback_count() const { return additional_callback_count_; } | 193 int additional_callback_count() const { return additional_callback_count_; } |
182 void set_additional_callback_count(int count) { | 194 void set_additional_callback_count(int count) { |
183 additional_callback_count_ = count; | 195 additional_callback_count_ = count; |
184 } | 196 } |
185 | 197 |
186 private: | 198 private: |
187 void OnGetUsage(int64 usage) { | 199 void OnGetUsage(int64 usage) { |
188 usage_ = usage; | 200 usage_ = usage; |
189 } | 201 } |
190 | 202 |
191 void OnGetOrigins(const std::set<GURL>& origins) { | 203 void OnGetOrigins(const std::set<GURL>& origins) { |
192 origins_ = origins; | 204 origins_ = origins; |
193 } | 205 } |
194 | 206 |
195 void OnGetAdditionalUsage(int64) { | 207 void OnGetAdditionalUsage(int64 usage_unused) { |
196 ++additional_callback_count_; | 208 ++additional_callback_count_; |
197 } | 209 } |
198 | 210 |
| 211 void OnDeleteOrigin(quota::QuotaStatusCode status) { |
| 212 deletion_status_ = status; |
| 213 } |
| 214 |
199 ScopedTempDir data_dir_; | 215 ScopedTempDir data_dir_; |
200 scoped_refptr<FileSystemContext> file_system_context_; | 216 scoped_refptr<FileSystemContext> file_system_context_; |
201 base::ScopedCallbackFactory<SandboxQuotaClientTest> callback_factory_; | 217 base::ScopedCallbackFactory<SandboxQuotaClientTest> callback_factory_; |
202 int64 usage_; | 218 int64 usage_; |
203 int additional_callback_count_; | 219 int additional_callback_count_; |
204 std::set<GURL> origins_; | 220 std::set<GURL> origins_; |
| 221 quota::QuotaStatusCode deletion_status_; |
205 | 222 |
206 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaClientTest); | 223 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaClientTest); |
207 }; | 224 }; |
208 | 225 |
209 TEST_F(SandboxQuotaClientTest, NoFileSystemTest) { | 226 TEST_F(SandboxQuotaClientTest, NoFileSystemTest) { |
210 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); | 227 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); |
211 | 228 |
212 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 229 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
213 } | 230 } |
214 | 231 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // queried in incognito mode. | 441 // queried in incognito mode. |
425 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 442 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
426 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); | 443 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
427 | 444 |
428 std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); | 445 std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); |
429 EXPECT_EQ(0U, origins.size()); | 446 EXPECT_EQ(0U, origins.size()); |
430 origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org"); | 447 origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org"); |
431 EXPECT_EQ(0U, origins.size()); | 448 EXPECT_EQ(0U, origins.size()); |
432 } | 449 } |
433 | 450 |
| 451 TEST_F(SandboxQuotaClientTest, DeleteOriginTest) { |
| 452 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); |
| 453 const TestFile kFiles[] = { |
| 454 {true, NULL, 0, "http://foo.com/", kTemporary}, |
| 455 {false, "a", 1, "http://foo.com/", kTemporary}, |
| 456 {true, NULL, 0, "https://foo.com/", kTemporary}, |
| 457 {false, "b", 2, "https://foo.com/", kTemporary}, |
| 458 {true, NULL, 0, "http://foo.com/", kPersistent}, |
| 459 {false, "c", 4, "http://foo.com/", kPersistent}, |
| 460 {true, NULL, 0, "http://bar.com/", kTemporary}, |
| 461 {false, "d", 8, "http://bar.com/", kTemporary}, |
| 462 {true, NULL, 0, "http://bar.com/", kPersistent}, |
| 463 {false, "e", 16, "http://bar.com/", kPersistent}, |
| 464 {true, NULL, 0, "https://bar.com/", kPersistent}, |
| 465 {false, "f", 32, "https://bar.com/", kPersistent}, |
| 466 {true, NULL, 0, "https://bar.com/", kTemporary}, |
| 467 {false, "g", 64, "https://bar.com/", kTemporary}, |
| 468 }; |
| 469 CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles)); |
| 470 |
| 471 DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary); |
| 472 MessageLoop::current()->RunAllPending(); |
| 473 EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 474 |
| 475 DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent); |
| 476 MessageLoop::current()->RunAllPending(); |
| 477 EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 478 |
| 479 DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary); |
| 480 MessageLoop::current()->RunAllPending(); |
| 481 EXPECT_EQ(quota::kQuotaStatusOk, status()); |
| 482 |
| 483 EXPECT_EQ(0, GetOriginUsage( |
| 484 quota_client.get(), "http://foo.com/", kTemporary)); |
| 485 EXPECT_EQ(0, GetOriginUsage( |
| 486 quota_client.get(), "http://bar.com/", kPersistent)); |
| 487 EXPECT_EQ(0, GetOriginUsage( |
| 488 quota_client.get(), "http://buz.com/", kTemporary)); |
| 489 |
| 490 EXPECT_EQ(2 + kUsageFileSize, |
| 491 GetOriginUsage(quota_client.get(), |
| 492 "https://foo.com/", |
| 493 kTemporary)); |
| 494 EXPECT_EQ(4 + kUsageFileSize, |
| 495 GetOriginUsage(quota_client.get(), |
| 496 "http://foo.com/", |
| 497 kPersistent)); |
| 498 EXPECT_EQ(8 + kUsageFileSize, |
| 499 GetOriginUsage(quota_client.get(), |
| 500 "http://bar.com/", |
| 501 kTemporary)); |
| 502 EXPECT_EQ(32 + kUsageFileSize, |
| 503 GetOriginUsage(quota_client.get(), |
| 504 "https://bar.com/", |
| 505 kPersistent)); |
| 506 EXPECT_EQ(64 + kUsageFileSize, |
| 507 GetOriginUsage(quota_client.get(), |
| 508 "https://bar.com/", |
| 509 kTemporary)); |
| 510 } |
| 511 |
434 } // namespace fileapi | 512 } // namespace fileapi |
OLD | NEW |