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, SetContentSettingRecordRevocation) { | 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 ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION; | 25 ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
| 26 PermissionSourceUI source_ui = PermissionSourceUI::SITE_SETTINGS; |
26 | 27 |
27 // Allow->Block triggers a revocation. | 28 // Allow->Block triggers a revocation. |
28 map->SetContentSettingDefaultScope(host, host, type, std::string(), | 29 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
29 CONTENT_SETTING_ALLOW); | 30 CONTENT_SETTING_ALLOW); |
30 PermissionUtil::SetContentSettingAndRecordRevocation( | 31 { |
31 &profile, host, host, type, std::string(), CONTENT_SETTING_BLOCK); | 32 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 33 &profile, host, host, type, source_ui); |
| 34 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 35 CONTENT_SETTING_BLOCK); |
| 36 } |
32 histograms.ExpectBucketCount("Permissions.Action.Geolocation", | 37 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
33 PermissionAction::REVOKED, 1); | 38 PermissionAction::REVOKED, 1); |
34 | 39 |
35 // Block->Allow does not trigger a revocation. | 40 // Block->Allow does not trigger a revocation. |
36 PermissionUtil::SetContentSettingAndRecordRevocation( | 41 { |
37 &profile, host, host, type, std::string(), CONTENT_SETTING_ALLOW); | 42 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 43 &profile, host, host, type, source_ui); |
| 44 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 45 CONTENT_SETTING_ALLOW); |
| 46 } |
38 histograms.ExpectBucketCount("Permissions.Action.Geolocation", | 47 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
39 PermissionAction::REVOKED, 1); | 48 PermissionAction::REVOKED, 1); |
40 | 49 |
41 // Allow->Default triggers a revocation when default is 'ask'. | 50 // Allow->Default triggers a revocation when default is 'ask'. |
42 map->SetDefaultContentSetting(type, CONTENT_SETTING_ASK); | 51 map->SetDefaultContentSetting(type, CONTENT_SETTING_ASK); |
43 PermissionUtil::SetContentSettingAndRecordRevocation( | 52 { |
44 &profile, host, host, type, std::string(), CONTENT_SETTING_DEFAULT); | 53 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 54 &profile, host, host, type, source_ui); |
| 55 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 56 CONTENT_SETTING_DEFAULT); |
| 57 } |
45 histograms.ExpectBucketCount("Permissions.Action.Geolocation", | 58 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
46 PermissionAction::REVOKED, 2); | 59 PermissionAction::REVOKED, 2); |
47 | 60 |
48 // Allow->Default does not trigger a revocation when default is 'allow'. | 61 // Allow->Default does not trigger a revocation when default is 'allow'. |
49 map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW); | 62 map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW); |
50 PermissionUtil::SetContentSettingAndRecordRevocation( | 63 { |
51 &profile, host, host, type, std::string(), CONTENT_SETTING_DEFAULT); | 64 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 65 &profile, host, host, type, source_ui); |
| 66 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 67 CONTENT_SETTING_DEFAULT); |
| 68 } |
52 histograms.ExpectBucketCount("Permissions.Action.Geolocation", | 69 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
53 PermissionAction::REVOKED, 2); | 70 PermissionAction::REVOKED, 2); |
54 } | 71 } |
OLD | NEW |