| 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 <list> | 10 #include <list> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 const base::FilePath::CharType kDomStorageOrigin2[] = | 165 const base::FilePath::CharType kDomStorageOrigin2[] = |
| 166 FILE_PATH_LITERAL("http_host2_1.localstorage"); | 166 FILE_PATH_LITERAL("http_host2_1.localstorage"); |
| 167 | 167 |
| 168 const base::FilePath::CharType kDomStorageOrigin3[] = | 168 const base::FilePath::CharType kDomStorageOrigin3[] = |
| 169 FILE_PATH_LITERAL("http_host3_1.localstorage"); | 169 FILE_PATH_LITERAL("http_host3_1.localstorage"); |
| 170 | 170 |
| 171 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( | 171 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( |
| 172 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); | 172 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); |
| 173 | 173 |
| 174 bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary, | |
| 175 const ContentSettingsPattern& primary_pattern, | |
| 176 const ContentSettingsPattern& secondary_pattern) { | |
| 177 return expected_primary == primary_pattern; | |
| 178 } | |
| 179 | |
| 180 #if defined(OS_CHROMEOS) | 174 #if defined(OS_CHROMEOS) |
| 181 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { | 175 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { |
| 182 base::ThreadTaskRunnerHandle::Get()->PostTask( | 176 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 183 FROM_HERE, | 177 FROM_HERE, |
| 184 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); | 178 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); |
| 185 } | 179 } |
| 186 #endif | 180 #endif |
| 187 | 181 |
| 188 struct StoragePartitionRemovalData { | 182 struct StoragePartitionRemovalData { |
| 189 uint32_t remove_mask = 0; | 183 uint32_t remove_mask = 0; |
| (...skipping 2413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 host_settings[0].primary_pattern) | 2597 host_settings[0].primary_pattern) |
| 2604 << host_settings[0].primary_pattern.ToString(); | 2598 << host_settings[0].primary_pattern.ToString(); |
| 2605 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4), | 2599 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4), |
| 2606 host_settings[1].primary_pattern) | 2600 host_settings[1].primary_pattern) |
| 2607 << host_settings[1].primary_pattern.ToString(); | 2601 << host_settings[1].primary_pattern.ToString(); |
| 2608 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3), | 2602 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3), |
| 2609 host_settings[2].primary_pattern) | 2603 host_settings[2].primary_pattern) |
| 2610 << host_settings[2].primary_pattern.ToString(); | 2604 << host_settings[2].primary_pattern.ToString(); |
| 2611 } | 2605 } |
| 2612 | 2606 |
| 2613 TEST_F(BrowsingDataRemoverTest, ClearWithPredicate) { | |
| 2614 HostContentSettingsMap* host_content_settings_map = | |
| 2615 HostContentSettingsMapFactory::GetForProfile(GetProfile()); | |
| 2616 ContentSettingsForOneType host_settings; | |
| 2617 | |
| 2618 // Patterns with wildcards. | |
| 2619 ContentSettingsPattern pattern = | |
| 2620 ContentSettingsPattern::FromString("[*.]example.org"); | |
| 2621 ContentSettingsPattern pattern2 = | |
| 2622 ContentSettingsPattern::FromString("[*.]example.net"); | |
| 2623 | |
| 2624 // Patterns without wildcards. | |
| 2625 GURL url1("https://www.google.com/"); | |
| 2626 GURL url2("https://www.google.com/maps"); | |
| 2627 GURL url3("http://www.google.com/maps"); | |
| 2628 GURL url3_origin_only("http://www.google.com/"); | |
| 2629 | |
| 2630 host_content_settings_map->SetContentSettingCustomScope( | |
| 2631 pattern2, ContentSettingsPattern::Wildcard(), | |
| 2632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 2633 host_content_settings_map->SetContentSettingCustomScope( | |
| 2634 pattern, ContentSettingsPattern::Wildcard(), | |
| 2635 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 2636 host_content_settings_map->SetWebsiteSettingCustomScope( | |
| 2637 pattern2, ContentSettingsPattern::Wildcard(), | |
| 2638 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | |
| 2639 base::WrapUnique(new base::DictionaryValue())); | |
| 2640 | |
| 2641 // First, test that we clear only COOKIES (not APP_BANNER), and pattern2. | |
| 2642 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( | |
| 2643 host_content_settings_map, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 2644 base::Bind(&MatchPrimaryPattern, pattern2)); | |
| 2645 host_content_settings_map->GetSettingsForOneType( | |
| 2646 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); | |
| 2647 // |host_settings| contains default & block. | |
| 2648 EXPECT_EQ(2U, host_settings.size()); | |
| 2649 EXPECT_EQ(pattern, host_settings[0].primary_pattern); | |
| 2650 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); | |
| 2651 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); | |
| 2652 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); | |
| 2653 | |
| 2654 host_content_settings_map->GetSettingsForOneType( | |
| 2655 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), &host_settings); | |
| 2656 // |host_settings| contains block. | |
| 2657 EXPECT_EQ(1U, host_settings.size()); | |
| 2658 EXPECT_EQ(pattern2, host_settings[0].primary_pattern); | |
| 2659 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); | |
| 2660 | |
| 2661 // Next, test that we do correct pattern matching w/ an origin policy item. | |
| 2662 // We verify that we have no settings stored. | |
| 2663 host_content_settings_map->GetSettingsForOneType( | |
| 2664 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 2665 EXPECT_EQ(0u, host_settings.size()); | |
| 2666 // Add settings. | |
| 2667 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 2668 url1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 2669 base::WrapUnique(new base::DictionaryValue())); | |
| 2670 // This setting should override the one above, as it's the same origin. | |
| 2671 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 2672 url2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 2673 base::WrapUnique(new base::DictionaryValue())); | |
| 2674 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 2675 url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 2676 base::WrapUnique(new base::DictionaryValue())); | |
| 2677 // Verify we only have two. | |
| 2678 host_content_settings_map->GetSettingsForOneType( | |
| 2679 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 2680 EXPECT_EQ(2u, host_settings.size()); | |
| 2681 | |
| 2682 // Clear the http one, which we should be able to do w/ the origin only, as | |
| 2683 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is | |
| 2684 // REQUESTING_ORIGIN_ONLY_SCOPE. | |
| 2685 ContentSettingsPattern http_pattern = | |
| 2686 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); | |
| 2687 BrowsingDataRemover::ClearSettingsForOneTypeWithPredicate( | |
| 2688 host_content_settings_map, CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | |
| 2689 base::Bind(&MatchPrimaryPattern, http_pattern)); | |
| 2690 // Verify we only have one, and it's url1. | |
| 2691 host_content_settings_map->GetSettingsForOneType( | |
| 2692 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 2693 EXPECT_EQ(1u, host_settings.size()); | |
| 2694 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), | |
| 2695 host_settings[0].primary_pattern); | |
| 2696 } | |
| 2697 | |
| 2698 // Test that removing cookies clears HTTP auth data. | 2607 // Test that removing cookies clears HTTP auth data. |
| 2699 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemoveCookies) { | 2608 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemoveCookies) { |
| 2700 net::HttpNetworkSession* http_session = GetProfile() | 2609 net::HttpNetworkSession* http_session = GetProfile() |
| 2701 ->GetRequestContext() | 2610 ->GetRequestContext() |
| 2702 ->GetURLRequestContext() | 2611 ->GetURLRequestContext() |
| 2703 ->http_transaction_factory() | 2612 ->http_transaction_factory() |
| 2704 ->GetSession(); | 2613 ->GetSession(); |
| 2705 DCHECK(http_session); | 2614 DCHECK(http_session); |
| 2706 | 2615 |
| 2707 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); | 2616 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3068 EXPECT_TRUE(remover->is_removing()); | 2977 EXPECT_TRUE(remover->is_removing()); |
| 3069 | 2978 |
| 3070 // Add one more deletion and wait for it. | 2979 // Add one more deletion and wait for it. |
| 3071 BlockUntilBrowsingDataRemoved( | 2980 BlockUntilBrowsingDataRemoved( |
| 3072 browsing_data::ALL_TIME, | 2981 browsing_data::ALL_TIME, |
| 3073 BrowsingDataRemover::REMOVE_COOKIES, | 2982 BrowsingDataRemover::REMOVE_COOKIES, |
| 3074 BrowsingDataHelper::UNPROTECTED_WEB); | 2983 BrowsingDataHelper::UNPROTECTED_WEB); |
| 3075 | 2984 |
| 3076 EXPECT_FALSE(remover->is_removing()); | 2985 EXPECT_FALSE(remover->is_removing()); |
| 3077 } | 2986 } |
| OLD | NEW |