Commit 8b6f374d authored by Raymes Khoury's avatar Raymes Khoury Committed by Commit Bot

Add more tests to SearchPermissionsService

This adds more tests to SearchPermissionsService to test:
-The cases where the kGrantNotificationsToDSE flag is disabled
-The case where the kGrantNotificationsToDSE is enabled and then changes
back to disabled.

This also fixes a bug where resetting DSE notifications permissions
would happen even when the feature flag was disabled.

Bug: 799534
Change-Id: I907f03308936a1a502fa9fba04aae80325c3a3ee
Reviewed-on: https://chromium-review.googlesource.com/813140Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522362}
parent 06670b5b
......@@ -192,7 +192,8 @@ void SearchPermissionsService::ResetDSEPermission(ContentSettingsType type) {
void SearchPermissionsService::ResetDSEPermissions() {
ResetDSEPermission(CONTENT_SETTINGS_TYPE_GEOLOCATION);
ResetDSEPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
if (base::FeatureList::IsEnabled(features::kGrantNotificationsToDSE))
ResetDSEPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
}
void SearchPermissionsService::Shutdown() {
......
......@@ -613,3 +613,100 @@ TEST_F(SearchPermissionsServiceTest, ResetDSEPermissions) {
EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
}
TEST_F(SearchPermissionsServiceTest, GrantNotificationsToDSEFeatureDisabled) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(features::kGrantNotificationsToDSE);
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_DEFAULT);
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_DEFAULT);
ReinitializeService(true /* clear_pref */);
test_delegate()->ChangeDSEOrigin(kGoogleURL);
// Only geolocation should be granted to the DSE.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// Only geolocation should be granted when changing DSEs.
test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_TRUE(GetService()->IsPermissionControlledByDSE(
CONTENT_SETTINGS_TYPE_GEOLOCATION, ToOrigin(kGoogleAusURL)));
EXPECT_FALSE(GetService()->IsPermissionControlledByDSE(
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, ToOrigin(kGoogleAusURL)));
// Resetting the DSE setting should only impact geolocation.
SetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_BLOCK);
SetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_BLOCK);
GetService()->ResetDSEPermissions();
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
}
TEST_F(SearchPermissionsServiceTest,
GrantNotificationsToDSEFeatureEnabledThenDisabled) {
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// When the feature flag was enabled previously and is then disabled, the
// notifications permission should be restored to its previous value.
{
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(
features::kGrantNotificationsToDSE);
ReinitializeService(false /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
}
// The setting should be restored correctly even if it was non-ask.
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_BLOCK);
ReinitializeService(true /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
{
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndDisableFeature(
features::kGrantNotificationsToDSE);
ReinitializeService(false /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment