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