OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop/message_loop_proxy.h" | 6 #include "base/message_loop/message_loop_proxy.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/gpu/shader_disk_cache.h" | 10 #include "content/browser/gpu/shader_disk_cache.h" |
| 11 #include "content/browser/quota/mock_quota_manager.h" |
11 #include "content/browser/storage_partition_impl.h" | 12 #include "content/browser/storage_partition_impl.h" |
12 #include "content/public/browser/local_storage_usage_info.h" | 13 #include "content/public/browser/local_storage_usage_info.h" |
13 #include "content/public/browser/storage_partition.h" | 14 #include "content/public/browser/storage_partition.h" |
14 #include "content/public/test/test_browser_context.h" | 15 #include "content/public/test/test_browser_context.h" |
15 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
18 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "webkit/browser/quota/mock_quota_manager.h" | |
23 #include "webkit/browser/quota/mock_special_storage_policy.h" | 23 #include "webkit/browser/quota/mock_special_storage_policy.h" |
24 #include "webkit/browser/quota/quota_manager.h" | 24 #include "webkit/browser/quota/quota_manager.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 namespace { | 27 namespace { |
28 | 28 |
29 const int kDefaultClientId = 42; | 29 const int kDefaultClientId = 42; |
30 const char kCacheKey[] = "key"; | 30 const char kCacheKey[] = "key"; |
31 const char kCacheValue[] = "cached value"; | 31 const char kCacheValue[] = "cached value"; |
32 | 32 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 } // namespace | 325 } // namespace |
326 | 326 |
327 class StoragePartitionImplTest : public testing::Test { | 327 class StoragePartitionImplTest : public testing::Test { |
328 public: | 328 public: |
329 StoragePartitionImplTest() | 329 StoragePartitionImplTest() |
330 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 330 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
331 browser_context_(new TestBrowserContext()) { | 331 browser_context_(new TestBrowserContext()) { |
332 } | 332 } |
333 | 333 |
334 quota::MockQuotaManager* GetMockManager() { | 334 MockQuotaManager* GetMockManager() { |
335 if (!quota_manager_.get()) { | 335 if (!quota_manager_.get()) { |
336 quota_manager_ = new quota::MockQuotaManager( | 336 quota_manager_ = new MockQuotaManager( |
337 browser_context_->IsOffTheRecord(), | 337 browser_context_->IsOffTheRecord(), |
338 browser_context_->GetPath(), | 338 browser_context_->GetPath(), |
339 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), | 339 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
340 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), | 340 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get(), |
341 browser_context_->GetSpecialStoragePolicy()); | 341 browser_context_->GetSpecialStoragePolicy()); |
342 } | 342 } |
343 return quota_manager_.get(); | 343 return quota_manager_.get(); |
344 } | 344 } |
345 | 345 |
346 TestBrowserContext* browser_context() { | 346 TestBrowserContext* browser_context() { |
347 return browser_context_.get(); | 347 return browser_context_.get(); |
348 } | 348 } |
349 | 349 |
350 private: | 350 private: |
351 content::TestBrowserThreadBundle thread_bundle_; | 351 content::TestBrowserThreadBundle thread_bundle_; |
352 scoped_ptr<TestBrowserContext> browser_context_; | 352 scoped_ptr<TestBrowserContext> browser_context_; |
353 scoped_refptr<quota::MockQuotaManager> quota_manager_; | 353 scoped_refptr<MockQuotaManager> quota_manager_; |
354 | 354 |
355 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest); | 355 DISALLOW_COPY_AND_ASSIGN(StoragePartitionImplTest); |
356 }; | 356 }; |
357 | 357 |
358 class StoragePartitionShaderClearTest : public testing::Test { | 358 class StoragePartitionShaderClearTest : public testing::Test { |
359 public: | 359 public: |
360 StoragePartitionShaderClearTest() | 360 StoragePartitionShaderClearTest() |
361 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 361 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
362 browser_context_(new TestBrowserContext()) { | 362 browser_context_(new TestBrowserContext()) { |
363 ShaderCacheFactory::GetInstance()->SetCacheInfo( | 363 ShaderCacheFactory::GetInstance()->SetCacheInfo( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 quota::QuotaClient::kDatabase | | 432 quota::QuotaClient::kDatabase | |
433 quota::QuotaClient::kAppcache | | 433 quota::QuotaClient::kAppcache | |
434 quota::QuotaClient::kIndexedDatabase, | 434 quota::QuotaClient::kIndexedDatabase, |
435 StoragePartitionImpl::GenerateQuotaClientMask( | 435 StoragePartitionImpl::GenerateQuotaClientMask( |
436 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 436 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
437 StoragePartition::REMOVE_DATA_MASK_WEBSQL | | 437 StoragePartition::REMOVE_DATA_MASK_WEBSQL | |
438 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 438 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
439 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); | 439 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); |
440 } | 440 } |
441 | 441 |
442 void PopulateTestQuotaManagedPersistentData(quota::MockQuotaManager* manager) { | 442 void PopulateTestQuotaManagedPersistentData(MockQuotaManager* manager) { |
443 manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time()); | 443 manager->AddOrigin(kOrigin2, kPersistent, kClientFile, base::Time()); |
444 manager->AddOrigin(kOrigin3, kPersistent, kClientFile, | 444 manager->AddOrigin(kOrigin3, kPersistent, kClientFile, |
445 base::Time::Now() - base::TimeDelta::FromDays(1)); | 445 base::Time::Now() - base::TimeDelta::FromDays(1)); |
446 | 446 |
447 EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile)); | 447 EXPECT_FALSE(manager->OriginHasData(kOrigin1, kPersistent, kClientFile)); |
448 EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile)); | 448 EXPECT_TRUE(manager->OriginHasData(kOrigin2, kPersistent, kClientFile)); |
449 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile)); | 449 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kPersistent, kClientFile)); |
450 } | 450 } |
451 | 451 |
452 void PopulateTestQuotaManagedTemporaryData(quota::MockQuotaManager* manager) { | 452 void PopulateTestQuotaManagedTemporaryData(MockQuotaManager* manager) { |
453 manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now()); | 453 manager->AddOrigin(kOrigin1, kTemporary, kClientFile, base::Time::Now()); |
454 manager->AddOrigin(kOrigin3, kTemporary, kClientFile, | 454 manager->AddOrigin(kOrigin3, kTemporary, kClientFile, |
455 base::Time::Now() - base::TimeDelta::FromDays(1)); | 455 base::Time::Now() - base::TimeDelta::FromDays(1)); |
456 | 456 |
457 EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile)); | 457 EXPECT_TRUE(manager->OriginHasData(kOrigin1, kTemporary, kClientFile)); |
458 EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile)); | 458 EXPECT_FALSE(manager->OriginHasData(kOrigin2, kTemporary, kClientFile)); |
459 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile)); | 459 EXPECT_TRUE(manager->OriginHasData(kOrigin3, kTemporary, kClientFile)); |
460 } | 460 } |
461 | 461 |
462 void PopulateTestQuotaManagedData(quota::MockQuotaManager* manager) { | 462 void PopulateTestQuotaManagedData(MockQuotaManager* manager) { |
463 // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent | 463 // Set up kOrigin1 with a temporary quota, kOrigin2 with a persistent |
464 // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2 | 464 // quota, and kOrigin3 with both. kOrigin1 is modified now, kOrigin2 |
465 // is modified at the beginning of time, and kOrigin3 is modified one day | 465 // is modified at the beginning of time, and kOrigin3 is modified one day |
466 // ago. | 466 // ago. |
467 PopulateTestQuotaManagedPersistentData(manager); | 467 PopulateTestQuotaManagedPersistentData(manager); |
468 PopulateTestQuotaManagedTemporaryData(manager); | 468 PopulateTestQuotaManagedTemporaryData(manager); |
469 } | 469 } |
470 | 470 |
471 void PopulateTestQuotaManagedNonBrowsingData(quota::MockQuotaManager* manager) { | 471 void PopulateTestQuotaManagedNonBrowsingData(MockQuotaManager* manager) { |
472 manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time()); | 472 manager->AddOrigin(kOriginDevTools, kTemporary, kClientFile, base::Time()); |
473 manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time()); | 473 manager->AddOrigin(kOriginDevTools, kPersistent, kClientFile, base::Time()); |
474 } | 474 } |
475 | 475 |
476 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { | 476 TEST_F(StoragePartitionImplTest, RemoveQuotaManagedDataForeverBoth) { |
477 PopulateTestQuotaManagedData(GetMockManager()); | 477 PopulateTestQuotaManagedData(GetMockManager()); |
478 | 478 |
479 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | 479 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( |
480 BrowserContext::GetDefaultStoragePartition(browser_context())); | 480 BrowserContext::GetDefaultStoragePartition(browser_context())); |
481 partition->OverrideQuotaManagerForTesting( | 481 partition->OverrideQuotaManagerForTesting( |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 &run_loop)); | 928 &run_loop)); |
929 run_loop.Run(); | 929 run_loop.Run(); |
930 | 930 |
931 // kOrigin1 and kOrigin2 do not have age more than a week. | 931 // kOrigin1 and kOrigin2 do not have age more than a week. |
932 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); | 932 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin1)); |
933 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); | 933 EXPECT_FALSE(tester.DOMStorageExistsForOrigin(kOrigin2)); |
934 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); | 934 EXPECT_TRUE(tester.DOMStorageExistsForOrigin(kOrigin3)); |
935 } | 935 } |
936 | 936 |
937 } // namespace content | 937 } // namespace content |
OLD | NEW |