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