OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/subresource_filter/subresource_filter_content_settings_
observer_factory.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/test/histogram_tester.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kActionsHistogram[] = "SubresourceFilter.Actions"; |
| 19 |
| 20 class SubresourceFilterContentSettingsObserverFactoryTest |
| 21 : public testing::Test { |
| 22 public: |
| 23 SubresourceFilterContentSettingsObserverFactoryTest() {} |
| 24 |
| 25 void SetUp() override { |
| 26 SubresourceFilterContentSettingsObserverFactory::EnsureForProfile( |
| 27 &testing_profile_); |
| 28 histogram_tester().ExpectTotalCount(kActionsHistogram, 0); |
| 29 } |
| 30 |
| 31 HostContentSettingsMap* GetSettingsMap() { |
| 32 return HostContentSettingsMapFactory::GetForProfile(&testing_profile_); |
| 33 } |
| 34 |
| 35 const base::HistogramTester& histogram_tester() { return histogram_tester_; } |
| 36 |
| 37 private: |
| 38 content::TestBrowserThreadBundle thread_bundle_; |
| 39 TestingProfile testing_profile_; |
| 40 base::HistogramTester histogram_tester_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterContentSettingsObserverFactoryTest); |
| 43 }; |
| 44 |
| 45 TEST_F(SubresourceFilterContentSettingsObserverFactoryTest, IrrelevantSetting) { |
| 46 GetSettingsMap()->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_POPUPS, |
| 47 CONTENT_SETTING_ALLOW); |
| 48 histogram_tester().ExpectTotalCount(kActionsHistogram, 0); |
| 49 } |
| 50 |
| 51 TEST_F(SubresourceFilterContentSettingsObserverFactoryTest, DefaultSetting) { |
| 52 GetSettingsMap()->SetDefaultContentSetting( |
| 53 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, CONTENT_SETTING_ALLOW); |
| 54 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 55 kActionContentSettingsAllowedGlobal, 1); |
| 56 |
| 57 GetSettingsMap()->SetDefaultContentSetting( |
| 58 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, CONTENT_SETTING_BLOCK); |
| 59 histogram_tester().ExpectTotalCount(kActionsHistogram, 2); |
| 60 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 61 kActionContentSettingsBlockedGlobal, 1); |
| 62 } |
| 63 |
| 64 TEST_F(SubresourceFilterContentSettingsObserverFactoryTest, UrlSetting) { |
| 65 GURL url("https://www.example.test/"); |
| 66 |
| 67 GetSettingsMap()->SetContentSettingDefaultScope( |
| 68 url, url, CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, std::string(), |
| 69 CONTENT_SETTING_BLOCK); |
| 70 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 71 kActionContentSettingsBlocked, 1); |
| 72 |
| 73 GetSettingsMap()->SetContentSettingDefaultScope( |
| 74 url, url, CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, std::string(), |
| 75 CONTENT_SETTING_ALLOW); |
| 76 histogram_tester().ExpectTotalCount(kActionsHistogram, 2); |
| 77 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 78 kActionContentSettingsAllowed, 1); |
| 79 } |
| 80 |
| 81 TEST_F(SubresourceFilterContentSettingsObserverFactoryTest, WildcardUpdate) { |
| 82 ContentSettingsPattern primary_pattern = |
| 83 ContentSettingsPattern::FromString("[*.]example.test"); |
| 84 ContentSettingsPattern secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 85 |
| 86 GetSettingsMap()->SetContentSettingCustomScope( |
| 87 primary_pattern, secondary_pattern, |
| 88 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, std::string(), |
| 89 CONTENT_SETTING_BLOCK); |
| 90 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 91 kActionContentSettingsWildcardUpdate, 1); |
| 92 |
| 93 GetSettingsMap()->SetContentSettingCustomScope( |
| 94 primary_pattern, secondary_pattern, |
| 95 CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, std::string(), |
| 96 CONTENT_SETTING_ALLOW); |
| 97 histogram_tester().ExpectTotalCount(kActionsHistogram, 2); |
| 98 histogram_tester().ExpectBucketCount(kActionsHistogram, |
| 99 kActionContentSettingsWildcardUpdate, 2); |
| 100 } |
| 101 |
| 102 } // namespace |
OLD | NEW |