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

Side by Side Diff: chrome/browser/browsing_data/cache_counter_browsertest.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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 16 matching lines...) Expand all
27 27
28 using content::BrowserContext; 28 using content::BrowserContext;
29 using content::BrowserThread; 29 using content::BrowserThread;
30 30
31 namespace { 31 namespace {
32 32
33 class CacheCounterTest : public InProcessBrowserTest { 33 class CacheCounterTest : public InProcessBrowserTest {
34 public: 34 public:
35 void SetUpOnMainThread() override { 35 void SetUpOnMainThread() override {
36 SetCacheDeletionPref(true); 36 SetCacheDeletionPref(true);
37 SetDeletionPeriodPref(browsing_data::ALL_TIME); 37 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
38 } 38 }
39 39
40 void SetCacheDeletionPref(bool value) { 40 void SetCacheDeletionPref(bool value) {
41 browser()->profile()->GetPrefs()->SetBoolean( 41 browser()->profile()->GetPrefs()->SetBoolean(
42 browsing_data::prefs::kDeleteCache, value); 42 browsing_data::prefs::kDeleteCache, value);
43 } 43 }
44 44
45 void SetDeletionPeriodPref(browsing_data::TimePeriod period) { 45 void SetDeletionPeriodPref(browsing_data::TimePeriod period) {
46 browser()->profile()->GetPrefs()->SetInteger( 46 browser()->profile()->GetPrefs()->SetInteger(
47 browsing_data::prefs::kDeleteTimePeriod, static_cast<int>(period)); 47 browsing_data::prefs::kDeleteTimePeriod, static_cast<int>(period));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 browsing_data::BrowsingDataCounter::ResultInt result_; 176 browsing_data::BrowsingDataCounter::ResultInt result_;
177 bool is_upper_limit_; 177 bool is_upper_limit_;
178 }; 178 };
179 179
180 // Tests that for the empty cache, the result is zero. 180 // Tests that for the empty cache, the result is zero.
181 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) { 181 IN_PROC_BROWSER_TEST_F(CacheCounterTest, Empty) {
182 Profile* profile = browser()->profile(); 182 Profile* profile = browser()->profile();
183 183
184 CacheCounter counter(profile); 184 CacheCounter counter(profile);
185 counter.Init( 185 counter.Init(
186 profile->GetPrefs(), 186 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
187 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); 187 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
188 counter.Restart(); 188 counter.Restart();
189 189
190 WaitForIOThread(); 190 WaitForIOThread();
191 EXPECT_EQ(0u, GetResult()); 191 EXPECT_EQ(0u, GetResult());
192 } 192 }
193 193
194 // Tests that for a non-empty cache, the result is nonzero. 194 // Tests that for a non-empty cache, the result is nonzero.
195 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) { 195 IN_PROC_BROWSER_TEST_F(CacheCounterTest, NonEmpty) {
196 CreateCacheEntry(); 196 CreateCacheEntry();
197 197
198 Profile* profile = browser()->profile(); 198 Profile* profile = browser()->profile();
199 CacheCounter counter(profile); 199 CacheCounter counter(profile);
200 counter.Init( 200 counter.Init(
201 profile->GetPrefs(), 201 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
202 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); 202 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
203 counter.Restart(); 203 counter.Restart();
204 204
205 WaitForIOThread(); 205 WaitForIOThread();
206 206
207 EXPECT_NE(0u, GetResult()); 207 EXPECT_NE(0u, GetResult());
208 } 208 }
209 209
210 // Tests that after dooming a nonempty cache, the result is zero. 210 // Tests that after dooming a nonempty cache, the result is zero.
211 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) { 211 IN_PROC_BROWSER_TEST_F(CacheCounterTest, AfterDoom) {
212 CreateCacheEntry(); 212 CreateCacheEntry();
213 213
214 Profile* profile = browser()->profile(); 214 Profile* profile = browser()->profile();
215 CacheCounter counter(profile); 215 CacheCounter counter(profile);
216 counter.Init( 216 counter.Init(
217 profile->GetPrefs(), 217 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
218 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); 218 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
219 219
220 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 220 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
221 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()), 221 content::BrowserContext::GetDefaultStoragePartition(browser()->profile()),
222 base::Time(), 222 base::Time(),
223 base::Time::Max())->Remove( 223 base::Time::Max())->Remove(
224 base::Bind(&CacheCounter::Restart, 224 base::Bind(&CacheCounter::Restart,
225 base::Unretained(&counter))); 225 base::Unretained(&counter)));
226 226
227 WaitForIOThread(); 227 WaitForIOThread();
228 EXPECT_EQ(0u, GetResult()); 228 EXPECT_EQ(0u, GetResult());
229 } 229 }
230 230
231 // Tests that the counter starts counting automatically when the deletion 231 // Tests that the counter starts counting automatically when the deletion
232 // pref changes to true. 232 // pref changes to true.
233 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) { 233 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PrefChanged) {
234 SetCacheDeletionPref(false); 234 SetCacheDeletionPref(false);
235 235
236 Profile* profile = browser()->profile(); 236 Profile* profile = browser()->profile();
237 CacheCounter counter(profile); 237 CacheCounter counter(profile);
238 counter.Init( 238 counter.Init(
239 profile->GetPrefs(), 239 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
240 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); 240 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
241 SetCacheDeletionPref(true); 241 SetCacheDeletionPref(true);
242 242
243 WaitForIOThread(); 243 WaitForIOThread();
244 EXPECT_EQ(0u, GetResult()); 244 EXPECT_EQ(0u, GetResult());
245 } 245 }
246 246
247 // Tests that the counting is restarted when the time period changes. 247 // Tests that the counting is restarted when the time period changes.
248 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) { 248 IN_PROC_BROWSER_TEST_F(CacheCounterTest, PeriodChanged) {
249 CreateCacheEntry(); 249 CreateCacheEntry();
250 250
251 Profile* profile = browser()->profile(); 251 Profile* profile = browser()->profile();
252 CacheCounter counter(profile); 252 CacheCounter counter(profile);
253 counter.Init( 253 counter.Init(
254 profile->GetPrefs(), 254 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED,
255 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this))); 255 base::Bind(&CacheCounterTest::CountingCallback, base::Unretained(this)));
256 256
257 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 257 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR);
258 WaitForIOThread(); 258 WaitForIOThread();
259 browsing_data::BrowsingDataCounter::ResultInt result = GetResult(); 259 browsing_data::BrowsingDataCounter::ResultInt result = GetResult();
260 260
261 SetDeletionPeriodPref(browsing_data::LAST_DAY); 261 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY);
262 WaitForIOThread(); 262 WaitForIOThread();
263 EXPECT_EQ(result, GetResult()); 263 EXPECT_EQ(result, GetResult());
264 264
265 SetDeletionPeriodPref(browsing_data::LAST_WEEK); 265 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK);
266 WaitForIOThread(); 266 WaitForIOThread();
267 EXPECT_EQ(result, GetResult()); 267 EXPECT_EQ(result, GetResult());
268 268
269 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); 269 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS);
270 WaitForIOThread(); 270 WaitForIOThread();
271 EXPECT_EQ(result, GetResult()); 271 EXPECT_EQ(result, GetResult());
272 272
273 SetDeletionPeriodPref(browsing_data::ALL_TIME); 273 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME);
274 WaitForIOThread(); 274 WaitForIOThread();
275 EXPECT_EQ(result, GetResult()); 275 EXPECT_EQ(result, GetResult());
276 EXPECT_FALSE(IsUpperLimit()); 276 EXPECT_FALSE(IsUpperLimit());
277 } 277 }
278 278
279 } // namespace 279 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/cache_counter.cc ('k') | chrome/browser/browsing_data/downloads_counter_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698