OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 |
| 7 #include <set> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_temp_dir.h" |
| 13 #include "base/message_loop.h" |
| 14 #include "base/message_loop_proxy.h" |
| 15 #include "webkit/quota/mock_storage_client.h" |
| 16 #include "webkit/quota/quota_database.h" |
| 17 #include "webkit/quota/quota_manager.h" |
| 18 #include "webkit/quota/quota_temporary_storage_evictor.h" |
| 19 |
| 20 namespace quota { |
| 21 |
| 22 namespace { |
| 23 |
| 24 class MockQuotaManager : public quota::QuotaManager { |
| 25 public: |
| 26 MockQuotaManager(const FilePath& profile_path, int64 usage, int64 quota) |
| 27 : quota::QuotaManager(false /* is_incognito */, |
| 28 profile_path, |
| 29 base::MessageLoopProxy::CreateForCurrentThread(), |
| 30 base::MessageLoopProxy::CreateForCurrentThread()), |
| 31 test_profile_path_(profile_path), |
| 32 usage_(usage), |
| 33 quota_(quota) {} |
| 34 |
| 35 virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type, |
| 36 GetUsageAndQuotaCallback* callback) { |
| 37 callback->Run(quota::kQuotaStatusOk, usage_, quota_); |
| 38 delete callback; |
| 39 } |
| 40 |
| 41 virtual void DeleteOriginDataOnIOThread( |
| 42 const GURL& origin, |
| 43 StorageType type, |
| 44 DeleteOriginDataCallback* callback) { |
| 45 callback->Run(quota::kQuotaStatusOk); |
| 46 delete callback; |
| 47 } |
| 48 |
| 49 void set_usage(int64 usage) { usage_ = usage; } |
| 50 void set_quota(int64 quota) { quota_ = quota; } |
| 51 |
| 52 private: |
| 53 FilePath test_profile_path_; |
| 54 int64 usage_; |
| 55 int64 quota_; |
| 56 }; |
| 57 |
| 58 class MockQuotaDatabase : public quota::QuotaDatabase { |
| 59 public: |
| 60 MockQuotaDatabase() : QuotaDatabase(FilePath()) {} |
| 61 |
| 62 virtual GURL GetLRUOriginExceptFor(StorageType type, |
| 63 const std::set<GURL>& exceptions) { |
| 64 return GURL("http://www.example.com"); |
| 65 } |
| 66 |
| 67 private: |
| 68 }; |
| 69 |
| 70 } // anonymous namespace |
| 71 |
| 72 class QuotaTemporaryStorageEvictorTest : public testing::Test { |
| 73 public: |
| 74 QuotaTemporaryStorageEvictorTest() {} |
| 75 |
| 76 void SetUp() { |
| 77 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 78 |
| 79 quota_manager_ = new MockQuotaManager(data_dir_.path(), 0, 1000); |
| 80 quota_database_.reset(new MockQuotaDatabase()); |
| 81 |
| 82 temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor( |
| 83 quota_manager_.get(), quota_database_.get(), 3000, |
| 84 base::MessageLoopProxy::CreateForCurrentThread(), |
| 85 base::MessageLoopProxy::CreateForCurrentThread()); |
| 86 |
| 87 additional_callback_count_ = 0; |
| 88 } |
| 89 |
| 90 void TearDown() { |
| 91 temporary_storage_evictor_ = NULL; |
| 92 quota_database_.reset(NULL); |
| 93 |
| 94 // Make sure the quota manager cleans up correctly. |
| 95 quota_manager_ = NULL; |
| 96 MessageLoop::current()->RunAllPending(); |
| 97 } |
| 98 |
| 99 protected: |
| 100 /* |
| 101 MockStorageClient* CreateClient( |
| 102 const MockOriginData* mock_data, size_t mock_data_size) { |
| 103 MockStorageClient* client = new MockStorageClient(quota_manager_->proxy()); |
| 104 for (size_t i = 0; i < mock_data_size; ++i) { |
| 105 client->AddMockOriginData(GURL(mock_data[i].origin), |
| 106 mock_data[i].type, |
| 107 mock_data[i].usage); |
| 108 } |
| 109 return client; |
| 110 } |
| 111 */ |
| 112 |
| 113 MockQuotaManager* quota_manager() const { |
| 114 return static_cast<MockQuotaManager*>(quota_manager_.get()); |
| 115 } |
| 116 |
| 117 MockQuotaDatabase* quota_database() const { |
| 118 return static_cast<MockQuotaDatabase*>(quota_database_.get()); |
| 119 } |
| 120 |
| 121 QuotaTemporaryStorageEvictor* temporary_storage_evictor() const { |
| 122 return temporary_storage_evictor_.get(); |
| 123 } |
| 124 |
| 125 private: |
| 126 ScopedTempDir data_dir_; |
| 127 |
| 128 scoped_refptr<QuotaManager> quota_manager_; |
| 129 scoped_ptr<QuotaDatabase> quota_database_; |
| 130 scoped_refptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; |
| 131 |
| 132 QuotaStatusCode quota_status_; |
| 133 std::string host_; |
| 134 int64 usage_; |
| 135 int64 quota_; |
| 136 |
| 137 int additional_callback_count_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest); |
| 140 }; |
| 141 |
| 142 TEST_F(QuotaTemporaryStorageEvictorTest, Simple) { |
| 143 temporary_storage_evictor()->Start(); |
| 144 MessageLoop::current()->RunAllPending(); |
| 145 } |
| 146 |
| 147 } // namespace quota |
OLD | NEW |