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_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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 base::Unretained(&size))); | 112 base::Unretained(&size))); |
112 counter.Restart(); | 113 counter.Restart(); |
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(base::Time(), base::Time::Max(), remove_mask, |
122 base::Time(), base::Time::Max(), remove_mask, | 123 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
123 BrowsingDataHelper::UNPROTECTED_WEB, &completion_observer); | 124 &completion_observer); |
124 completion_observer.BlockUntilCompletion(); | 125 completion_observer.BlockUntilCompletion(); |
125 } | 126 } |
126 | 127 |
127 void RemoveWithFilterAndWait( | 128 void RemoveWithFilterAndWait( |
128 int remove_mask, | 129 int remove_mask, |
129 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { | 130 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { |
130 BrowsingDataRemover* remover = | 131 BrowsingDataRemover* remover = |
131 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 132 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
132 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 133 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
133 remover->RemoveWithFilterAndReply( | 134 remover->RemoveWithFilterAndReply( |
134 base::Time(), base::Time::Max(), remove_mask, | 135 base::Time(), base::Time::Max(), remove_mask, |
135 BrowsingDataHelper::UNPROTECTED_WEB, std::move(filter_builder), | 136 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, |
136 &completion_observer); | 137 std::move(filter_builder), &completion_observer); |
137 completion_observer.BlockUntilCompletion(); | 138 completion_observer.BlockUntilCompletion(); |
138 } | 139 } |
139 | 140 |
140 private: | 141 private: |
141 void OnCacheSizeResult( | 142 void OnCacheSizeResult( |
142 base::RunLoop* run_loop, | 143 base::RunLoop* run_loop, |
143 browsing_data::BrowsingDataCounter::ResultInt* out_size, | 144 browsing_data::BrowsingDataCounter::ResultInt* out_size, |
144 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 145 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
145 if (!result->Finished()) | 146 if (!result->Finished()) |
146 return; | 147 return; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); | 188 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); |
188 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); | 189 EXPECT_FALSE(state->ShouldUpgradeToSSL("example.test")); |
189 state->AddHSTS("example.test", expiry, false); | 190 state->AddHSTS("example.test", expiry, false); |
190 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); | 191 EXPECT_TRUE(state->ShouldUpgradeToSSL("example.test")); |
191 } | 192 } |
192 }; | 193 }; |
193 | 194 |
194 // Test BrowsingDataRemover for downloads. | 195 // Test BrowsingDataRemover for downloads. |
195 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { | 196 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) { |
196 DownloadAnItem(); | 197 DownloadAnItem(); |
197 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); | 198 RemoveAndWait(BrowsingDataRemover::DATA_TYPE_DOWNLOADS); |
198 VerifyDownloadCount(0u); | 199 VerifyDownloadCount(0u); |
199 } | 200 } |
200 | 201 |
201 // 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 |
202 // process model prevents using a death test. | 203 // process model prevents using a death test. |
203 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 204 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
204 // Test BrowsingDataRemover for prohibited downloads. Note that this only | 205 // Test BrowsingDataRemover for prohibited downloads. Note that this only |
205 // really exercises the code in a Release build. | 206 // really exercises the code in a Release build. |
206 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) { | 207 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) { |
207 PrefService* prefs = browser()->profile()->GetPrefs(); | 208 PrefService* prefs = browser()->profile()->GetPrefs(); |
208 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); | 209 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); |
209 | 210 |
210 DownloadAnItem(); | 211 DownloadAnItem(); |
211 RemoveAndWait(BrowsingDataRemover::REMOVE_DOWNLOADS); | 212 RemoveAndWait(BrowsingDataRemover::DATA_TYPE_DOWNLOADS); |
212 VerifyDownloadCount(1u); | 213 VerifyDownloadCount(1u); |
213 } | 214 } |
214 #endif | 215 #endif |
215 | 216 |
216 // Verify can modify database after deleting it. | 217 // Verify can modify database after deleting it. |
217 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) { | 218 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Database) { |
218 GURL url = embedded_test_server()->GetURL("/simple_database.html"); | 219 GURL url = embedded_test_server()->GetURL("/simple_database.html"); |
219 LOG(ERROR) << url; | 220 LOG(ERROR) << url; |
220 ui_test_utils::NavigateToURL(browser(), url); | 221 ui_test_utils::NavigateToURL(browser(), url); |
221 | 222 |
222 RunScriptAndCheckResult("createTable()", "done"); | 223 RunScriptAndCheckResult("createTable()", "done"); |
223 RunScriptAndCheckResult("insertRecord('text')", "done"); | 224 RunScriptAndCheckResult("insertRecord('text')", "done"); |
224 RunScriptAndCheckResult("getRecords()", "text"); | 225 RunScriptAndCheckResult("getRecords()", "text"); |
225 | 226 |
226 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 227 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA); |
227 | 228 |
228 ui_test_utils::NavigateToURL(browser(), url); | 229 ui_test_utils::NavigateToURL(browser(), url); |
229 RunScriptAndCheckResult("createTable()", "done"); | 230 RunScriptAndCheckResult("createTable()", "done"); |
230 RunScriptAndCheckResult("insertRecord('text2')", "done"); | 231 RunScriptAndCheckResult("insertRecord('text2')", "done"); |
231 RunScriptAndCheckResult("getRecords()", "text2"); | 232 RunScriptAndCheckResult("getRecords()", "text2"); |
232 } | 233 } |
233 | 234 |
234 // Verify that cache deleting cache finishes successfully. Complete deletion | 235 // Verify that cache deleting cache finishes successfully. Complete deletion |
235 // 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 |
236 // 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... |
247 | 248 |
248 // The cache is nonempty, because we created entries by visiting websites. | 249 // The cache is nonempty, because we created entries by visiting websites. |
249 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); | 250 browsing_data::BrowsingDataCounter::ResultInt original_size = GetCacheSize(); |
250 EXPECT_GT(original_size, 0); | 251 EXPECT_GT(original_size, 0); |
251 | 252 |
252 // 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 |
253 // 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|. |
254 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder = | 255 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder = |
255 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); | 256 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); |
256 filter_builder->AddOrigin(url::Origin(url1)); | 257 filter_builder->AddOrigin(url::Origin(url1)); |
257 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, | 258 RemoveWithFilterAndWait(BrowsingDataRemover::DATA_TYPE_CACHE, |
258 std::move(filter_builder)); | 259 std::move(filter_builder)); |
259 | 260 |
260 // After the partial deletion, the cache should be smaller but still nonempty. | 261 // After the partial deletion, the cache should be smaller but still nonempty. |
261 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); | 262 browsing_data::BrowsingDataCounter::ResultInt new_size = GetCacheSize(); |
262 EXPECT_LT(new_size, original_size); | 263 EXPECT_LT(new_size, original_size); |
263 | 264 |
264 // Another partial deletion with the same filter should have no effect. | 265 // Another partial deletion with the same filter should have no effect. |
265 filter_builder = | 266 filter_builder = |
266 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); | 267 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST); |
267 filter_builder->AddOrigin(url::Origin(url1)); | 268 filter_builder->AddOrigin(url::Origin(url1)); |
268 RemoveWithFilterAndWait(BrowsingDataRemover::REMOVE_CACHE, | 269 RemoveWithFilterAndWait(BrowsingDataRemover::DATA_TYPE_CACHE, |
269 std::move(filter_builder)); | 270 std::move(filter_builder)); |
270 EXPECT_EQ(new_size, GetCacheSize()); | 271 EXPECT_EQ(new_size, GetCacheSize()); |
271 | 272 |
272 // Delete the remaining data. | 273 // Delete the remaining data. |
273 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 274 RemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE); |
274 | 275 |
275 // The cache is empty. | 276 // The cache is empty. |
276 EXPECT_EQ(0, GetCacheSize()); | 277 EXPECT_EQ(0, GetCacheSize()); |
277 } | 278 } |
278 | 279 |
279 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, | 280 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, |
280 ExternalProtocolHandlerPrefs) { | 281 ExternalProtocolHandlerPrefs) { |
281 Profile* profile = browser()->profile(); | 282 Profile* profile = browser()->profile(); |
282 base::DictionaryValue prefs; | 283 base::DictionaryValue prefs; |
283 prefs.SetBoolean("tel", true); | 284 prefs.SetBoolean("tel", true); |
284 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); | 285 profile->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); |
285 ExternalProtocolHandler::BlockState block_state = | 286 ExternalProtocolHandler::BlockState block_state = |
286 ExternalProtocolHandler::GetBlockState("tel", profile); | 287 ExternalProtocolHandler::GetBlockState("tel", profile); |
287 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); | 288 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); |
288 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 289 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA); |
289 block_state = ExternalProtocolHandler::GetBlockState("tel", profile); | 290 block_state = ExternalProtocolHandler::GetBlockState("tel", profile); |
290 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); | 291 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); |
291 } | 292 } |
292 | 293 |
293 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. | 294 // Verify that TransportSecurityState data is cleared for REMOVE_CACHE. |
294 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, | 295 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
295 ClearTransportSecurityState) { | 296 ClearTransportSecurityState) { |
296 RemoveAndWait(BrowsingDataRemover::REMOVE_CACHE); | 297 RemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE); |
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 true /* should be cleared */), | 305 true /* should be cleared */), |
305 run_loop.QuitClosure()); | 306 run_loop.QuitClosure()); |
306 } | 307 } |
307 | 308 |
308 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not | 309 // Verify that TransportSecurityState data is not cleared if REMOVE_CACHE is not |
309 // set. | 310 // set. |
310 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, | 311 IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest, |
311 PreserveTransportSecurityState) { | 312 PreserveTransportSecurityState) { |
312 RemoveAndWait(BrowsingDataRemover::REMOVE_SITE_DATA); | 313 RemoveAndWait(ChromeBrowsingDataRemoverDelegate::DATA_TYPE_SITE_DATA); |
313 base::RunLoop run_loop; | 314 base::RunLoop run_loop; |
314 BrowserThread::PostTaskAndReply( | 315 BrowserThread::PostTaskAndReply( |
315 BrowserThread::IO, FROM_HERE, | 316 BrowserThread::IO, FROM_HERE, |
316 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: | 317 base::Bind(&BrowsingDataRemoverTransportSecurityStateBrowserTest:: |
317 CheckTransportSecurityState, | 318 CheckTransportSecurityState, |
318 base::Unretained(this), | 319 base::Unretained(this), |
319 base::RetainedRef(browser()->profile()->GetRequestContext()), | 320 base::RetainedRef(browser()->profile()->GetRequestContext()), |
320 false /* should not be cleared */), | 321 false /* should not be cleared */), |
321 run_loop.QuitClosure()); | 322 run_loop.QuitClosure()); |
322 } | 323 } |
OLD | NEW |