| OLD | NEW |
| 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 |
| 11 #include "chrome/browser/browsing_data/cache_counter.h" | 11 #include "chrome/browser/browsing_data/cache_counter.h" |
| 12 | 12 |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "components/browsing_data/browsing_data_utils.h" | 18 #include "components/browsing_data/browsing_data_utils.h" |
| 20 #include "components/browsing_data/pref_names.h" | 19 #include "components/browsing_data/pref_names.h" |
| 21 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" | 20 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
| 22 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 23 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
| 24 #include "net/disk_cache/disk_cache.h" | 23 #include "net/disk_cache/disk_cache.h" |
| 25 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 26 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 28 | 27 |
| 29 using content::BrowserContext; | 28 using content::BrowserContext; |
| 30 using content::BrowserThread; | 29 using content::BrowserThread; |
| 31 | 30 |
| 32 namespace { | 31 namespace { |
| 33 | 32 |
| 34 class CacheCounterTest : public InProcessBrowserTest { | 33 class CacheCounterTest : public InProcessBrowserTest { |
| 35 public: | 34 public: |
| 36 void SetUpOnMainThread() override { | 35 void SetUpOnMainThread() override { |
| 37 SetCacheDeletionPref(true); | 36 SetCacheDeletionPref(true); |
| 38 SetDeletionPeriodPref(browsing_data::EVERYTHING); | 37 SetDeletionPeriodPref(browsing_data::EVERYTHING); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void SetCacheDeletionPref(bool value) { | 40 void SetCacheDeletionPref(bool value) { |
| 42 browser()->profile()->GetPrefs()->SetBoolean(prefs::kDeleteCache, value); | 41 browser()->profile()->GetPrefs()->SetBoolean( |
| 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)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // One step in the process of creating a cache entry. Every step must be | 50 // One step in the process of creating a cache entry. Every step must be |
| 51 // executed on IO thread after the previous one has finished. | 51 // executed on IO thread after the previous one has finished. |
| 52 void CreateCacheEntryStep(int return_value) { | 52 void CreateCacheEntryStep(int return_value) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 280 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
| 281 WaitForIOThread(); | 281 WaitForIOThread(); |
| 282 EXPECT_EQ(result, GetResult()); | 282 EXPECT_EQ(result, GetResult()); |
| 283 | 283 |
| 284 SetDeletionPeriodPref(browsing_data::EVERYTHING); | 284 SetDeletionPeriodPref(browsing_data::EVERYTHING); |
| 285 WaitForIOThread(); | 285 WaitForIOThread(); |
| 286 EXPECT_EQ(result, GetResult()); | 286 EXPECT_EQ(result, GetResult()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace | 289 } // namespace |
| OLD | NEW |