Chromium Code Reviews| Index: chrome/browser/browsing_data_quota_helper_unittest.cc |
| diff --git a/chrome/browser/browsing_data_quota_helper_unittest.cc b/chrome/browser/browsing_data_quota_helper_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..021bc2207436d724ef5cbbb1cb1aa7d3a637e44e |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data_quota_helper_unittest.cc |
| @@ -0,0 +1,112 @@ |
| +// 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 "base/memory/scoped_callback_factory.h" |
| +#include "base/message_loop_proxy.h" |
| +#include "base/scoped_temp_dir.h" |
| +#include "chrome/browser/browsing_data_quota_helper_impl.h" |
| +#include "webkit/quota/mock_storage_client.h" |
| +#include "webkit/quota/quota_manager.h" |
| + |
| +class BrowsingDataQuotaHelperTest : public testing::Test { |
| + public: |
| + typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo; |
| + typedef BrowsingDataQuotaHelper::QuotaInfoList QuotaInfoList; |
| + |
| + BrowsingDataQuotaHelperTest() |
| + : fetching_completed_(true), |
| + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } |
| + |
| + virtual ~BrowsingDataQuotaHelperTest() { } |
| + |
| + void SetUp() { |
|
kinuko
2011/07/25 13:22:41
virtual?
tzik
2011/07/26 10:52:41
Done.
|
| + EXPECT_TRUE(dir_.CreateUniqueTempDir()); |
| + quota_manager_ = new quota::QuotaManager( |
| + false, dir_.path(), |
| + base::MessageLoopProxy::CreateForCurrentThread(), /* io_thread */ |
| + base::MessageLoopProxy::CreateForCurrentThread(), /* db_thread */ |
| + NULL); |
| + helper_ = new BrowsingDataQuotaHelperImpl( |
| + base::MessageLoopProxy::CreateForCurrentThread(), /* ui_thread */ |
| + base::MessageLoopProxy::CreateForCurrentThread(), /* io_thread */ |
|
kinuko
2011/07/25 13:22:41
not quite sure if we should rather create UI/IO/DB
|
| + quota_manager_); |
| + } |
| + |
| + void TearDown() { |
|
kinuko
2011/07/25 13:22:41
virtual?
tzik
2011/07/26 10:52:41
Done.
|
| + helper_ = NULL; |
| + quota_manager_ = NULL; |
| + quota_info_.clear(); |
| + } |
| + |
| + protected: |
| + const QuotaInfoList& quota_info() { |
| + return quota_info_; |
| + } |
| + |
| + bool fetching_completed() { |
| + return fetching_completed_; |
| + } |
| + |
| + void StartFetching() { |
| + fetching_completed_ = false; |
| + helper_->StartFetching( |
| + callback_factory_.NewCallback( |
| + &BrowsingDataQuotaHelperTest::FetchCompleted)); |
| + } |
| + |
| + void RegisterClient(const quota::MockOriginData* data, std::size_t data_len) { |
| + quota::MockStorageClient* client = |
| + new quota::MockStorageClient( |
| + quota_manager_->proxy(), data, data_len); |
| + quota_manager_->proxy()->RegisterClient(client); |
| + client->NotifyAllOrigins(); |
| + } |
| + |
| + private: |
| + void FetchCompleted(const QuotaInfoList& quota_info) { |
| + quota_info_ = quota_info; |
| + fetching_completed_ = true; |
| + } |
| + |
| + MessageLoopForUI message_loop_; |
| + scoped_refptr<quota::QuotaManager> quota_manager_; |
| + |
| + ScopedTempDir dir_; |
| + scoped_refptr<BrowsingDataQuotaHelper> helper_; |
| + |
| + bool fetching_completed_; |
| + QuotaInfoList quota_info_; |
| + base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); |
| +}; |
| + |
| +TEST_F(BrowsingDataQuotaHelperTest, Empty) { |
| + StartFetching(); |
| + MessageLoop::current()->RunAllPending(); |
| + EXPECT_TRUE(fetching_completed()); |
| + EXPECT_TRUE(quota_info().empty()); |
| +} |
| + |
| +TEST_F(BrowsingDataQuotaHelperTest, FetchData) { |
| + const quota::MockOriginData kOrigins[] = { |
| + {"http://example.com/", quota::kStorageTypeTemporary, 1}, |
| + {"https://example.com/", quota::kStorageTypeTemporary, 10}, |
| + {"http://example.com/", quota::kStorageTypePersistent, 100}, |
| + {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, |
| + }; |
| + |
| + RegisterClient(kOrigins, arraysize(kOrigins)); |
| + StartFetching(); |
| + MessageLoop::current()->RunAllPending(); |
| + EXPECT_TRUE(fetching_completed()); |
| + |
| + std::set<QuotaInfo> expected, actual; |
| + actual.insert(quota_info().begin(), quota_info().end()); |
| + expected.insert(QuotaInfo("example.com", 11, 100, -1)); |
| + expected.insert(QuotaInfo("example2.com", 1000, -1, -1)); |
| + EXPECT_TRUE(expected == actual); |
| +} |