Commit 6567c2d7 authored by Raymes Khoury's avatar Raymes Khoury Committed by Commit Bot

Change SearchPermissionService to work correctly in the presence of enterpise policy

This makes SearchPermissionService preserve the correct content setting
values when content setting enterprise policies are in effect. It is
changed to use GetUserModifiableContentSetting which will always return
the user defined content setting, even when an enterprise policy is in
place.

Bug: 780344
Change-Id: I8b9362ddd6580c602270f7b5d8d9dafbb467a896
Reviewed-on: https://chromium-review.googlesource.com/807865Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521970}
parent 47b0b6ca
......@@ -451,10 +451,8 @@ void SearchPermissionsService::SetDSEPref(
ContentSetting SearchPermissionsService::GetContentSetting(
const GURL& origin,
ContentSettingsType type) {
// TODO(raymes): For this to be correct, it should only query the user-defined
// settings in HostContentSettingsMap. Add a function to do this.
return host_content_settings_map_->GetContentSetting(origin, origin, type,
std::string());
return host_content_settings_map_->GetUserModifiableContentSetting(
origin, origin, type, std::string());
}
void SearchPermissionsService::SetContentSetting(const GURL& origin,
......
......@@ -370,6 +370,64 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
}
TEST_F(SearchPermissionsServiceTest, DSEChangesWithEnterprisePolicy) {
test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Set a policy value for the geolocation setting.
sync_preferences::TestingPrefServiceSyncable* prefs =
profile()->GetTestingPrefService();
prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting,
base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Change DSE.
test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
// The enterprise policy should still be in effect.
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// When the enterprise policy goes away, the setting should revert to ALLOW
// for the current DSE and ASK for the previous one.
prefs->RemoveManagedPref(prefs::kManagedDefaultGeolocationSetting);
EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Simulate the user setting google.com to BLOCK.
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_BLOCK);
// Put an ALLOW enterprise policy in place.
prefs->SetManagedPref(prefs::kManagedDefaultGeolocationSetting,
base::MakeUnique<base::Value>(CONTENT_SETTING_ALLOW));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Now change the DSE back to google.com. The enterprise setting should still
// be in effect so it should be ALLOW.
test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
// Remove the enterprise policy. google.com should go back to blocked.
// google.com.au should be ASK.
prefs->RemoveManagedPref(prefs::kManagedDefaultGeolocationSetting);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
}
TEST_F(SearchPermissionsServiceTest, DSEChangesAndDisclosure) {
test_delegate()->ChangeDSEOrigin(kGoogleURL);
SearchGeolocationDisclosureTabHelper::FakeShowingDisclosureForTests(
......
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