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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 helper_ = new BrowsingDataQuotaHelperImpl( 42 helper_ = new BrowsingDataQuotaHelperImpl(
43 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), 43 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), 44 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
45 quota_manager_); 45 quota_manager_);
46 } 46 }
47 47
48 virtual void TearDown() OVERRIDE { 48 virtual void TearDown() OVERRIDE {
49 helper_ = NULL; 49 helper_ = NULL;
50 quota_manager_ = NULL; 50 quota_manager_ = NULL;
51 quota_info_.clear(); 51 quota_info_.clear();
52 MessageLoop::current()->RunUntilIdle(); 52 base::MessageLoop::current()->RunUntilIdle();
53 } 53 }
54 54
55 protected: 55 protected:
56 const QuotaInfoArray& quota_info() const { 56 const QuotaInfoArray& quota_info() const {
57 return quota_info_; 57 return quota_info_;
58 } 58 }
59 59
60 bool fetching_completed() const { 60 bool fetching_completed() const {
61 return fetching_completed_; 61 return fetching_completed_;
62 } 62 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 int64 quota() { 106 int64 quota() {
107 return quota_; 107 return quota_;
108 } 108 }
109 109
110 private: 110 private:
111 void FetchCompleted(const QuotaInfoArray& quota_info) { 111 void FetchCompleted(const QuotaInfoArray& quota_info) {
112 quota_info_ = quota_info; 112 quota_info_ = quota_info;
113 fetching_completed_ = true; 113 fetching_completed_ = true;
114 } 114 }
115 115
116 MessageLoop message_loop_; 116 base::MessageLoop message_loop_;
117 content::TestBrowserThread ui_thread_; 117 content::TestBrowserThread ui_thread_;
118 content::TestBrowserThread db_thread_; 118 content::TestBrowserThread db_thread_;
119 content::TestBrowserThread io_thread_; 119 content::TestBrowserThread io_thread_;
120 scoped_refptr<quota::QuotaManager> quota_manager_; 120 scoped_refptr<quota::QuotaManager> quota_manager_;
121 121
122 base::ScopedTempDir dir_; 122 base::ScopedTempDir dir_;
123 scoped_refptr<BrowsingDataQuotaHelper> helper_; 123 scoped_refptr<BrowsingDataQuotaHelper> helper_;
124 124
125 bool fetching_completed_; 125 bool fetching_completed_;
126 QuotaInfoArray quota_info_; 126 QuotaInfoArray quota_info_;
127 int64 quota_; 127 int64 quota_;
128 base::WeakPtrFactory<BrowsingDataQuotaHelperTest> weak_factory_; 128 base::WeakPtrFactory<BrowsingDataQuotaHelperTest> weak_factory_;
129 129
130 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); 130 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest);
131 }; 131 };
132 132
133 TEST_F(BrowsingDataQuotaHelperTest, Empty) { 133 TEST_F(BrowsingDataQuotaHelperTest, Empty) {
134 StartFetching(); 134 StartFetching();
135 MessageLoop::current()->RunUntilIdle(); 135 base::MessageLoop::current()->RunUntilIdle();
136 EXPECT_TRUE(fetching_completed()); 136 EXPECT_TRUE(fetching_completed());
137 EXPECT_TRUE(quota_info().empty()); 137 EXPECT_TRUE(quota_info().empty());
138 } 138 }
139 139
140 TEST_F(BrowsingDataQuotaHelperTest, FetchData) { 140 TEST_F(BrowsingDataQuotaHelperTest, FetchData) {
141 const quota::MockOriginData kOrigins[] = { 141 const quota::MockOriginData kOrigins[] = {
142 {"http://example.com/", quota::kStorageTypeTemporary, 1}, 142 {"http://example.com/", quota::kStorageTypeTemporary, 1},
143 {"https://example.com/", quota::kStorageTypeTemporary, 10}, 143 {"https://example.com/", quota::kStorageTypeTemporary, 10},
144 {"http://example.com/", quota::kStorageTypePersistent, 100}, 144 {"http://example.com/", quota::kStorageTypePersistent, 100},
145 {"https://example.com/", quota::kStorageTypeSyncable, 1}, 145 {"https://example.com/", quota::kStorageTypeSyncable, 1},
146 {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, 146 {"http://example2.com/", quota::kStorageTypeTemporary, 1000},
147 }; 147 };
148 148
149 RegisterClient(kOrigins, arraysize(kOrigins)); 149 RegisterClient(kOrigins, arraysize(kOrigins));
150 StartFetching(); 150 StartFetching();
151 MessageLoop::current()->RunUntilIdle(); 151 base::MessageLoop::current()->RunUntilIdle();
152 EXPECT_TRUE(fetching_completed()); 152 EXPECT_TRUE(fetching_completed());
153 153
154 std::set<QuotaInfo> expected, actual; 154 std::set<QuotaInfo> expected, actual;
155 actual.insert(quota_info().begin(), quota_info().end()); 155 actual.insert(quota_info().begin(), quota_info().end());
156 expected.insert(QuotaInfo("example.com", 11, 100, 1)); 156 expected.insert(QuotaInfo("example.com", 11, 100, 1));
157 expected.insert(QuotaInfo("example2.com", 1000, 0, 0)); 157 expected.insert(QuotaInfo("example2.com", 1000, 0, 0));
158 EXPECT_TRUE(expected == actual); 158 EXPECT_TRUE(expected == actual);
159 } 159 }
160 160
161 TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensionsAndDevTools) { 161 TEST_F(BrowsingDataQuotaHelperTest, IgnoreExtensionsAndDevTools) {
162 const quota::MockOriginData kOrigins[] = { 162 const quota::MockOriginData kOrigins[] = {
163 {"http://example.com/", quota::kStorageTypeTemporary, 1}, 163 {"http://example.com/", quota::kStorageTypeTemporary, 1},
164 {"https://example.com/", quota::kStorageTypeTemporary, 10}, 164 {"https://example.com/", quota::kStorageTypeTemporary, 10},
165 {"http://example.com/", quota::kStorageTypePersistent, 100}, 165 {"http://example.com/", quota::kStorageTypePersistent, 100},
166 {"https://example.com/", quota::kStorageTypeSyncable, 1}, 166 {"https://example.com/", quota::kStorageTypeSyncable, 1},
167 {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, 167 {"http://example2.com/", quota::kStorageTypeTemporary, 1000},
168 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/", 168 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/",
169 quota::kStorageTypeTemporary, 10000}, 169 quota::kStorageTypeTemporary, 10000},
170 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/", 170 {"chrome-extension://abcdefghijklmnopqrstuvwxyz/",
171 quota::kStorageTypePersistent, 100000}, 171 quota::kStorageTypePersistent, 100000},
172 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", 172 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/",
173 quota::kStorageTypeTemporary, 10000}, 173 quota::kStorageTypeTemporary, 10000},
174 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/", 174 {"chrome-devtools://abcdefghijklmnopqrstuvwxyz/",
175 quota::kStorageTypePersistent, 100000}, 175 quota::kStorageTypePersistent, 100000},
176 }; 176 };
177 177
178 RegisterClient(kOrigins, arraysize(kOrigins)); 178 RegisterClient(kOrigins, arraysize(kOrigins));
179 StartFetching(); 179 StartFetching();
180 MessageLoop::current()->RunUntilIdle(); 180 base::MessageLoop::current()->RunUntilIdle();
181 EXPECT_TRUE(fetching_completed()); 181 EXPECT_TRUE(fetching_completed());
182 182
183 std::set<QuotaInfo> expected, actual; 183 std::set<QuotaInfo> expected, actual;
184 actual.insert(quota_info().begin(), quota_info().end()); 184 actual.insert(quota_info().begin(), quota_info().end());
185 expected.insert(QuotaInfo("example.com", 11, 100, 1)); 185 expected.insert(QuotaInfo("example.com", 11, 100, 1));
186 expected.insert(QuotaInfo("example2.com", 1000, 0, 0)); 186 expected.insert(QuotaInfo("example2.com", 1000, 0, 0));
187 EXPECT_TRUE(expected == actual); 187 EXPECT_TRUE(expected == actual);
188 } 188 }
189 189
190 TEST_F(BrowsingDataQuotaHelperTest, RevokeHostQuota) { 190 TEST_F(BrowsingDataQuotaHelperTest, RevokeHostQuota) {
191 const std::string kHost1("example1.com"); 191 const std::string kHost1("example1.com");
192 const std::string kHost2("example2.com"); 192 const std::string kHost2("example2.com");
193 193
194 SetPersistentHostQuota(kHost1, 1); 194 SetPersistentHostQuota(kHost1, 1);
195 SetPersistentHostQuota(kHost2, 10); 195 SetPersistentHostQuota(kHost2, 10);
196 MessageLoop::current()->RunUntilIdle(); 196 base::MessageLoop::current()->RunUntilIdle();
197 197
198 RevokeHostQuota(kHost1); 198 RevokeHostQuota(kHost1);
199 MessageLoop::current()->RunUntilIdle(); 199 base::MessageLoop::current()->RunUntilIdle();
200 200
201 GetPersistentHostQuota(kHost1); 201 GetPersistentHostQuota(kHost1);
202 MessageLoop::current()->RunUntilIdle(); 202 base::MessageLoop::current()->RunUntilIdle();
203 EXPECT_EQ(0, quota()); 203 EXPECT_EQ(0, quota());
204 204
205 GetPersistentHostQuota(kHost2); 205 GetPersistentHostQuota(kHost2);
206 MessageLoop::current()->RunUntilIdle(); 206 base::MessageLoop::current()->RunUntilIdle();
207 EXPECT_EQ(10, quota()); 207 EXPECT_EQ(10, quota());
208 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698