OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/histogram_tester.h" |
| 6 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 7 #include "chrome/browser/permissions/permission_uma_util.h" |
| 8 #include "chrome/browser/permissions/permission_util.h" |
| 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 class PermissionUtilTest : public testing::Test { |
| 15 content::TestBrowserThreadBundle thread_bundle_; |
| 16 }; |
| 17 |
| 18 TEST_F(PermissionUtilTest, SetContentSettingRecordRevocation) { |
| 19 TestingProfile profile; |
| 20 // TODO(tsergeant): Add more comprehensive tests of PermissionUmaUtil. |
| 21 base::HistogramTester histograms; |
| 22 HostContentSettingsMap* map = |
| 23 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 24 GURL host("https://example.com"); |
| 25 ContentSettingsType type = CONTENT_SETTINGS_TYPE_GEOLOCATION; |
| 26 |
| 27 // Allow->Block triggers a revocation. |
| 28 map->SetContentSettingDefaultScope(host, host, type, std::string(), |
| 29 CONTENT_SETTING_ALLOW); |
| 30 EXPECT_TRUE(PermissionUtil::SetContentSettingAndRecordRevocation( |
| 31 &profile, host, host, type, std::string(), CONTENT_SETTING_BLOCK)); |
| 32 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 33 PermissionAction::REVOKED, 1); |
| 34 |
| 35 // Block->Allow does not trigger a revocation. |
| 36 EXPECT_FALSE(PermissionUtil::SetContentSettingAndRecordRevocation( |
| 37 &profile, host, host, type, std::string(), CONTENT_SETTING_ALLOW)); |
| 38 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 39 PermissionAction::REVOKED, 1); |
| 40 |
| 41 // Allow->Default triggers a revocation when default is 'ask'. |
| 42 map->SetDefaultContentSetting(type, CONTENT_SETTING_ASK); |
| 43 EXPECT_TRUE(PermissionUtil::SetContentSettingAndRecordRevocation( |
| 44 &profile, host, host, type, std::string(), CONTENT_SETTING_DEFAULT)); |
| 45 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 46 PermissionAction::REVOKED, 2); |
| 47 |
| 48 // Allow->Default does not trigger a revocation when default is 'allow'. |
| 49 map->SetDefaultContentSetting(type, CONTENT_SETTING_ALLOW); |
| 50 EXPECT_FALSE(PermissionUtil::SetContentSettingAndRecordRevocation( |
| 51 &profile, host, host, type, std::string(), CONTENT_SETTING_DEFAULT)); |
| 52 histograms.ExpectBucketCount("Permissions.Action.Geolocation", |
| 53 PermissionAction::REVOKED, 2); |
| 54 } |
OLD | NEW |