Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/browsing_data_quota_helper_unittest.cc

Issue 7387007: Adding usage and quota entry to chrome://settings/cookies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/memory/scoped_callback_factory.h"
8 #include "base/message_loop_proxy.h"
9 #include "base/scoped_temp_dir.h"
10 #include "chrome/browser/browsing_data_quota_helper_impl.h"
11 #include "webkit/quota/mock_storage_client.h"
12 #include "webkit/quota/quota_manager.h"
13
14 class BrowsingDataQuotaHelperTest : public testing::Test {
15 public:
16 typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo;
17 typedef BrowsingDataQuotaHelper::QuotaInfoList QuotaInfoList;
18
19 BrowsingDataQuotaHelperTest()
20 : fetching_completed_(true),
21 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { }
22
23 virtual ~BrowsingDataQuotaHelperTest() { }
24
25 void SetUp() {
kinuko 2011/07/25 13:22:41 virtual?
tzik 2011/07/26 10:52:41 Done.
26 EXPECT_TRUE(dir_.CreateUniqueTempDir());
27 quota_manager_ = new quota::QuotaManager(
28 false, dir_.path(),
29 base::MessageLoopProxy::CreateForCurrentThread(), /* io_thread */
30 base::MessageLoopProxy::CreateForCurrentThread(), /* db_thread */
31 NULL);
32 helper_ = new BrowsingDataQuotaHelperImpl(
33 base::MessageLoopProxy::CreateForCurrentThread(), /* ui_thread */
34 base::MessageLoopProxy::CreateForCurrentThread(), /* io_thread */
kinuko 2011/07/25 13:22:41 not quite sure if we should rather create UI/IO/DB
35 quota_manager_);
36 }
37
38 void TearDown() {
kinuko 2011/07/25 13:22:41 virtual?
tzik 2011/07/26 10:52:41 Done.
39 helper_ = NULL;
40 quota_manager_ = NULL;
41 quota_info_.clear();
42 }
43
44 protected:
45 const QuotaInfoList& quota_info() {
46 return quota_info_;
47 }
48
49 bool fetching_completed() {
50 return fetching_completed_;
51 }
52
53 void StartFetching() {
54 fetching_completed_ = false;
55 helper_->StartFetching(
56 callback_factory_.NewCallback(
57 &BrowsingDataQuotaHelperTest::FetchCompleted));
58 }
59
60 void RegisterClient(const quota::MockOriginData* data, std::size_t data_len) {
61 quota::MockStorageClient* client =
62 new quota::MockStorageClient(
63 quota_manager_->proxy(), data, data_len);
64 quota_manager_->proxy()->RegisterClient(client);
65 client->NotifyAllOrigins();
66 }
67
68 private:
69 void FetchCompleted(const QuotaInfoList& quota_info) {
70 quota_info_ = quota_info;
71 fetching_completed_ = true;
72 }
73
74 MessageLoopForUI message_loop_;
75 scoped_refptr<quota::QuotaManager> quota_manager_;
76
77 ScopedTempDir dir_;
78 scoped_refptr<BrowsingDataQuotaHelper> helper_;
79
80 bool fetching_completed_;
81 QuotaInfoList quota_info_;
82 base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_;
83
84 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest);
85 };
86
87 TEST_F(BrowsingDataQuotaHelperTest, Empty) {
88 StartFetching();
89 MessageLoop::current()->RunAllPending();
90 EXPECT_TRUE(fetching_completed());
91 EXPECT_TRUE(quota_info().empty());
92 }
93
94 TEST_F(BrowsingDataQuotaHelperTest, FetchData) {
95 const quota::MockOriginData kOrigins[] = {
96 {"http://example.com/", quota::kStorageTypeTemporary, 1},
97 {"https://example.com/", quota::kStorageTypeTemporary, 10},
98 {"http://example.com/", quota::kStorageTypePersistent, 100},
99 {"http://example2.com/", quota::kStorageTypeTemporary, 1000},
100 };
101
102 RegisterClient(kOrigins, arraysize(kOrigins));
103 StartFetching();
104 MessageLoop::current()->RunAllPending();
105 EXPECT_TRUE(fetching_completed());
106
107 std::set<QuotaInfo> expected, actual;
108 actual.insert(quota_info().begin(), quota_info().end());
109 expected.insert(QuotaInfo("example.com", 11, 100, -1));
110 expected.insert(QuotaInfo("example2.com", 1000, -1, -1));
111 EXPECT_TRUE(expected == actual);
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698