Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 MockFileSystemPathManager(const FilePath& filesystem_path) | 36 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 | 41 |
| 42 class SandboxQuotaClientTest : public testing::Test { | 42 class SandboxQuotaClientTest : public testing::Test { |
| 43 public: | 43 public: |
| 44 SandboxQuotaClientTest() | 44 SandboxQuotaClientTest() |
| 45 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 45 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 46 additional_callback_count_(0) { | 46 additional_callback_count_(0), |
| 47 quota_status_(quota::kQuotaStatusUnknown) { | |
| 47 } | 48 } |
| 48 | 49 |
| 49 void SetUp() { | 50 void SetUp() { |
| 50 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 51 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 51 file_system_context_ = | 52 file_system_context_ = |
| 52 new FileSystemContext( | 53 new FileSystemContext( |
| 53 base::MessageLoopProxy::CreateForCurrentThread(), | 54 base::MessageLoopProxy::CreateForCurrentThread(), |
| 54 base::MessageLoopProxy::CreateForCurrentThread(), | 55 base::MessageLoopProxy::CreateForCurrentThread(), |
| 55 NULL, NULL, | 56 NULL, NULL, |
| 56 FilePath(), false /* is_incognito */, | 57 FilePath(), false /* is_incognito */, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 if (files[i].isDirectory) { | 170 if (files[i].isDirectory) { |
| 170 ASSERT_TRUE(CreateFileSystemDirectory( | 171 ASSERT_TRUE(CreateFileSystemDirectory( |
| 171 files[i].name, files[i].origin_url, files[i].type)); | 172 files[i].name, files[i].origin_url, files[i].type)); |
| 172 } else { | 173 } else { |
| 173 ASSERT_TRUE(CreateFileSystemFile( | 174 ASSERT_TRUE(CreateFileSystemFile( |
| 174 files[i].name, files[i].size, files[i].origin_url, files[i].type)); | 175 files[i].name, files[i].size, files[i].origin_url, files[i].type)); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 180 void DeleteOriginData(SandboxQuotaClient* quota_client, | |
| 181 const char* origin, | |
| 182 quota::StorageType type) { | |
| 183 quota_status_ = quota::kQuotaStatusUnknown; | |
| 184 quota_client->DeleteOriginData( | |
| 185 GURL(origin), type, | |
| 186 callback_factory_.NewCallback( | |
| 187 &SandboxQuotaClientTest::OnDeleteOrigin)); | |
| 188 } | |
| 189 | |
| 179 int64 usage() const { return usage_; } | 190 int64 usage() const { return usage_; } |
| 191 quota::QuotaStatusCode status(){ return quota_status_; } | |
|
michaeln
2011/05/13 07:28:02
maybe delete_status_ and delete_status()
tzik (google)
2011/05/13 14:22:24
Done.
| |
| 180 int additional_callback_count() const { return additional_callback_count_; } | 192 int additional_callback_count() const { return additional_callback_count_; } |
| 181 void set_additional_callback_count(int count) { | 193 void set_additional_callback_count(int count) { |
| 182 additional_callback_count_ = count; | 194 additional_callback_count_ = count; |
| 183 } | 195 } |
| 184 | 196 |
| 185 private: | 197 private: |
| 186 void OnGetUsage(int64 usage) { | 198 void OnGetUsage(int64 usage) { |
| 187 usage_ = usage; | 199 usage_ = usage; |
| 188 } | 200 } |
| 189 | 201 |
| 190 void OnGetOrigins(const std::set<GURL>& origins) { | 202 void OnGetOrigins(const std::set<GURL>& origins) { |
| 191 origins_ = origins; | 203 origins_ = origins; |
| 192 } | 204 } |
| 193 | 205 |
| 194 void OnGetAdditionalUsage(int64) { | 206 void OnGetAdditionalUsage(int64) { |
| 195 ++additional_callback_count_; | 207 ++additional_callback_count_; |
| 196 } | 208 } |
| 197 | 209 |
| 210 void OnDeleteOrigin(quota::QuotaStatusCode status) { | |
| 211 quota_status_ = status; | |
| 212 } | |
| 213 | |
| 198 ScopedTempDir data_dir_; | 214 ScopedTempDir data_dir_; |
| 199 scoped_refptr<FileSystemContext> file_system_context_; | 215 scoped_refptr<FileSystemContext> file_system_context_; |
| 200 base::ScopedCallbackFactory<SandboxQuotaClientTest> callback_factory_; | 216 base::ScopedCallbackFactory<SandboxQuotaClientTest> callback_factory_; |
| 201 int64 usage_; | 217 int64 usage_; |
| 202 int additional_callback_count_; | 218 int additional_callback_count_; |
| 203 std::set<GURL> origins_; | 219 std::set<GURL> origins_; |
| 220 quota::QuotaStatusCode quota_status_; | |
| 204 | 221 |
| 205 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaClientTest); | 222 DISALLOW_COPY_AND_ASSIGN(SandboxQuotaClientTest); |
| 206 }; | 223 }; |
| 207 | 224 |
| 208 TEST_F(SandboxQuotaClientTest, NoFileSystemTest) { | 225 TEST_F(SandboxQuotaClientTest, NoFileSystemTest) { |
| 209 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); | 226 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); |
| 210 | 227 |
| 211 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 228 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 212 } | 229 } |
| 213 | 230 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 // Having files in the usual directory wouldn't affect the result | 439 // Having files in the usual directory wouldn't affect the result |
| 423 // queried in incognito mode. | 440 // queried in incognito mode. |
| 424 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); | 441 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary)); |
| 425 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); | 442 EXPECT_EQ(0, GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent)); |
| 426 | 443 |
| 427 std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); | 444 std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary); |
| 428 EXPECT_EQ(0U, origins.size()); | 445 EXPECT_EQ(0U, origins.size()); |
| 429 origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org"); | 446 origins = GetOriginsForHost(quota_client.get(), kTemporary, "www.dummy.org"); |
| 430 EXPECT_EQ(0U, origins.size()); | 447 EXPECT_EQ(0U, origins.size()); |
| 431 } | 448 } |
| 449 | |
| 450 TEST_F(SandboxQuotaClientTest, DeleteOriginTest) { | |
| 451 scoped_ptr<SandboxQuotaClient> quota_client(NewQuotaClient(false)); | |
| 452 const TestFile kFiles[] = { | |
| 453 {true, NULL, 0, "http://foo.com/", kTemporary}, | |
| 454 {false, "a", 1, "http://foo.com/", kTemporary}, | |
| 455 {true, NULL, 0, "https://foo.com/", kTemporary}, | |
| 456 {false, "b", 2, "https://foo.com/", kTemporary}, | |
| 457 {true, NULL, 0, "http://foo.com/", kPersistent}, | |
| 458 {false, "c", 4, "http://foo.com/", kPersistent}, | |
| 459 {true, NULL, 0, "http://bar.com/", kTemporary}, | |
| 460 {false, "d", 8, "http://bar.com/", kTemporary}, | |
| 461 {true, NULL, 0, "http://bar.com/", kPersistent}, | |
| 462 {false, "e", 16, "http://bar.com/", kPersistent}, | |
| 463 {true, NULL, 0, "https://bar.com/", kPersistent}, | |
| 464 {false, "f", 32, "https://bar.com/", kPersistent}, | |
| 465 {true, NULL, 0, "https://bar.com/", kTemporary}, | |
| 466 {false, "g", 64, "https://bar.com/", kTemporary}, | |
| 467 }; | |
| 468 CreateFiles(kFiles,ARRAYSIZE_UNSAFE(kFiles)); | |
|
michaeln
2011/05/13 07:28:02
missing space before,ARRAY (why does lint not run?
tzik (google)
2011/05/13 14:22:24
Done.
Thanks, I'll try it.
| |
| 469 | |
| 470 DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary); | |
| 471 MessageLoop::current()->RunAllPending(); | |
| 472 EXPECT_EQ(quota::kQuotaStatusOk, status()); | |
| 473 | |
| 474 DeleteOriginData(quota_client.get(), "http://bar.com/", kPersistent); | |
| 475 MessageLoop::current()->RunAllPending(); | |
| 476 EXPECT_EQ(quota::kQuotaStatusOk, status()); | |
| 477 | |
| 478 DeleteOriginData(quota_client.get(), "http://buz.com/", kTemporary); | |
| 479 MessageLoop::current()->RunAllPending(); | |
| 480 EXPECT_EQ(quota::kQuotaStatusOk, status()); | |
| 481 | |
| 482 EXPECT_EQ(0, GetOriginUsage( | |
| 483 quota_client.get(), "http://foo.com/", kTemporary)); | |
| 484 EXPECT_EQ(0, GetOriginUsage( | |
| 485 quota_client.get(), "http://bar.com/", kPersistent)); | |
| 486 EXPECT_EQ(0, GetOriginUsage( | |
| 487 quota_client.get(), "http://buz.com/", kTemporary)); | |
| 488 | |
| 489 EXPECT_EQ(2 + kUsageFileSize, | |
| 490 GetOriginUsage(quota_client.get(), "https://foo.com/", kTemporary)); | |
| 491 EXPECT_EQ(4 + kUsageFileSize, | |
| 492 GetOriginUsage(quota_client.get(), "http://foo.com/", kPersistent)) ; | |
|
kinuko
2011/05/13 07:26:00
style-nit: over 80 chars
michaeln
2011/05/13 07:28:02
line length
tzik (google)
2011/05/13 14:22:24
Done.
| |
| 493 EXPECT_EQ(8 + kUsageFileSize, | |
| 494 GetOriginUsage(quota_client.get(), "http://bar.com/", kTemporary)); | |
| 495 EXPECT_EQ(32 + kUsageFileSize, | |
| 496 GetOriginUsage(quota_client.get(), "https://bar.com/", kPersistent)) ; | |
|
kinuko
2011/05/13 07:26:00
ditto
michaeln
2011/05/13 07:28:02
line length
tzik (google)
2011/05/13 14:22:24
Done.
| |
| 497 EXPECT_EQ(64 + kUsageFileSize, | |
| 498 GetOriginUsage(quota_client.get(), "https://bar.com/", kTemporary)); | |
| 499 } | |
| OLD | NEW |