| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/test/histogram_tester.h" | 5 #include "base/test/histogram_tester.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 7 #include "chrome/browser/permissions/permission_uma_util.h" | 7 #include "chrome/browser/permissions/permission_uma_util.h" |
| 8 #include "chrome/browser/permissions/permission_util.h" | 8 #include "chrome/browser/permissions/permission_util.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "components/content_settings/core/browser/host_content_settings_map.h" | 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 class PermissionUtilTest : public testing::Test { | 14 class PermissionUtilTest : public testing::Test { |
| 15 content::TestBrowserThreadBundle thread_bundle_; | 15 content::TestBrowserThreadBundle thread_bundle_; |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 TEST_F(PermissionUtilTest, ScopedRevocationReporter) { | 18 TEST_F(PermissionUtilTest, ScopedRevocationReporter) { |
| 19 TestingProfile profile; | 19 TestingProfile profile; |
| 20 // TODO(tsergeant): Add more comprehensive tests of PermissionUmaUtil. | 20 // TODO(tsergeant): Add more comprehensive tests of PermissionUmaUtil. |
| 21 base::HistogramTester histograms; | 21 base::HistogramTester histograms; |
| 22 HostContentSettingsMap* map = | 22 HostContentSettingsMap* map = |
| 23 HostContentSettingsMapFactory::GetForProfile(&profile); | 23 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 24 GURL host("https://example.com"); | 24 GURL host("https://example.com"); |
| 25 ContentSettingsPattern host_pattern = |
| 26 ContentSettingsPattern::FromURLNoWildcard(host); |
| 27 ContentSettingsPattern host_containing_wildcards_pattern = |
| 28 ContentSettingsPattern::FromString("https://[*.]example.com/"); |
| 25 ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 29 ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
| 26 PermissionSourceUI source_ui = PermissionSourceUI::SITE_SETTINGS; | 30 PermissionSourceUI source_ui = PermissionSourceUI::SITE_SETTINGS; |
| 27 | 31 |
| 28 // Allow->Block triggers a revocation. | 32 // Allow->Block triggers a revocation. |
| 29 map->SetContentSettingDefaultScope(host, host, type, std::string(), | 33 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 30 CONTENT_SETTING_ALLOW); | 34 CONTENT_SETTING_ALLOW); |
| 31 { | 35 { |
| 32 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 36 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 33 &profile, host, host, type, source_ui); | 37 &profile, host, host, type, source_ui); |
| 34 map->SetContentSettingDefaultScope(host, host, type, std::string(), | 38 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 61 // Allow->Default does not trigger a revocation when default is 'allow'. | 65 // Allow->Default does not trigger a revocation when default is 'allow'. |
| 62 map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW); | 66 map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW); |
| 63 { | 67 { |
| 64 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 68 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 65 &profile, host, host, type, source_ui); | 69 &profile, host, host, type, source_ui); |
| 66 map->SetContentSettingDefaultScope(host, host, type, std::string(), | 70 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 67 CONTENT_SETTING_DEFAULT); | 71 CONTENT_SETTING_DEFAULT); |
| 68 } | 72 } |
| 69 histograms.ExpectBucketCount("Permissions.Action.Geolocation", | 73 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 70 PermissionAction::REVOKED, 2); | 74 PermissionAction::REVOKED, 2); |
| 75 |
| 76 // Allow->Block with url pattern string triggers a revocation. |
| 77 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 78 CONTENT_SETTING_ALLOW); |
| 79 { |
| 80 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 81 &profile, host_pattern, host_pattern, type, source_ui); |
| 82 map->SetContentSettingCustomScope(host_pattern, host_pattern, type, |
| 83 std::string(), CONTENT_SETTING_BLOCK); |
| 84 } |
| 85 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 86 PermissionAction::REVOKED, 3); |
| 87 |
| 88 // Allow->Block with non url pattern string does not trigger a revocation. |
| 89 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 90 CONTENT_SETTING_ALLOW); |
| 91 { |
| 92 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 93 &profile, host_containing_wildcards_pattern, host_pattern, type, |
| 94 source_ui); |
| 95 map->SetContentSettingCustomScope(host_containing_wildcards_pattern, |
| 96 host_pattern, type, std::string(), |
| 97 CONTENT_SETTING_BLOCK); |
| 98 } |
| 99 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 100 PermissionAction::REVOKED, 3); |
| 71 } | 101 } |
| OLD | NEW |