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

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

Issue 2733393003: Split browsing data masks between content and embedder (Closed)
Patch Set: Extensions can't match extensions if there are no extensions. 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) 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/chrome_browsing_data_remover_delegate.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/external_protocol/external_protocol_handler.h" 20 #include "chrome/browser/external_protocol/external_protocol_handler.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h" 25 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 26 #include "chrome/test/base/ui_test_utils.h"
26 #include "components/browsing_data/core/browsing_data_utils.h" 27 #include "components/browsing_data/core/browsing_data_utils.h"
27 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 run_loop.Run(); 114 run_loop.Run();
114 return size; 115 return size;
115 } 116 }
116 117
117 void RemoveAndWait(int remove_mask) { 118 void RemoveAndWait(int remove_mask) {
118 BrowsingDataRemover* remover = 119 BrowsingDataRemover* remover =
119 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); 120 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
120 BrowsingDataRemoverCompletionObserver completion_observer(remover); 121 BrowsingDataRemoverCompletionObserver completion_observer(remover);
121 remover->RemoveAndReply( 122 remover->RemoveAndReply(
122 base::Time(), base::Time::Max(), remove_mask, 123 base::Time(), base::Time::Max(), remove_mask,
123 BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); 124 ChromeBrowsingDataRemoverDelegate::ORIGIN_TYPE_UNPROTECTED_WEB,
125 &completion_observer);
124 completion_observer.BlockUntilCompletion(); 126 completion_observer.BlockUntilCompletion();
125 } 127 }
126 128
127 void RemoveWithFilterAndWait( 129 void RemoveWithFilterAndWait(
128 int remove_mask, 130 int remove_mask,
129 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { 131 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
130 BrowsingDataRemover* remover = 132 BrowsingDataRemover* remover =
131 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); 133 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
132 BrowsingDataRemoverCompletionObserver completion_observer(remover); 134 BrowsingDataRemoverCompletionObserver completion_observer(remover);
133 remover->RemoveWithFilterAndReply( 135 remover->RemoveWithFilterAndReply(
134 base::Time(), base::Time::Max(), remove_mask, 136 base::Time(), base::Time::Max(), remove_mask,
135 BrowsingDataHelper::UNPROTECTED_WEB, std::move(filter_builder), 137 ChromeBrowsingDataRemoverDelegate::ORIGIN_TYPE_UNPROTECTED_WEB,
138 std::move(filter_builder),
136 &completion_observer); 139 &completion_observer);
137 completion_observer.BlockUntilCompletion(); 140 completion_observer.BlockUntilCompletion();
138 } 141 }
139 142
140 private: 143 private:
141 void OnCacheSizeResult( 144 void OnCacheSizeResult(
142 base::RunLoop* run_loop, 145 base::RunLoop* run_loop,
143 browsing_data::BrowsingDataCounter::ResultInt* out_size, 146 browsing_data::BrowsingDataCounter::ResultInt* out_size,
144 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 147 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
145 if (!result->Finished()) 148 if (!result->Finished())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); 190 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
188 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); 191 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test"));
189 state->AddHSTS("example.test", expiry, false); 192 state->AddHSTS("example.test", expiry, false);
190 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); 193 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test"));
191 } 194 }
192 }; 195 };
193 196
194 // Test BrowsingDataRemover for downloads. 197 // Test BrowsingDataRemover for downloads.
195 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { 198 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) {
196 DownloadAnItem(); 199 DownloadAnItem();
197 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); 200 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_DOWNLOADS);
198 VerifyDownloadCount(0u); 201 VerifyDownloadCount(0u);
199 } 202 }
200 203
201 // The call to Remove() should crash in debug (DCHECK), but the browser-test 204 // The call to Remove() should crash in debug (DCHECK), but the browser-test
202 // process model prevents using a death test. 205 // process model prevents using a death test.
203 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 206 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
204 // Test BrowsingDataRemover for prohibited downloads. Note that this only 207 // Test BrowsingDataRemover for prohibited downloads. Note that this only
205 // really exercises the code in a Release build. 208 // really exercises the code in a Release build.
206 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) { 209 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) {
207 PrefService* prefs = browser()->profile()->GetPrefs(); 210 PrefService* prefs = browser()->profile()->GetPrefs();
208 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 211 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
209 212
210 DownloadAnItem(); 213 DownloadAnItem();
211 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); 214 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_DOWNLOADS);
212 VerifyDownloadCount(1u); 215 VerifyDownloadCount(1u);
213 } 216 }
214 #endif 217 #endif
215 218
216 // Verify can modify database after deleting it. 219 // Verify can modify database after deleting it.
217 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) { 220 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) {
218 GURL url = embedded_test_server()->GetURL("/simple_database.html"); 221 GURL url = embedded_test_server()->GetURL("/simple_database.html");
219 LOG(ERROR) << url; 222 LOG(ERROR) << url;
220 ui_test_utils::NavigateToURL(browser(), url); 223 ui_test_utils::NavigateToURL(browser(), url);
221 224
222 RunScriptAndCheckResult("createTable()", "done"); 225 RunScriptAndCheckResult("createTable()", "done");
223 RunScriptAndCheckResult("insertRecord('text')", "done"); 226 RunScriptAndCheckResult("insertRecord('text')", "done");
224 RunScriptAndCheckResult("getRecords()", "text"); 227 RunScriptAndCheckResult("getRecords()", "text");
225 228
226 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); 229 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA);
227 230
228 ui_test_utils::NavigateToURL(browser(), url); 231 ui_test_utils::NavigateToURL(browser(), url);
229 RunScriptAndCheckResult("createTable()", "done"); 232 RunScriptAndCheckResult("createTable()", "done");
230 RunScriptAndCheckResult("insertRecord('text2')", "done"); 233 RunScriptAndCheckResult("insertRecord('text2')", "done");
231 RunScriptAndCheckResult("getRecords()", "text2"); 234 RunScriptAndCheckResult("getRecords()", "text2");
232 } 235 }
233 236
234 // Verify that cache deleting cache finishes successfully. Complete deletion 237 // Verify that cache deleting cache finishes successfully. Complete deletion
235 // of cache should leave it empty, and partial deletion should leave nonzero 238 // of cache should leave it empty, and partial deletion should leave nonzero
236 // amount of data. Note that this tests the integration of BrowsingDataRemover 239 // amount of data. Note that this tests the integration of BrowsingDataRemover
(...skipping 10 matching lines...) Expand all
247 250
248 // The cache is nonempty, because we created entries by visiting websites. 251 // The cache is nonempty, because we created entries by visiting websites.
249 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); 252 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize();
250 EXPECT_GT(original_size, 0); 253 EXPECT_GT(original_size, 0);
251 254
252 // Partially delete cache data. Delete data for localhost, which is the origin 255 // Partially delete cache data. Delete data for localhost, which is the origin
253 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. 256 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|.
254 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder = 257 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder =
255 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); 258 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
256 filter_builder->AddOrigin(url::Origin(url1)); 259 filter_builder->AddOrigin(url::Origin(url1));
257 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, 260 RemoveWithFilterAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_CACHE,
258 std::move(filter_builder)); 261 std::move(filter_builder));
259 262
260 // After the partial deletion, the cache should be smaller but still nonempty. 263 // After the partial deletion, the cache should be smaller but still nonempty.
261 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); 264 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize();
262 EXPECT_LT(new_size, original_size); 265 EXPECT_LT(new_size, original_size);
263 266
264 // Another partial deletion with the same filter should have no effect. 267 // Another partial deletion with the same filter should have no effect.
265 filter_builder = 268 filter_builder =
266 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); 269 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
267 filter_builder->AddOrigin(url::Origin(url1)); 270 filter_builder->AddOrigin(url::Origin(url1));
268 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, 271 RemoveWithFilterAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_CACHE,
269 std::move(filter_builder)); 272 std::move(filter_builder));
270 EXPECT_EQ(new_size, GetCacheSize()); 273 EXPECT_EQ(new_size, GetCacheSize());
271 274
272 // Delete the remaining data. 275 // Delete the remaining data.
273 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); 276 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_CACHE);
274 277
275 // The cache is empty. 278 // The cache is empty.
276 EXPECT_EQ(0, GetCacheSize()); 279 EXPECT_EQ(0, GetCacheSize());
277 } 280 }
278 281
279 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, 282 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
280 ExternalProtocolHandlerPrefs) { 283 ExternalProtocolHandlerPrefs) {
281 Profile* profile = browser()->profile(); 284 Profile* profile = browser()->profile();
282 base::DictionaryValue prefs; 285 base::DictionaryValue prefs;
283 prefs.SetBoolean("tel", true); 286 prefs.SetBoolean("tel", true);
284 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); 287 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs);
285 ExternalProtocolHandler::BlockState block_state = 288 ExternalProtocolHandler::BlockState block_state =
286 ExternalProtocolHandler::GetBlockState("tel", profile); 289 ExternalProtocolHandler::GetBlockState("tel", profile);
287 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); 290 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state);
288 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); 291 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA);
289 block_state = ExternalProtocolHandler::GetBlockState("tel", profile); 292 block_state = ExternalProtocolHandler::GetBlockState("tel", profile);
290 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); 293 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state);
291 } 294 }
292 295
293 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. 296 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE.
294 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, 297 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest,
295 ClearTransportSecurityState) { 298 ClearTransportSecurityState) {
296 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); 299 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_CACHE);
297 base::RunLoop run_loop; 300 base::RunLoop run_loop;
298 BrowserThread::PostTaskAndReply( 301 BrowserThread::PostTaskAndReply(
299 BrowserThread::IO, FROM_HERE, 302 BrowserThread::IO, FROM_HERE,
300 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: 303 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest::
301 CheckTransportSecurityState, 304 CheckTransportSecurityState,
302 base::Unretained(this), 305 base::Unretained(this),
303 base::RetainedRef(browser()->profile()->GetRequestContext()), 306 base::RetainedRef(browser()->profile()->GetRequestContext()),
304 true /* should be cleared */), 307 true /* should be cleared */),
305 run_loop.QuitClosure()); 308 run_loop.QuitClosure());
306 } 309 }
307 310
308 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not 311 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not
309 // set. 312 // set.
310 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, 313 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest,
311 PreserveTransportSecurityState) { 314 PreserveTransportSecurityState) {
312 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); 315 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA);
313 base::RunLoop run_loop; 316 base::RunLoop run_loop;
314 BrowserThread::PostTaskAndReply( 317 BrowserThread::PostTaskAndReply(
315 BrowserThread::IO, FROM_HERE, 318 BrowserThread::IO, FROM_HERE,
316 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: 319 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest::
317 CheckTransportSecurityState, 320 CheckTransportSecurityState,
318 base::Unretained(this), 321 base::Unretained(this),
319 base::RetainedRef(browser()->profile()->GetRequestContext()), 322 base::RetainedRef(browser()->profile()->GetRequestContext()),
320 false /* should not be cleared */), 323 false /* should not be cleared */),
321 run_loop.QuitClosure()); 324 run_loop.QuitClosure());
322 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698