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

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

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" 13 #include "chrome/browser/browsing_data/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_remover.h" 14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 16 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
17 #include "chrome/browser/browsing_data/cache_counter.h" 17 #include "chrome/browser/browsing_data/cache_counter.h"
18 #include "chrome/browser/browsing_data/origin_filter_builder.h" 18 #include "chrome/browser/browsing_data/origin_filter_builder.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "components/browsing_data/browsing_data_utils.h"
26 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
27 #include "content/public/browser/browser_context.h" 28 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/download_manager.h" 30 #include "content/public/browser/download_manager.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/content_paths.h" 32 #include "content/public/common/content_paths.h"
32 #include "content/public/test/browser_test_utils.h" 33 #include "content/public/test/browser_test_utils.h"
33 #include "content/public/test/download_test_observer.h" 34 #include "content/public/test/download_test_observer.h"
34 #include "net/dns/mock_host_resolver.h" 35 #include "net/dns/mock_host_resolver.h"
35 #include "net/http/transport_security_state.h" 36 #include "net/http/transport_security_state.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 89
89 GURL download_url = ui_test_utils::GetTestUrl( 90 GURL download_url = ui_test_utils::GetTestUrl(
90 base::FilePath().AppendASCII("downloads"), 91 base::FilePath().AppendASCII("downloads"),
91 base::FilePath().AppendASCII("a_zip_file.zip")); 92 base::FilePath().AppendASCII("a_zip_file.zip"));
92 ui_test_utils::NavigateToURL(browser(), download_url); 93 ui_test_utils::NavigateToURL(browser(), download_url);
93 observer->WaitForFinished(); 94 observer->WaitForFinished();
94 95
95 VerifyDownloadCount(1u); 96 VerifyDownloadCount(1u);
96 } 97 }
97 98
98 BrowsingDataCounter::ResultInt GetCacheSize() { 99 browsing_data::BrowsingDataCounter::ResultInt GetCacheSize() {
99 base::RunLoop run_loop; 100 base::RunLoop run_loop;
100 BrowsingDataCounter::ResultInt size; 101 browsing_data::BrowsingDataCounter::ResultInt size;
101 102
102 CacheCounter counter; 103 Profile* profile = browser()->profile();
103 counter.Init(browser()->profile(), 104 CacheCounter counter(profile);
105 counter.Init(profile->GetPrefs(),
104 base::Bind(&BrowsingDataRemoverBrowserTest::OnCacheSizeResult, 106 base::Bind(&BrowsingDataRemoverBrowserTest::OnCacheSizeResult,
105 base::Unretained(this), 107 base::Unretained(this), base::Unretained(&run_loop),
106 base::Unretained(&run_loop),
107 base::Unretained(&size))); 108 base::Unretained(&size)));
108 counter.Restart(); 109 counter.Restart();
109 run_loop.Run(); 110 run_loop.Run();
110 return size; 111 return size;
111 } 112 }
112 113
113 void RemoveAndWait(int remove_mask) { 114 void RemoveAndWait(int remove_mask) {
114 BrowsingDataRemover* remover = 115 BrowsingDataRemover* remover =
115 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); 116 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
116 BrowsingDataRemoverCompletionObserver completion_observer(remover); 117 BrowsingDataRemoverCompletionObserver completion_observer(remover);
117 remover->Remove(BrowsingDataRemover::Period(BrowsingDataRemover::LAST_HOUR), 118 remover->Remove(BrowsingDataRemover::Period(browsing_data::LAST_HOUR),
118 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); 119 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
119 completion_observer.BlockUntilCompletion(); 120 completion_observer.BlockUntilCompletion();
120 } 121 }
121 122
122 void RemoveWithFilterAndWait( 123 void RemoveWithFilterAndWait(
123 int remove_mask, 124 int remove_mask,
124 const BrowsingDataFilterBuilder& filter_builder) { 125 const BrowsingDataFilterBuilder& filter_builder) {
125 BrowsingDataRemover* remover = 126 BrowsingDataRemover* remover =
126 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); 127 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
127 BrowsingDataRemoverCompletionObserver completion_observer(remover); 128 BrowsingDataRemoverCompletionObserver completion_observer(remover);
128 remover->RemoveWithFilter( 129 remover->RemoveWithFilter(
129 BrowsingDataRemover::Period(BrowsingDataRemover::LAST_HOUR), 130 BrowsingDataRemover::Period(browsing_data::LAST_HOUR), remove_mask,
130 remove_mask, BrowsingDataHelper::UNPROTECTED_WEB, filter_builder); 131 BrowsingDataHelper::UNPROTECTED_WEB, filter_builder);
131 completion_observer.BlockUntilCompletion(); 132 completion_observer.BlockUntilCompletion();
132 } 133 }
133 134
134 private: 135 private:
135 void OnCacheSizeResult( 136 void OnCacheSizeResult(
136 base::RunLoop* run_loop, 137 base::RunLoop* run_loop,
137 BrowsingDataCounter::ResultInt* out_size, 138 browsing_data::BrowsingDataCounter::ResultInt* out_size,
138 std::unique_ptr<BrowsingDataCounter::Result> result) { 139 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
139 if (!result->Finished()) 140 if (!result->Finished())
140 return; 141 return;
141 142
142 *out_size = static_cast<BrowsingDataCounter::FinishedResult*>( 143 *out_size =
143 result.get())->Value(); 144 static_cast<browsing_data::BrowsingDataCounter::FinishedResult*>(
145 result.get())
146 ->Value();
144 run_loop->Quit(); 147 run_loop->Quit();
145 } 148 }
146 }; 149 };
147 150
148 class BrowsingDataRemoverTransportSecurityStateBrowserTest 151 class BrowsingDataRemoverTransportSecurityStateBrowserTest
149 : public BrowsingDataRemoverBrowserTest { 152 : public BrowsingDataRemoverBrowserTest {
150 public: 153 public:
151 BrowsingDataRemoverTransportSecurityStateBrowserTest() {} 154 BrowsingDataRemoverTransportSecurityStateBrowserTest() {}
152 155
153 void SetUpOnMainThread() override { 156 void SetUpOnMainThread() override {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // in ConditionalCacheDeletionHelperBrowsertest. 233 // in ConditionalCacheDeletionHelperBrowsertest.
231 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Cache) { 234 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Cache) {
232 // Load several resources. 235 // Load several resources.
233 GURL url1 = embedded_test_server()->GetURL("/simple.html"); 236 GURL url1 = embedded_test_server()->GetURL("/simple.html");
234 GURL url2 = embedded_test_server()->GetURL(kExampleHost, "/simple.html"); 237 GURL url2 = embedded_test_server()->GetURL(kExampleHost, "/simple.html");
235 ASSERT_FALSE(url::IsSameOriginWith(url1, url2)); 238 ASSERT_FALSE(url::IsSameOriginWith(url1, url2));
236 ui_test_utils::NavigateToURL(browser(), url1); 239 ui_test_utils::NavigateToURL(browser(), url1);
237 ui_test_utils::NavigateToURL(browser(), url2); 240 ui_test_utils::NavigateToURL(browser(), url2);
238 241
239 // The cache is nonempty, because we created entries by visiting websites. 242 // The cache is nonempty, because we created entries by visiting websites.
240 BrowsingDataCounter::ResultInt original_size = GetCacheSize(); 243 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize();
241 EXPECT_GT(original_size, 0); 244 EXPECT_GT(original_size, 0);
242 245
243 // Partially delete cache data. Delete data for localhost, which is the origin 246 // Partially delete cache data. Delete data for localhost, which is the origin
244 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. 247 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|.
245 OriginFilterBuilder filter_builder(OriginFilterBuilder::WHITELIST); 248 OriginFilterBuilder filter_builder(OriginFilterBuilder::WHITELIST);
246 filter_builder.AddOrigin(url::Origin(url1)); 249 filter_builder.AddOrigin(url::Origin(url1));
247 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder); 250 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder);
248 251
249 // After the partial deletion, the cache should be smaller but still nonempty. 252 // After the partial deletion, the cache should be smaller but still nonempty.
250 BrowsingDataCounter::ResultInt new_size = GetCacheSize(); 253 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize();
251 EXPECT_LT(new_size, original_size); 254 EXPECT_LT(new_size, original_size);
252 255
253 // Another partial deletion with the same filter should have no effect. 256 // Another partial deletion with the same filter should have no effect.
254 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder); 257 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, filter_builder);
255 EXPECT_EQ(new_size, GetCacheSize()); 258 EXPECT_EQ(new_size, GetCacheSize());
256 259
257 // Delete the remaining data. 260 // Delete the remaining data.
258 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); 261 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE);
259 262
260 // The cache is empty. 263 // The cache is empty.
(...skipping 23 matching lines...) Expand all
284 base::RunLoop run_loop; 287 base::RunLoop run_loop;
285 BrowserThread::PostTaskAndReply( 288 BrowserThread::PostTaskAndReply(
286 BrowserThread::IO, FROM_HERE, 289 BrowserThread::IO, FROM_HERE,
287 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: 290 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest::
288 CheckTransportSecurityState, 291 CheckTransportSecurityState,
289 this, 292 this,
290 base::RetainedRef(browser()->profile()->GetRequestContext()), 293 base::RetainedRef(browser()->profile()->GetRequestContext()),
291 false /* should not be cleared */), 294 false /* should not be cleared */),
292 run_loop.QuitClosure()); 295 run_loop.QuitClosure());
293 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.cc ('k') | chrome/browser/browsing_data/browsing_data_remover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698