Index: webkit/quota/quota_temporary_storage_evictor_unittest.cc |
diff --git a/webkit/quota/quota_temporary_storage_evictor_unittest.cc b/webkit/quota/quota_temporary_storage_evictor_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6634c5b0fbfcb4d6860653063a474c1663af75cc |
--- /dev/null |
+++ b/webkit/quota/quota_temporary_storage_evictor_unittest.cc |
@@ -0,0 +1,143 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include <set> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/scoped_temp_dir.h" |
+#include "base/message_loop.h" |
+#include "base/message_loop_proxy.h" |
+#include "webkit/quota/mock_storage_client.h" |
+#include "webkit/quota/quota_manager.h" |
+#include "webkit/quota/quota_temporary_storage_evictor.h" |
+ |
+namespace quota { |
+ |
+namespace { |
+ |
+class MockQuotaManager : public quota::QuotaEvictionHandler { |
+ public: |
+ MockQuotaManager(const FilePath& profile_path, int64 usage, int64 quota) |
+ : test_profile_path_(profile_path), |
+ usage_(usage), |
+ quota_(quota) {} |
+ virtual ~MockQuotaManager() {} |
+ |
+ virtual void EvictOriginData( |
+ const GURL& origin, |
+ StorageType type, |
+ EvictOriginDataCallback* callback) OVERRIDE { |
+ LOG(ERROR) << "MockQM::EvictOriginData"; |
+ usage_ -= 500; |
+ callback->Run(quota::kQuotaStatusOk); |
+ delete callback; |
+ } |
+ |
+ virtual void GetUsageAndQuotaForEviction( |
+ GetUsageAndQuotaForEvictionCallback* callback) OVERRIDE { |
+ LOG(ERROR) << "MockQM::GetUsageAndQuotaForEviction"; |
+ callback->Run(quota::kQuotaStatusOk, usage_, quota_, 1000000000); |
+ delete callback; |
+ } |
+ |
+ virtual void GetLRUOrigin( |
+ StorageType type, |
+ GetLRUOriginCallback* callback) OVERRIDE { |
+ callback->Run(GURL("http://www.example.com")); |
+ } |
+ |
+ void set_usage(int64 usage) { usage_ = usage; } |
+ void set_quota(int64 quota) { quota_ = quota; } |
+ |
+ private: |
+ FilePath test_profile_path_; |
+ int64 usage_; |
+ int64 quota_; |
+}; |
+ |
+} // anonymous namespace |
+ |
+class QuotaTemporaryStorageEvictorTest : public testing::Test { |
+ public: |
+ QuotaTemporaryStorageEvictorTest() {} |
+ |
+ void SetUp() { |
+ ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
+ |
+ quota_manager_.reset(new MockQuotaManager(data_dir_.path(), 3000, 3500)); |
+ |
+ temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor( |
+ quota_manager_.get(), |
+ 10000000, 3000, base::MessageLoopProxy::CreateForCurrentThread())); |
+ |
+ additional_callback_count_ = 0; |
+ } |
+ |
+ void TearDown() { |
+ temporary_storage_evictor_.reset(); |
+ quota_manager_.reset(); |
+ MessageLoop::current()->RunAllPending(); |
+ } |
+ |
+ protected: |
+ /* |
+ MockStorageClient* CreateClient( |
+ const MockOriginData* mock_data, size_t mock_data_size) { |
+ MockStorageClient* client = new MockStorageClient(quota_manager_->proxy()); |
+ for (size_t i = 0; i < mock_data_size; ++i) { |
+ client->AddMockOriginData(GURL(mock_data[i].origin), |
+ mock_data[i].type, |
+ mock_data[i].usage); |
+ } |
+ return client; |
+ } |
+ */ |
+ |
+ void StartEviction() { |
+ temporary_storage_evictor_->Start(); |
+ } |
+ |
+ void Repeated() { |
+ temporary_storage_evictor_->set_repeated_eviction(true); |
+ } |
+ |
+ MockQuotaManager* quota_manager() const { |
+ return static_cast<MockQuotaManager*>(quota_manager_.get()); |
+ } |
+ |
+ QuotaTemporaryStorageEvictor* temporary_storage_evictor() const { |
+ return temporary_storage_evictor_.get(); |
+ } |
+ |
+ private: |
+ ScopedTempDir data_dir_; |
+ |
+ scoped_ptr<QuotaEvictionHandler> quota_manager_; |
+ scoped_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; |
+ |
+ QuotaStatusCode quota_status_; |
+ std::string host_; |
+ int64 usage_; |
+ int64 quota_; |
+ |
+ int additional_callback_count_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest); |
+}; |
+ |
+TEST_F(QuotaTemporaryStorageEvictorTest, Simple) { |
+ StartEviction(); |
+ MessageLoop::current()->RunAllPending(); |
+} |
+ |
+TEST_F(QuotaTemporaryStorageEvictorTest, Repeated) { |
+ Repeated(); |
+ StartEviction(); |
+ MessageLoop::current()->RunAllPending(); |
+} |
+ |
+} // namespace quota |