| 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 "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/task/cancelable_task_tracker.h" | 24 #include "base/task/cancelable_task_tracker.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 26 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 28 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 30 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| 31 #include "chrome/browser/browsing_data/origin_filter_builder.h" | 31 #include "chrome/browser/browsing_data/origin_filter_builder.h" |
| 32 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 32 #include "chrome/browser/domain_reliability/service_factory.h" | 33 #include "chrome/browser/domain_reliability/service_factory.h" |
| 33 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 34 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 34 #include "chrome/browser/favicon/favicon_service_factory.h" | 35 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 35 #include "chrome/browser/history/history_service_factory.h" | 36 #include "chrome/browser/history/history_service_factory.h" |
| 36 #include "chrome/browser/password_manager/password_store_factory.h" | 37 #include "chrome/browser/password_manager/password_store_factory.h" |
| 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 38 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/test/base/testing_browser_process.h" | 40 #include "chrome/test/base/testing_browser_process.h" |
| 40 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
| 41 #include "components/autofill/core/browser/autofill_profile.h" | 42 #include "components/autofill/core/browser/autofill_profile.h" |
| 42 #include "components/autofill/core/browser/autofill_test_utils.h" | 43 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 43 #include "components/autofill/core/browser/credit_card.h" | 44 #include "components/autofill/core/browser/credit_card.h" |
| 44 #include "components/autofill/core/browser/personal_data_manager.h" | 45 #include "components/autofill/core/browser/personal_data_manager.h" |
| 45 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 46 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 46 #include "components/bookmarks/browser/bookmark_model.h" | 47 #include "components/bookmarks/browser/bookmark_model.h" |
| 47 #include "components/bookmarks/test/bookmark_test_helpers.h" | 48 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 49 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 50 #include "components/content_settings/core/common/content_settings.h" |
| 51 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 48 #include "components/domain_reliability/clear_mode.h" | 52 #include "components/domain_reliability/clear_mode.h" |
| 49 #include "components/domain_reliability/monitor.h" | 53 #include "components/domain_reliability/monitor.h" |
| 50 #include "components/domain_reliability/service.h" | 54 #include "components/domain_reliability/service.h" |
| 51 #include "components/favicon/core/favicon_service.h" | 55 #include "components/favicon/core/favicon_service.h" |
| 52 #include "components/history/core/browser/history_service.h" | 56 #include "components/history/core/browser/history_service.h" |
| 53 #include "components/omnibox/browser/omnibox_pref_names.h" | 57 #include "components/omnibox/browser/omnibox_pref_names.h" |
| 54 #include "components/password_manager/core/browser/mock_password_store.h" | 58 #include "components/password_manager/core/browser/mock_password_store.h" |
| 55 #include "components/password_manager/core/browser/password_manager_test_utils.h
" | 59 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
| 56 #include "components/password_manager/core/browser/password_store_consumer.h" | 60 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 57 #include "components/prefs/testing_pref_service.h" | 61 #include "components/prefs/testing_pref_service.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 137 |
| 134 const base::FilePath::CharType kDomStorageOrigin2[] = | 138 const base::FilePath::CharType kDomStorageOrigin2[] = |
| 135 FILE_PATH_LITERAL("http_host2_1.localstorage"); | 139 FILE_PATH_LITERAL("http_host2_1.localstorage"); |
| 136 | 140 |
| 137 const base::FilePath::CharType kDomStorageOrigin3[] = | 141 const base::FilePath::CharType kDomStorageOrigin3[] = |
| 138 FILE_PATH_LITERAL("http_host3_1.localstorage"); | 142 FILE_PATH_LITERAL("http_host3_1.localstorage"); |
| 139 | 143 |
| 140 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( | 144 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( |
| 141 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); | 145 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); |
| 142 | 146 |
| 147 bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary, |
| 148 const ContentSettingsPattern& primary_pattern, |
| 149 const ContentSettingsPattern& secondary_pattern) { |
| 150 return expected_primary == primary_pattern; |
| 151 } |
| 152 |
| 143 #if defined(OS_CHROMEOS) | 153 #if defined(OS_CHROMEOS) |
| 144 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { | 154 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { |
| 145 base::MessageLoop::current()->PostTask( | 155 base::MessageLoop::current()->PostTask( |
| 146 FROM_HERE, | 156 FROM_HERE, |
| 147 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); | 157 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); |
| 148 } | 158 } |
| 149 #endif | 159 #endif |
| 150 | 160 |
| 151 struct StoragePartitionRemovalData { | 161 struct StoragePartitionRemovalData { |
| 152 uint32_t remove_mask = 0; | 162 uint32_t remove_mask = 0; |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, | 1023 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 1014 int remove_mask, | 1024 int remove_mask, |
| 1015 const GURL& remove_origin) { | 1025 const GURL& remove_origin) { |
| 1016 BrowsingDataRemover* remover = | 1026 BrowsingDataRemover* remover = |
| 1017 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); | 1027 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); |
| 1018 TestStoragePartition storage_partition; | 1028 TestStoragePartition storage_partition; |
| 1019 remover->OverrideStoragePartitionForTesting(&storage_partition); | 1029 remover->OverrideStoragePartitionForTesting(&storage_partition); |
| 1020 | 1030 |
| 1021 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 1031 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 1022 | 1032 |
| 1033 OriginFilterBuilder builder(OriginFilterBuilder::WHITELIST); |
| 1034 builder.AddOrigin(url::Origin(remove_origin)); |
| 1023 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 1035 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
| 1024 remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask, | 1036 remover->RemoveImpl(BrowsingDataRemover::Period(period), remove_mask, |
| 1025 remove_origin, BrowsingDataHelper::UNPROTECTED_WEB); | 1037 builder, BrowsingDataHelper::UNPROTECTED_WEB); |
| 1026 completion_observer.BlockUntilCompletion(); | 1038 completion_observer.BlockUntilCompletion(); |
| 1027 | 1039 |
| 1028 // Save so we can verify later. | 1040 // Save so we can verify later. |
| 1029 storage_partition_removal_data_ = | 1041 storage_partition_removal_data_ = |
| 1030 storage_partition.GetStoragePartitionRemovalData(); | 1042 storage_partition.GetStoragePartitionRemovalData(); |
| 1031 } | 1043 } |
| 1032 | 1044 |
| 1033 TestingProfile* GetProfile() { | 1045 TestingProfile* GetProfile() { |
| 1034 return profile_.get(); | 1046 return profile_.get(); |
| 1035 } | 1047 } |
| (...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2270 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { | 2282 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) { |
| 2271 RemovePasswordsTester tester(GetProfile()); | 2283 RemovePasswordsTester tester(GetProfile()); |
| 2272 const url::Origin expectedOrigin(kOrigin1); | 2284 const url::Origin expectedOrigin(kOrigin1); |
| 2273 | 2285 |
| 2274 EXPECT_CALL(*tester.store(), | 2286 EXPECT_CALL(*tester.store(), |
| 2275 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) | 2287 RemoveLoginsByOriginAndTimeImpl(SameOrigin(expectedOrigin), _, _)) |
| 2276 .WillOnce(Return(password_manager::PasswordStoreChangeList())); | 2288 .WillOnce(Return(password_manager::PasswordStoreChangeList())); |
| 2277 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, | 2289 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 2278 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); | 2290 BrowsingDataRemover::REMOVE_PASSWORDS, kOrigin1); |
| 2279 } | 2291 } |
| 2292 |
| 2293 TEST_F(BrowsingDataRemoverTest, ClearWithPredicate) { |
| 2294 TestingProfile profile; |
| 2295 HostContentSettingsMap* host_content_settings_map = |
| 2296 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 2297 ContentSettingsForOneType host_settings; |
| 2298 |
| 2299 // Patterns with wildcards. |
| 2300 ContentSettingsPattern pattern = |
| 2301 ContentSettingsPattern::FromString("[*.]example.org"); |
| 2302 ContentSettingsPattern pattern2 = |
| 2303 ContentSettingsPattern::FromString("[*.]example.net"); |
| 2304 |
| 2305 // Patterns without wildcards. |
| 2306 GURL url1("https://www.google.com/"); |
| 2307 GURL url2("https://www.google.com/maps"); |
| 2308 GURL url3("http://www.google.com/maps"); |
| 2309 GURL url3_origin_only("http://www.google.com/"); |
| 2310 |
| 2311 host_content_settings_map->SetContentSetting( |
| 2312 pattern2, ContentSettingsPattern::Wildcard(), |
| 2313 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), CONTENT_SETTING_BLOCK); |
| 2314 host_content_settings_map->SetContentSetting( |
| 2315 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_IMAGES, |
| 2316 std::string(), CONTENT_SETTING_BLOCK); |
| 2317 host_content_settings_map->SetContentSetting( |
| 2318 pattern2, ContentSettingsPattern::Wildcard(), |
| 2319 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), CONTENT_SETTING_BLOCK); |
| 2320 |
| 2321 // First, test that we clear only IMAGES (not APP_BANNER), and pattern2. |
| 2322 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
| 2323 host_content_settings_map, CONTENT_SETTINGS_TYPE_IMAGES, |
| 2324 base::Bind(&MatchPrimaryPattern, pattern2)); |
| 2325 host_content_settings_map->GetSettingsForOneType( |
| 2326 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); |
| 2327 // |host_settings| contains default & block. |
| 2328 EXPECT_EQ(2U, host_settings.size()); |
| 2329 EXPECT_EQ(pattern, host_settings[0].primary_pattern); |
| 2330 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); |
| 2331 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); |
| 2332 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); |
| 2333 |
| 2334 host_content_settings_map->GetSettingsForOneType( |
| 2335 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), &host_settings); |
| 2336 // |host_settings| contains block. |
| 2337 EXPECT_EQ(1U, host_settings.size()); |
| 2338 EXPECT_EQ(pattern2, host_settings[0].primary_pattern); |
| 2339 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); |
| 2340 |
| 2341 // Next, test that we do correct pattern matching w/ an origin policy item. |
| 2342 // We verify that we have no settings stored. |
| 2343 host_content_settings_map->GetSettingsForOneType( |
| 2344 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
| 2345 EXPECT_EQ(0u, host_settings.size()); |
| 2346 // Add settings. |
| 2347 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2348 url1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 2349 new base::FundamentalValue(10)); |
| 2350 // This setting should override the one above, as it's the same origin. |
| 2351 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2352 url2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 2353 new base::FundamentalValue(10)); |
| 2354 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2355 url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), |
| 2356 new base::FundamentalValue(10)); |
| 2357 // Verify we only have two. |
| 2358 host_content_settings_map->GetSettingsForOneType( |
| 2359 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
| 2360 EXPECT_EQ(2u, host_settings.size()); |
| 2361 |
| 2362 // Clear the http one, which we should be able to do w/ the origin only, as |
| 2363 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is |
| 2364 // REQUESTING_ORIGIN_ONLY_SCOPE. |
| 2365 ContentSettingsPattern http_pattern = |
| 2366 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); |
| 2367 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( |
| 2368 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
| 2369 base::Bind(&MatchPrimaryPattern, http_pattern)); |
| 2370 // Verify we only have one, and it's url1. |
| 2371 host_content_settings_map->GetSettingsForOneType( |
| 2372 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
| 2373 EXPECT_EQ(1u, host_settings.size()); |
| 2374 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), |
| 2375 host_settings[0].primary_pattern); |
| 2376 } |
| OLD | NEW |