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