| 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..e6eb53d233a401ae266948554ec91c99e7823be8
|
| --- /dev/null
|
| +++ b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
|
| @@ -0,0 +1,136 @@
|
| +// 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/ref_counted.h"
|
| +#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 {
|
| +
|
| +// TODO(dmikurube): Add an interface between QuotaManager and Evictor.
|
| +// Do not use mock, and implement the interface here.
|
| +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 void DeleteOriginData(
|
| + const GURL& origin,
|
| + StorageType type,
|
| + DeleteOriginDataCallback* callback) {
|
| + LOG(ERROR) << "MockQM::DeleteOriginData";
|
| + callback->Run(quota::kQuotaStatusOk, 3000, 100000, 1000000000);
|
| + delete callback;
|
| + }
|
| +
|
| + virtual void GetUsageAndQuotaForEviction(
|
| + DeleteOriginDataCallback* callback) {
|
| + LOG(ERROR) << "MockQM::GetUsageAndQuotaForEviction";
|
| + callback->Run(quota::kQuotaStatusOk, 3000, 100000, 1000000000);
|
| + delete callback;
|
| + }
|
| +
|
| + virtual void GetLRUOrigin(
|
| + StorageType type,
|
| + GetLRUOriginCallback* callback) {
|
| + 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(), 0, 1000));
|
| +
|
| + temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor(
|
| + 10000000, 3000, base::MessageLoopProxy::CreateForCurrentThread());
|
| +
|
| + temporary_storage_evictor_->RegisterQuotaManagerOnIOThread(
|
| + quota_manager_.get());
|
| +
|
| + additional_callback_count_ = 0;
|
| + }
|
| +
|
| + void TearDown() {
|
| + temporary_storage_evictor_ = NULL;
|
| + quota_manager_.reset(NULL);
|
| + 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();
|
| + }
|
| +
|
| + 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_refptr<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();
|
| +}
|
| +
|
| +} // namespace quota
|
|
|