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