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

Side by Side Diff: ios/chrome/browser/browsing_data/cache_counter_unittest.cc

Issue 2671743002: Separate state of basic and advanced tab in CBD dialog (Closed)
Patch Set: rebase and fix compilation Created 3 years, 9 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Note that this file only tests the basic behavior of the cache counter, as in 5 // Note that this file only tests the basic behavior of the cache counter, as in
6 // when it counts and when not, when result is nonzero and when not. It does not 6 // when it counts and when not, when result is nonzero and when not. It does not
7 // test whether the result of the counting is correct. This is the 7 // test whether the result of the counting is correct. This is the
8 // responsibility of a lower layer, and is tested in 8 // responsibility of a lower layer, and is tested in
9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests. 9 // DiskCacheBackendTest.CalculateSizeOfAllEntries in net_unittests.
10 10
(...skipping 17 matching lines...) Expand all
28 #include "net/url_request/url_request_context_getter.h" 28 #include "net/url_request/url_request_context_getter.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 namespace { 31 namespace {
32 32
33 class CacheCounterTest : public testing::Test { 33 class CacheCounterTest : public testing::Test {
34 public: 34 public:
35 CacheCounterTest() { 35 CacheCounterTest() {
36 prefs_.registry()->RegisterIntegerPref( 36 prefs_.registry()->RegisterIntegerPref(
37 browsing_data::prefs::kDeleteTimePeriod, 37 browsing_data::prefs::kDeleteTimePeriod,
38 static_cast<int>(browsing_data::ALL_TIME)); 38 static_cast<int>(browsing_data::TimePeriod::ALL_TIME));
39 prefs_.registry()->RegisterBooleanPref(browsing_data::prefs::kDeleteCache, 39 prefs_.registry()->RegisterBooleanPref(browsing_data::prefs::kDeleteCache,
40 true); 40 true);
41 41
42 context_getter_ = browser_state_.GetRequestContext(); 42 context_getter_ = browser_state_.GetRequestContext();
43 } 43 }
44 44
45 ~CacheCounterTest() override {} 45 ~CacheCounterTest() override {}
46 46
47 web::TestBrowserState* browser_state() { return &browser_state_; } 47 web::TestBrowserState* browser_state() { return &browser_state_; }
48 48
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 bool finished_; 229 bool finished_;
230 browsing_data::BrowsingDataCounter::ResultInt result_; 230 browsing_data::BrowsingDataCounter::ResultInt result_;
231 231
232 web::TestBrowserState browser_state_; 232 web::TestBrowserState browser_state_;
233 TestingPrefServiceSimple prefs_; 233 TestingPrefServiceSimple prefs_;
234 }; 234 };
235 235
236 // Tests that for the empty cache, the result is zero. 236 // Tests that for the empty cache, the result is zero.
237 TEST_F(CacheCounterTest, Empty) { 237 TEST_F(CacheCounterTest, Empty) {
238 CacheCounter counter(browser_state()); 238 CacheCounter counter(browser_state());
239 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, 239 counter.Init(
240 base::Unretained(this))); 240 prefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
241 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
241 counter.Restart(); 242 counter.Restart();
242 243
243 WaitForIOThread(); 244 WaitForIOThread();
244 EXPECT_EQ(0u, GetResult()); 245 EXPECT_EQ(0u, GetResult());
245 } 246 }
246 247
247 // Tests that for a non-empty cache, the result is nonzero, and after deleting 248 // Tests that for a non-empty cache, the result is nonzero, and after deleting
248 // its contents, it's zero again. Note that the exact value of the result 249 // its contents, it's zero again. Note that the exact value of the result
249 // is tested in DiskCacheBackendTest.CalculateSizeOfAllEntries. 250 // is tested in DiskCacheBackendTest.CalculateSizeOfAllEntries.
250 TEST_F(CacheCounterTest, BeforeAndAfterClearing) { 251 TEST_F(CacheCounterTest, BeforeAndAfterClearing) {
251 CreateCacheEntry(); 252 CreateCacheEntry();
252 253
253 CacheCounter counter(browser_state()); 254 CacheCounter counter(browser_state());
254 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, 255 counter.Init(
255 base::Unretained(this))); 256 prefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
257 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
256 counter.Restart(); 258 counter.Restart();
257 259
258 WaitForIOThread(); 260 WaitForIOThread();
259 EXPECT_NE(0u, GetResult()); 261 EXPECT_NE(0u, GetResult());
260 262
261 ClearCache(); 263 ClearCache();
262 counter.Restart(); 264 counter.Restart();
263 265
264 WaitForIOThread(); 266 WaitForIOThread();
265 EXPECT_EQ(0u, GetResult()); 267 EXPECT_EQ(0u, GetResult());
266 } 268 }
267 269
268 // Tests that the counter starts counting automatically when the deletion 270 // Tests that the counter starts counting automatically when the deletion
269 // pref changes to true. 271 // pref changes to true.
270 TEST_F(CacheCounterTest, PrefChanged) { 272 TEST_F(CacheCounterTest, PrefChanged) {
271 SetCacheDeletionPref(false); 273 SetCacheDeletionPref(false);
272 274
273 CacheCounter counter(browser_state()); 275 CacheCounter counter(browser_state());
274 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, 276 counter.Init(
275 base::Unretained(this))); 277 prefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
278 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
276 SetCacheDeletionPref(true); 279 SetCacheDeletionPref(true);
277 280
278 WaitForIOThread(); 281 WaitForIOThread();
279 EXPECT_EQ(0u, GetResult()); 282 EXPECT_EQ(0u, GetResult());
280 } 283 }
281 284
282 // Tests that the counting is restarted when the time period changes. Currently, 285 // Tests that the counting is restarted when the time period changes. Currently,
283 // the results should be the same for every period. This is because the counter 286 // the results should be the same for every period. This is because the counter
284 // always counts the size of the entire cache, and it is up to the UI 287 // always counts the size of the entire cache, and it is up to the UI
285 // to interpret it as exact value or upper bound. 288 // to interpret it as exact value or upper bound.
286 TEST_F(CacheCounterTest, PeriodChanged) { 289 TEST_F(CacheCounterTest, PeriodChanged) {
287 CreateCacheEntry(); 290 CreateCacheEntry();
288 291
289 CacheCounter counter(browser_state()); 292 CacheCounter counter(browser_state());
290 counter.Init(prefs(), base::Bind(&CacheCounterTest::CountingCallback, 293 counter.Init(
291 base::Unretained(this))); 294 prefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
295 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
292 296
293 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 297 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR);
294 WaitForIOThread(); 298 WaitForIOThread();
295 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); 299 browsing_data::BrowsingDataCounter::ResultInt result = GetResult();
296 300
297 SetDeletionPeriodPref(browsing_data::LAST_DAY); 301 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY);
298 WaitForIOThread(); 302 WaitForIOThread();
299 EXPECT_EQ(result, GetResult()); 303 EXPECT_EQ(result, GetResult());
300 304
301 SetDeletionPeriodPref(browsing_data::LAST_WEEK); 305 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK);
302 WaitForIOThread(); 306 WaitForIOThread();
303 EXPECT_EQ(result, GetResult()); 307 EXPECT_EQ(result, GetResult());
304 308
305 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); 309 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS);
306 WaitForIOThread(); 310 WaitForIOThread();
307 EXPECT_EQ(result, GetResult()); 311 EXPECT_EQ(result, GetResult());
308 312
309 SetDeletionPeriodPref(browsing_data::ALL_TIME); 313 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
310 WaitForIOThread(); 314 WaitForIOThread();
311 EXPECT_EQ(result, GetResult()); 315 EXPECT_EQ(result, GetResult());
312 } 316 }
313 317
314 } // namespace 318 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698