| 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..eadfb384800ac8f10e256c12dc80465184933c8e
|
| --- /dev/null
|
| +++ b/webkit/quota/quota_temporary_storage_evictor_unittest.cc
|
| @@ -0,0 +1,147 @@
|
| +// 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_database.h"
|
| +#include "webkit/quota/quota_manager.h"
|
| +#include "webkit/quota/quota_temporary_storage_evictor.h"
|
| +
|
| +namespace quota {
|
| +
|
| +namespace {
|
| +
|
| +class MockQuotaManager : public quota::QuotaManager {
|
| + public:
|
| + MockQuotaManager(const FilePath& profile_path, int64 usage, int64 quota)
|
| + : quota::QuotaManager(false /* is_incognito */,
|
| + profile_path,
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + base::MessageLoopProxy::CreateForCurrentThread()),
|
| + test_profile_path_(profile_path),
|
| + usage_(usage),
|
| + quota_(quota) {}
|
| +
|
| + virtual void GetUsageAndQuota(const GURL& origin, quota::StorageType type,
|
| + GetUsageAndQuotaCallback* callback) {
|
| + callback->Run(quota::kQuotaStatusOk, usage_, quota_);
|
| + delete callback;
|
| + }
|
| +
|
| + virtual void DeleteOriginDataOnIOThread(
|
| + const GURL& origin,
|
| + StorageType type,
|
| + DeleteOriginDataCallback* callback) {
|
| + callback->Run(quota::kQuotaStatusOk);
|
| + delete callback;
|
| + }
|
| +
|
| + void set_usage(int64 usage) { usage_ = usage; }
|
| + void set_quota(int64 quota) { quota_ = quota; }
|
| +
|
| + private:
|
| + FilePath test_profile_path_;
|
| + int64 usage_;
|
| + int64 quota_;
|
| +};
|
| +
|
| +class MockQuotaDatabase : public quota::QuotaDatabase {
|
| + public:
|
| + MockQuotaDatabase() : QuotaDatabase(FilePath()) {}
|
| +
|
| + virtual GURL GetLRUOriginExceptFor(StorageType type,
|
| + const std::set<GURL>& exceptions) {
|
| + return GURL("http://www.example.com");
|
| + }
|
| +
|
| + private:
|
| +};
|
| +
|
| +} // anonymous namespace
|
| +
|
| +class QuotaTemporaryStorageEvictorTest : public testing::Test {
|
| + public:
|
| + QuotaTemporaryStorageEvictorTest() {}
|
| +
|
| + void SetUp() {
|
| + ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
|
| +
|
| + quota_manager_ = new MockQuotaManager(data_dir_.path(), 0, 1000);
|
| + quota_database_.reset(new MockQuotaDatabase());
|
| +
|
| + temporary_storage_evictor_ = new QuotaTemporaryStorageEvictor(
|
| + quota_manager_.get(), quota_database_.get(), 3000,
|
| + base::MessageLoopProxy::CreateForCurrentThread(),
|
| + base::MessageLoopProxy::CreateForCurrentThread());
|
| +
|
| + additional_callback_count_ = 0;
|
| + }
|
| +
|
| + void TearDown() {
|
| + temporary_storage_evictor_ = NULL;
|
| + quota_database_.reset(NULL);
|
| +
|
| + // Make sure the quota manager cleans up correctly.
|
| + quota_manager_ = 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;
|
| + }
|
| + */
|
| +
|
| + MockQuotaManager* quota_manager() const {
|
| + return static_cast<MockQuotaManager*>(quota_manager_.get());
|
| + }
|
| +
|
| + MockQuotaDatabase* quota_database() const {
|
| + return static_cast<MockQuotaDatabase*>(quota_database_.get());
|
| + }
|
| +
|
| + QuotaTemporaryStorageEvictor* temporary_storage_evictor() const {
|
| + return temporary_storage_evictor_.get();
|
| + }
|
| +
|
| + private:
|
| + ScopedTempDir data_dir_;
|
| +
|
| + scoped_refptr<QuotaManager> quota_manager_;
|
| + scoped_ptr<QuotaDatabase> quota_database_;
|
| + 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) {
|
| + temporary_storage_evictor()->Start();
|
| + MessageLoop::current()->RunAllPending();
|
| +}
|
| +
|
| +} // namespace quota
|
|
|