OLD | NEW |
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_types.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" |
28 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
29 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/browsing_data_filter_builder.h" | 31 #include "content/public/browser/browsing_data_filter_builder.h" |
31 #include "content/public/browser/download_manager.h" | 32 #include "content/public/browser/download_manager.h" |
32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/content_paths.h" | 34 #include "content/public/common/content_paths.h" |
34 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
35 #include "content/public/test/download_test_observer.h" | 36 #include "content/public/test/download_test_observer.h" |
36 #include "net/dns/mock_host_resolver.h" | 37 #include "net/dns/mock_host_resolver.h" |
37 #include "net/http/transport_security_state.h" | 38 #include "net/http/transport_security_state.h" |
38 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
39 #include "net/url_request/url_request_context.h" | 40 #include "net/url_request/url_request_context.h" |
40 #include "net/url_request/url_request_context_getter.h" | 41 #include "net/url_request/url_request_context_getter.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
42 | 43 |
43 using content::BrowserThread; | 44 using content::BrowserThread; |
44 using content::BrowsingDataFilterBuilder; | 45 using content::BrowsingDataFilterBuilder; |
| 46 using content::BrowsingDataType; |
45 | 47 |
46 namespace { | 48 namespace { |
47 static const char* kExampleHost = "example.com"; | 49 static const char* kExampleHost = "example.com"; |
48 } | 50 } |
49 | 51 |
50 class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest { | 52 class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest { |
51 public: | 53 public: |
52 BrowsingDataRemoverBrowserTest() {} | 54 BrowsingDataRemoverBrowserTest() {} |
53 | 55 |
54 void SetUpOnMainThread() override { | 56 void SetUpOnMainThread() override { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 CacheCounter counter(profile); | 108 CacheCounter counter(profile); |
107 counter.Init(profile->GetPrefs(), | 109 counter.Init(profile->GetPrefs(), |
108 base::Bind(&BrowsingDataRemoverBrowserTest::OnCacheSizeResult, | 110 base::Bind(&BrowsingDataRemoverBrowserTest::OnCacheSizeResult, |
109 base::Unretained(this), base::Unretained(&run_loop), | 111 base::Unretained(this), base::Unretained(&run_loop), |
110 base::Unretained(&size))); | 112 base::Unretained(&size))); |
111 counter.Restart(); | 113 counter.Restart(); |
112 run_loop.Run(); | 114 run_loop.Run(); |
113 return size; | 115 return size; |
114 } | 116 } |
115 | 117 |
116 void RemoveAndWait(int remove_mask) { | 118 void RemoveAndWait(const std::set<const BrowsingDataType*>& remove_mask) { |
117 BrowsingDataRemover* remover = | 119 BrowsingDataRemover* remover = |
118 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 120 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
119 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 121 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
120 remover->RemoveAndReply( | 122 remover->RemoveAndReply( |
121 base::Time(), base::Time::Max(), remove_mask, | 123 base::Time(), base::Time::Max(), remove_mask, |
122 BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); | 124 BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); |
123 completion_observer.BlockUntilCompletion(); | 125 completion_observer.BlockUntilCompletion(); |
124 } | 126 } |
125 | 127 |
126 void RemoveWithFilterAndWait( | 128 void RemoveWithFilterAndWait( |
127 int remove_mask, | 129 const std::set<const BrowsingDataType*>& remove_mask, |
128 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { | 130 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { |
129 BrowsingDataRemover* remover = | 131 BrowsingDataRemover* remover = |
130 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 132 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
131 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 133 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
132 remover->RemoveWithFilterAndReply( | 134 remover->RemoveWithFilterAndReply( |
133 base::Time(), base::Time::Max(), remove_mask, | 135 base::Time(), base::Time::Max(), remove_mask, |
134 BrowsingDataHelper::UNPROTECTED_WEB, std::move(filter_builder), | 136 BrowsingDataHelper::UNPROTECTED_WEB, std::move(filter_builder), |
135 &completion_observer); | 137 &completion_observer); |
136 completion_observer.BlockUntilCompletion(); | 138 completion_observer.BlockUntilCompletion(); |
137 } | 139 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 188 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
187 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); | 189 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); |
188 state->AddHSTS("example.test", expiry, false); | 190 state->AddHSTS("example.test", expiry, false); |
189 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); | 191 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); |
190 } | 192 } |
191 }; | 193 }; |
192 | 194 |
193 // Test BrowsingDataRemover for downloads. | 195 // Test BrowsingDataRemover for downloads. |
194 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { | 196 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { |
195 DownloadAnItem(); | 197 DownloadAnItem(); |
196 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); | 198 RemoveAndWait({&kBrowsingDataTypeDownloads}); |
197 VerifyDownloadCount(0u); | 199 VerifyDownloadCount(0u); |
198 } | 200 } |
199 | 201 |
200 // The call to Remove() should crash in debug (DCHECK), but the browser-test | 202 // The call to Remove() should crash in debug (DCHECK), but the browser-test |
201 // process model prevents using a death test. | 203 // process model prevents using a death test. |
202 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 204 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
203 // Test BrowsingDataRemover for prohibited downloads. Note that this only | 205 // Test BrowsingDataRemover for prohibited downloads. Note that this only |
204 // really exercises the code in a Release build. | 206 // really exercises the code in a Release build. |
205 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) { | 207 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) { |
206 PrefService* prefs = browser()->profile()->GetPrefs(); | 208 PrefService* prefs = browser()->profile()->GetPrefs(); |
207 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | 209 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
208 | 210 |
209 DownloadAnItem(); | 211 DownloadAnItem(); |
210 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); | 212 RemoveAndWait({&kBrowsingDataTypeDownloads}); |
211 VerifyDownloadCount(1u); | 213 VerifyDownloadCount(1u); |
212 } | 214 } |
213 #endif | 215 #endif |
214 | 216 |
215 // Verify can modify database after deleting it. | 217 // Verify can modify database after deleting it. |
216 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) { | 218 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) { |
217 GURL url = embedded_test_server()->GetURL("/simple_database.html"); | 219 GURL url = embedded_test_server()->GetURL("/simple_database.html"); |
218 LOG(ERROR) << url; | 220 LOG(ERROR) << url; |
219 ui_test_utils::NavigateToURL(browser(), url); | 221 ui_test_utils::NavigateToURL(browser(), url); |
220 | 222 |
221 RunScriptAndCheckResult("createTable()", "done"); | 223 RunScriptAndCheckResult("createTable()", "done"); |
222 RunScriptAndCheckResult("insertRecord('text')", "done"); | 224 RunScriptAndCheckResult("insertRecord('text')", "done"); |
223 RunScriptAndCheckResult("getRecords()", "text"); | 225 RunScriptAndCheckResult("getRecords()", "text"); |
224 | 226 |
225 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 227 RemoveAndWait(BrowsingDataTypeSetSiteData()); |
226 | 228 |
227 ui_test_utils::NavigateToURL(browser(), url); | 229 ui_test_utils::NavigateToURL(browser(), url); |
228 RunScriptAndCheckResult("createTable()", "done"); | 230 RunScriptAndCheckResult("createTable()", "done"); |
229 RunScriptAndCheckResult("insertRecord('text2')", "done"); | 231 RunScriptAndCheckResult("insertRecord('text2')", "done"); |
230 RunScriptAndCheckResult("getRecords()", "text2"); | 232 RunScriptAndCheckResult("getRecords()", "text2"); |
231 } | 233 } |
232 | 234 |
233 // Verify that cache deleting cache finishes successfully. Complete deletion | 235 // Verify that cache deleting cache finishes successfully. Complete deletion |
234 // of cache should leave it empty, and partial deletion should leave nonzero | 236 // of cache should leave it empty, and partial deletion should leave nonzero |
235 // amount of data. Note that this tests the integration of BrowsingDataRemover | 237 // amount of data. Note that this tests the integration of BrowsingDataRemover |
(...skipping 10 matching lines...) Expand all Loading... |
246 | 248 |
247 // The cache is nonempty, because we created entries by visiting websites. | 249 // The cache is nonempty, because we created entries by visiting websites. |
248 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); | 250 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); |
249 EXPECT_GT(original_size, 0); | 251 EXPECT_GT(original_size, 0); |
250 | 252 |
251 // Partially delete cache data. Delete data for localhost, which is the origin | 253 // Partially delete cache data. Delete data for localhost, which is the origin |
252 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. | 254 // of |url1|, but not for |kExampleHost|, which is the origin of |url2|. |
253 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder = | 255 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder = |
254 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); | 256 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); |
255 filter_builder->AddOrigin(url::Origin(url1)); | 257 filter_builder->AddOrigin(url::Origin(url1)); |
256 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, | 258 RemoveWithFilterAndWait({&kBrowsingDataTypeCache}, std::move(filter_builder)); |
257 std::move(filter_builder)); | |
258 | 259 |
259 // After the partial deletion, the cache should be smaller but still nonempty. | 260 // After the partial deletion, the cache should be smaller but still nonempty. |
260 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); | 261 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); |
261 EXPECT_LT(new_size, original_size); | 262 EXPECT_LT(new_size, original_size); |
262 | 263 |
263 // Another partial deletion with the same filter should have no effect. | 264 // Another partial deletion with the same filter should have no effect. |
264 filter_builder = | 265 filter_builder = |
265 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); | 266 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); |
266 filter_builder->AddOrigin(url::Origin(url1)); | 267 filter_builder->AddOrigin(url::Origin(url1)); |
267 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, | 268 RemoveWithFilterAndWait({&kBrowsingDataTypeCache}, std::move(filter_builder)); |
268 std::move(filter_builder)); | |
269 EXPECT_EQ(new_size, GetCacheSize()); | 269 EXPECT_EQ(new_size, GetCacheSize()); |
270 | 270 |
271 // Delete the remaining data. | 271 // Delete the remaining data. |
272 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 272 RemoveAndWait({&kBrowsingDataTypeCache}); |
273 | 273 |
274 // The cache is empty. | 274 // The cache is empty. |
275 EXPECT_EQ(0, GetCacheSize()); | 275 EXPECT_EQ(0, GetCacheSize()); |
276 } | 276 } |
277 | 277 |
278 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, | 278 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, |
279 ExternalProtocolHandlerPrefs) { | 279 ExternalProtocolHandlerPrefs) { |
280 Profile* profile = browser()->profile(); | 280 Profile* profile = browser()->profile(); |
281 base::DictionaryValue prefs; | 281 base::DictionaryValue prefs; |
282 prefs.SetBoolean("tel", true); | 282 prefs.SetBoolean("tel", true); |
283 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); | 283 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); |
284 ExternalProtocolHandler::BlockState block_state = | 284 ExternalProtocolHandler::BlockState block_state = |
285 ExternalProtocolHandler::GetBlockState("tel", profile); | 285 ExternalProtocolHandler::GetBlockState("tel", profile); |
286 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); | 286 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); |
287 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 287 RemoveAndWait(BrowsingDataTypeSetSiteData()); |
288 block_state = ExternalProtocolHandler::GetBlockState("tel", profile); | 288 block_state = ExternalProtocolHandler::GetBlockState("tel", profile); |
289 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); | 289 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); |
290 } | 290 } |
291 | 291 |
292 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. | 292 // Verify that TransportSecurityState data is cleared |
| 293 // for kBrowsingDataTypeCache. |
293 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, | 294 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
294 ClearTransportSecurityState) { | 295 ClearTransportSecurityState) { |
295 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 296 RemoveAndWait({&kBrowsingDataTypeCache}); |
296 base::RunLoop run_loop; | 297 base::RunLoop run_loop; |
297 BrowserThread::PostTaskAndReply( | 298 BrowserThread::PostTaskAndReply( |
298 BrowserThread::IO, FROM_HERE, | 299 BrowserThread::IO, FROM_HERE, |
299 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: | 300 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
300 CheckTransportSecurityState, | 301 CheckTransportSecurityState, |
301 base::Unretained(this), | 302 base::Unretained(this), |
302 base::RetainedRef(browser()->profile()->GetRequestContext()), | 303 base::RetainedRef(browser()->profile()->GetRequestContext()), |
303 true /* should be cleared */), | 304 true /* should be cleared */), |
304 run_loop.QuitClosure()); | 305 run_loop.QuitClosure()); |
305 } | 306 } |
306 | 307 |
307 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not | 308 // Verify that TransportSecurityState data is not cleared |
308 // set. | 309 // if kBrowsingDataTypeCache is not set. |
309 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, | 310 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
310 PreserveTransportSecurityState) { | 311 PreserveTransportSecurityState) { |
311 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 312 RemoveAndWait(BrowsingDataTypeSetSiteData()); |
312 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
313 BrowserThread::PostTaskAndReply( | 314 BrowserThread::PostTaskAndReply( |
314 BrowserThread::IO, FROM_HERE, | 315 BrowserThread::IO, FROM_HERE, |
315 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: | 316 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
316 CheckTransportSecurityState, | 317 CheckTransportSecurityState, |
317 base::Unretained(this), | 318 base::Unretained(this), |
318 base::RetainedRef(browser()->profile()->GetRequestContext()), | 319 base::RetainedRef(browser()->profile()->GetRequestContext()), |
319 false /* should not be cleared */), | 320 false /* should not be cleared */), |
320 run_loop.QuitClosure()); | 321 run_loop.QuitClosure()); |
321 } | 322 } |
OLD | NEW |