Commit 91377e47 authored by Raymes Khoury's avatar Raymes Khoury Committed by Commit Bot

Handle DSE permission changes when the default search engine is disabled

The default search engine can be disabled by enterprise. In this case,
we restore the permission settings for the old DSE. We also delete the
underlying pref that tracks settings, so that if the DSE is re-enabled,
the DSE permissions will be re-initialized for the new DSE as if being
initialized for the first time.

Bug: 780344
Change-Id: I6df13d6b085dbe8164fe003c3406245e5b8efb2f
Reviewed-on: https://chromium-review.googlesource.com/765566
Commit-Queue: Raymes Khoury <raymes@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521278}
parent 0ea77a78
...@@ -179,6 +179,10 @@ SearchPermissionsService::~SearchPermissionsService() {} ...@@ -179,6 +179,10 @@ SearchPermissionsService::~SearchPermissionsService() {}
void SearchPermissionsService::OnDSEChanged() { void SearchPermissionsService::OnDSEChanged() {
InitializeSettingsIfNeeded(); InitializeSettingsIfNeeded();
// If we didn't initialize properly because there is no DSE don't do anything.
if (!pref_service_->HasPrefPath(prefs::kDSEPermissionsSettings))
return;
PrefValue pref = GetDSEPref(); PrefValue pref = GetDSEPref();
base::string16 new_dse_name = delegate_->GetDSEName(); base::string16 new_dse_name = delegate_->GetDSEName();
...@@ -187,24 +191,19 @@ void SearchPermissionsService::OnDSEChanged() { ...@@ -187,24 +191,19 @@ void SearchPermissionsService::OnDSEChanged() {
GURL old_dse_origin(pref.dse_origin); GURL old_dse_origin(pref.dse_origin);
GURL new_dse_origin = delegate_->GetDSEOrigin().GetURL(); GURL new_dse_origin = delegate_->GetDSEOrigin().GetURL();
// This can happen in tests. // Don't do anything if the DSE origin hasn't changed.
// TODO(raymes): It turns out this can also happen if the DSE is disabled by
// policy. This is another case we need to correctly handle.
if (!new_dse_origin.is_valid())
return;
// Don't do anything if the DSE name/origin hasn't changed.
if (old_dse_origin == new_dse_origin) if (old_dse_origin == new_dse_origin)
return; return;
ContentSetting geolocation_setting_to_restore = UpdatePermission( ContentSetting geolocation_setting_to_restore =
CONTENT_SETTINGS_TYPE_GEOLOCATION, old_dse_origin, new_dse_origin, UpdatePermissionAndReturnPrevious(
pref.geolocation_setting_to_restore, old_dse_name != new_dse_name); CONTENT_SETTINGS_TYPE_GEOLOCATION, old_dse_origin, new_dse_origin,
pref.geolocation_setting_to_restore, old_dse_name != new_dse_name);
ContentSetting notifications_setting_to_restore = ContentSetting notifications_setting_to_restore =
pref.notifications_setting_to_restore; pref.notifications_setting_to_restore;
// Only update the notifications part of the pref if the feature is enabled. // Only update the notifications part of the pref if the feature is enabled.
if (base::FeatureList::IsEnabled(features::kGrantNotificationsToDSE)) { if (base::FeatureList::IsEnabled(features::kGrantNotificationsToDSE)) {
notifications_setting_to_restore = UpdatePermission( notifications_setting_to_restore = UpdatePermissionAndReturnPrevious(
CONTENT_SETTINGS_TYPE_NOTIFICATIONS, old_dse_origin, new_dse_origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, old_dse_origin, new_dse_origin,
pref.notifications_setting_to_restore, old_dse_name != new_dse_name); pref.notifications_setting_to_restore, old_dse_name != new_dse_name);
} }
...@@ -217,19 +216,13 @@ void SearchPermissionsService::OnDSEChanged() { ...@@ -217,19 +216,13 @@ void SearchPermissionsService::OnDSEChanged() {
SetDSEPref(pref); SetDSEPref(pref);
} }
ContentSetting SearchPermissionsService::UpdatePermission( ContentSetting SearchPermissionsService::RestoreOldSettingAndReturnPrevious(
const GURL& dse_origin,
ContentSettingsType type, ContentSettingsType type,
const GURL& old_dse_origin, ContentSetting setting_to_restore) {
const GURL& new_dse_origin,
ContentSetting old_dse_setting_to_restore,
bool dse_name_changed) {
// Remove any embargo on the URL.
PermissionDecisionAutoBlocker::GetForProfile(profile_)->RemoveEmbargoByUrl(
new_dse_origin, type);
// Read the current value of the old DSE. This is the DSE setting that we want // Read the current value of the old DSE. This is the DSE setting that we want
// to try to apply to the new DSE origin. // to try to apply to the new DSE origin.
ContentSetting dse_setting = GetContentSetting(old_dse_origin, type); ContentSetting dse_setting = GetContentSetting(dse_origin, type);
// The user's setting should never be ASK while an origin is the DSE. There // The user's setting should never be ASK while an origin is the DSE. There
// should be no way for the user to reset the DSE content setting to ASK. // should be no way for the user to reset the DSE content setting to ASK.
...@@ -243,9 +236,25 @@ ContentSetting SearchPermissionsService::UpdatePermission( ...@@ -243,9 +236,25 @@ ContentSetting SearchPermissionsService::UpdatePermission(
// Restore the setting for the old origin. If the user has changed the setting // Restore the setting for the old origin. If the user has changed the setting
// since the origin became the DSE, we reset the setting so the user will be // since the origin became the DSE, we reset the setting so the user will be
// prompted. // prompted.
if (old_dse_setting_to_restore != dse_setting) if (setting_to_restore != dse_setting)
old_dse_setting_to_restore = CONTENT_SETTING_ASK; setting_to_restore = CONTENT_SETTING_ASK;
SetContentSetting(old_dse_origin, type, old_dse_setting_to_restore); SetContentSetting(dse_origin, type, setting_to_restore);
return dse_setting;
}
ContentSetting SearchPermissionsService::UpdatePermissionAndReturnPrevious(
ContentSettingsType type,
const GURL& old_dse_origin,
const GURL& new_dse_origin,
ContentSetting old_dse_setting_to_restore,
bool dse_name_changed) {
// Remove any embargo on the URL.
PermissionDecisionAutoBlocker::GetForProfile(profile_)->RemoveEmbargoByUrl(
new_dse_origin, type);
ContentSetting dse_setting = RestoreOldSettingAndReturnPrevious(
old_dse_origin, type, old_dse_setting_to_restore);
ContentSetting new_dse_setting_to_restore = ContentSetting new_dse_setting_to_restore =
GetContentSetting(new_dse_origin, type); GetContentSetting(new_dse_origin, type);
...@@ -276,10 +285,28 @@ ContentSetting SearchPermissionsService::UpdatePermission( ...@@ -276,10 +285,28 @@ ContentSetting SearchPermissionsService::UpdatePermission(
void SearchPermissionsService::InitializeSettingsIfNeeded() { void SearchPermissionsService::InitializeSettingsIfNeeded() {
GURL dse_origin = delegate_->GetDSEOrigin().GetURL(); GURL dse_origin = delegate_->GetDSEOrigin().GetURL();
// This can happen in tests or if the DSE is disabled by policy. We defer // This can happen in tests or if the DSE is disabled by policy. If that's
// initialization until later. // the case, we restore the old settings and erase the pref. This means that
if (!dse_origin.is_valid()) // things will be re-initialized to defaults when the DSE is no longer under
// enterprise policy.
if (!dse_origin.is_valid()) {
if (pref_service_->HasPrefPath(prefs::kDSEPermissionsSettings)) {
PrefValue pref = GetDSEPref();
GURL old_dse_origin(pref.dse_origin);
RestoreOldSettingAndReturnPrevious(old_dse_origin,
CONTENT_SETTINGS_TYPE_GEOLOCATION,
pref.geolocation_setting_to_restore);
if (pref.notifications_setting_to_restore != CONTENT_SETTING_DEFAULT) {
RestoreOldSettingAndReturnPrevious(
old_dse_origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
pref.notifications_setting_to_restore);
}
pref_service_->ClearPref(prefs::kDSEPermissionsSettings);
}
// Defer initialization until a search engine becomes the DSE.
return; return;
}
// Initialize the pref for geolocation if it hasn't been initialized yet. // Initialize the pref for geolocation if it hasn't been initialized yet.
if (!pref_service_->HasPrefPath(prefs::kDSEPermissionsSettings)) { if (!pref_service_->HasPrefPath(prefs::kDSEPermissionsSettings)) {
...@@ -323,7 +350,7 @@ void SearchPermissionsService::InitializeSettingsIfNeeded() { ...@@ -323,7 +350,7 @@ void SearchPermissionsService::InitializeSettingsIfNeeded() {
PrefValue pref; PrefValue pref;
pref.dse_name = delegate_->GetDSEName(); pref.dse_name = delegate_->GetDSEName();
pref.dse_origin = delegate_->GetDSEOrigin().GetURL().spec(); pref.dse_origin = dse_origin.spec();
pref.geolocation_setting_to_restore = geolocation_setting_to_restore; pref.geolocation_setting_to_restore = geolocation_setting_to_restore;
pref.notifications_setting_to_restore = CONTENT_SETTING_DEFAULT; pref.notifications_setting_to_restore = CONTENT_SETTING_DEFAULT;
SetDSEPref(pref); SetDSEPref(pref);
...@@ -353,8 +380,9 @@ void SearchPermissionsService::InitializeSettingsIfNeeded() { ...@@ -353,8 +380,9 @@ void SearchPermissionsService::InitializeSettingsIfNeeded() {
pref.notifications_setting_to_restore != CONTENT_SETTING_DEFAULT) { pref.notifications_setting_to_restore != CONTENT_SETTING_DEFAULT) {
// Handle the case where the feature has been disabled. Restore the pref // Handle the case where the feature has been disabled. Restore the pref
// value and reset the setting to restore to DEFAULT. // value and reset the setting to restore to DEFAULT.
SetContentSetting(dse_origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, RestoreOldSettingAndReturnPrevious(GURL(pref.dse_origin),
pref.notifications_setting_to_restore); CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
pref.notifications_setting_to_restore);
pref.notifications_setting_to_restore = CONTENT_SETTING_DEFAULT; pref.notifications_setting_to_restore = CONTENT_SETTING_DEFAULT;
SetDSEPref(pref); SetDSEPref(pref);
} }
......
...@@ -106,11 +106,21 @@ class SearchPermissionsService : public KeyedService { ...@@ -106,11 +106,21 @@ class SearchPermissionsService : public KeyedService {
// geolocation disclosure so that it will be shown again. // geolocation disclosure so that it will be shown again.
void OnDSEChanged(); void OnDSEChanged();
ContentSetting UpdatePermission(ContentSettingsType type, // Restore the setting for an origin before it became the DSE. Returns the
const GURL& old_dse_origin, // setting that the origin was set to before restoring the old value.
const GURL& new_dse_origin, ContentSetting RestoreOldSettingAndReturnPrevious(
ContentSetting old_setting, const GURL& dse_origin,
bool dse_name_changed); ContentSettingsType type,
ContentSetting setting_to_restore);
// Helper function for OnDSEChanged which transitions the DSE setting for a
// specific permission. It returns the content setting to be restored later
// for |new_dse_origin|.
ContentSetting UpdatePermissionAndReturnPrevious(ContentSettingsType type,
const GURL& old_dse_origin,
const GURL& new_dse_origin,
ContentSetting old_setting,
bool dse_name_changed);
// Initialize the DSE permission settings if they haven't already been // Initialize the DSE permission settings if they haven't already been
// initialized. Also, if they haven't been initialized, reset whether the DSE // initialized. Also, if they haven't been initialized, reset whether the DSE
......
...@@ -58,11 +58,15 @@ class TestSearchEngineDelegate ...@@ -58,11 +58,15 @@ class TestSearchEngineDelegate
dse_changed_callback_ = callback; dse_changed_callback_ = callback;
} }
void SetDSEOrigin(const std::string& dse_origin) { void ChangeDSEOrigin(const std::string& dse_origin) {
dse_origin_ = url::Origin::Create(GURL(dse_origin)); set_dse_origin(dse_origin);
dse_changed_callback_.Run(); dse_changed_callback_.Run();
} }
void set_dse_origin(const std::string& dse_origin) {
dse_origin_ = url::Origin::Create(GURL(dse_origin));
}
private: private:
url::Origin dse_origin_; url::Origin dse_origin_;
base::Closure dse_changed_callback_; base::Closure dse_changed_callback_;
...@@ -176,34 +180,34 @@ TEST_F(SearchPermissionsServiceTest, Initialization) { ...@@ -176,34 +180,34 @@ TEST_F(SearchPermissionsServiceTest, Initialization) {
for (ContentSettingsType type : {CONTENT_SETTINGS_TYPE_GEOLOCATION, for (ContentSettingsType type : {CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTINGS_TYPE_NOTIFICATIONS}) { CONTENT_SETTINGS_TYPE_NOTIFICATIONS}) {
// DSE setting initialized to true if the content setting is ALLOW. // DSE setting initialized to true if the content setting is ALLOW.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
SetContentSetting(kGoogleURL, type, CONTENT_SETTING_ALLOW); SetContentSetting(kGoogleURL, type, CONTENT_SETTING_ALLOW);
ReinitializeService(true /* clear_pref */); ReinitializeService(true /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type));
// Check that the correct value is restored when changing the DSE. // Check that the correct value is restored when changing the DSE.
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type));
// DSE setting initialized to true if the content setting is ASK. // DSE setting initialized to true if the content setting is ASK.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
SetContentSetting(kGoogleURL, type, CONTENT_SETTING_DEFAULT); SetContentSetting(kGoogleURL, type, CONTENT_SETTING_DEFAULT);
EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type));
ReinitializeService(true /* clear_pref */); ReinitializeService(true /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ALLOW, GetContentSetting(kGoogleURL, type));
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type));
// DSE setting initialized to false if the content setting is BLOCK. // DSE setting initialized to false if the content setting is BLOCK.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
SetContentSetting(kGoogleURL, type, CONTENT_SETTING_BLOCK); SetContentSetting(kGoogleURL, type, CONTENT_SETTING_BLOCK);
ReinitializeService(true /* clear_pref */); ReinitializeService(true /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(kGoogleURL, type));
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_BLOCK, GetContentSetting(kGoogleURL, type));
// Nothing happens if the pref is already set when the service is // Nothing happens if the pref is already set when the service is
// initialized. // initialized.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
SetContentSetting(kGoogleURL, type, CONTENT_SETTING_DEFAULT); SetContentSetting(kGoogleURL, type, CONTENT_SETTING_DEFAULT);
ReinitializeService(false /* clear_pref */); ReinitializeService(false /* clear_pref */);
EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type)); EXPECT_EQ(CONTENT_SETTING_ASK, GetContentSetting(kGoogleURL, type));
...@@ -233,7 +237,7 @@ TEST_F(SearchPermissionsServiceTest, OffTheRecord) { ...@@ -233,7 +237,7 @@ TEST_F(SearchPermissionsServiceTest, OffTheRecord) {
TEST_F(SearchPermissionsServiceTest, Migration) { TEST_F(SearchPermissionsServiceTest, Migration) {
// When location was previously allowed for the DSE, it should be carried // When location was previously allowed for the DSE, it should be carried
// over. // over.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION, SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION,
...@@ -260,7 +264,7 @@ TEST_F(SearchPermissionsServiceTest, Migration) { ...@@ -260,7 +264,7 @@ TEST_F(SearchPermissionsServiceTest, Migration) {
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// Changing DSE should cause the setting to go back to ASK for Google. // Changing DSE should cause the setting to go back to ASK for Google.
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_EQ(CONTENT_SETTING_ASK, EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
...@@ -281,7 +285,7 @@ TEST_F(SearchPermissionsServiceTest, Migration) { ...@@ -281,7 +285,7 @@ TEST_F(SearchPermissionsServiceTest, Migration) {
TEST_F(SearchPermissionsServiceTest, ArePermissionsControlledByDSE) { TEST_F(SearchPermissionsServiceTest, ArePermissionsControlledByDSE) {
// True for origin that matches the CCTLD and meets all requirements. // True for origin that matches the CCTLD and meets all requirements.
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_TRUE( EXPECT_TRUE(
GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleURL))); GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleURL)));
...@@ -290,18 +294,18 @@ TEST_F(SearchPermissionsServiceTest, ArePermissionsControlledByDSE) { ...@@ -290,18 +294,18 @@ TEST_F(SearchPermissionsServiceTest, ArePermissionsControlledByDSE) {
GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleAusURL))); GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleAusURL)));
// False for http origin. // False for http origin.
test_delegate()->SetDSEOrigin(kGoogleHTTPURL); test_delegate()->ChangeDSEOrigin(kGoogleHTTPURL);
EXPECT_FALSE( EXPECT_FALSE(
GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleHTTPURL))); GetService()->ArePermissionsControlledByDSE(ToOrigin(kGoogleHTTPURL)));
// True even for non-Google search engines. // True even for non-Google search engines.
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_TRUE( EXPECT_TRUE(
GetService()->ArePermissionsControlledByDSE(ToOrigin(kExampleURL))); GetService()->ArePermissionsControlledByDSE(ToOrigin(kExampleURL)));
} }
TEST_F(SearchPermissionsServiceTest, DSEChanges) { TEST_F(SearchPermissionsServiceTest, DSEChanges) {
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(CONTENT_SETTING_ALLOW, EXPECT_EQ(CONTENT_SETTING_ALLOW,
...@@ -309,7 +313,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -309,7 +313,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
// Change to google.com.au. Settings for google.com should revert and settings // Change to google.com.au. Settings for google.com should revert and settings
// for google.com.au should be set to allow. // for google.com.au should be set to allow.
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(CONTENT_SETTING_ASK, EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(CONTENT_SETTING_ASK, EXPECT_EQ(CONTENT_SETTING_ASK,
...@@ -325,7 +329,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -325,7 +329,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
// change back to google.com, the setting should still be blocked. // change back to google.com, the setting should still be blocked.
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_BLOCK); CONTENT_SETTING_BLOCK);
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_EQ( EXPECT_EQ(
...@@ -337,7 +341,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -337,7 +341,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
// notifications setting should remain blocked. // notifications setting should remain blocked.
SetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, SetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_ALLOW); CONTENT_SETTING_ALLOW);
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_EQ( EXPECT_EQ(
...@@ -346,7 +350,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -346,7 +350,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
// Now changing back to google.com, the google.com.au notifications setting // Now changing back to google.com, the google.com.au notifications setting
// should be reset to ask (we reset it because of the conflict previously). // should be reset to ask (we reset it because of the conflict previously).
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
EXPECT_EQ(CONTENT_SETTING_BLOCK, EXPECT_EQ(CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_EQ( EXPECT_EQ(
...@@ -358,7 +362,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -358,7 +362,7 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
// reset it back to ask once it is no longer the DSE. // reset it back to ask once it is no longer the DSE.
SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, SetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
CONTENT_SETTING_ALLOW); CONTENT_SETTING_ALLOW);
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(CONTENT_SETTING_ASK, EXPECT_EQ(CONTENT_SETTING_ASK,
GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); GetContentSetting(kGoogleURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_EQ( EXPECT_EQ(
...@@ -367,29 +371,29 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) { ...@@ -367,29 +371,29 @@ TEST_F(SearchPermissionsServiceTest, DSEChanges) {
} }
TEST_F(SearchPermissionsServiceTest, DSEChangesAndDisclosure) { TEST_F(SearchPermissionsServiceTest, DSEChangesAndDisclosure) {
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
SearchGeolocationDisclosureTabHelper::FakeShowingDisclosureForTests( SearchGeolocationDisclosureTabHelper::FakeShowingDisclosureForTests(
profile()); profile());
// Change to google.com.au. The disclosure should not be reset. // Change to google.com.au. The disclosure should not be reset.
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_FALSE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests( EXPECT_FALSE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests(
profile())); profile()));
// Now set to a non-google search. The disclosure should be reset. // Now set to a non-google search. The disclosure should be reset.
test_delegate()->SetDSEOrigin(kExampleURL); test_delegate()->ChangeDSEOrigin(kExampleURL);
EXPECT_TRUE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests( EXPECT_TRUE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests(
profile())); profile()));
SearchGeolocationDisclosureTabHelper::FakeShowingDisclosureForTests( SearchGeolocationDisclosureTabHelper::FakeShowingDisclosureForTests(
profile()); profile());
// Go back to google.com.au. The disclosure should again be reset. // Go back to google.com.au. The disclosure should again be reset.
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_TRUE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests( EXPECT_TRUE(SearchGeolocationDisclosureTabHelper::IsDisclosureResetForTests(
profile())); profile()));
} }
TEST_F(SearchPermissionsServiceTest, Embargo) { TEST_F(SearchPermissionsServiceTest, Embargo) {
test_delegate()->SetDSEOrigin(kGoogleURL); test_delegate()->ChangeDSEOrigin(kGoogleURL);
// Place another origin under embargo. // Place another origin under embargo.
GURL google_aus_url(kGoogleAusURL); GURL google_aus_url(kGoogleAusURL);
...@@ -407,9 +411,93 @@ TEST_F(SearchPermissionsServiceTest, Embargo) { ...@@ -407,9 +411,93 @@ TEST_F(SearchPermissionsServiceTest, Embargo) {
EXPECT_EQ(result.content_setting, CONTENT_SETTING_BLOCK); EXPECT_EQ(result.content_setting, CONTENT_SETTING_BLOCK);
// Now change the DSE to this origin and make sure the embargo is cleared. // Now change the DSE to this origin and make sure the embargo is cleared.
test_delegate()->SetDSEOrigin(kGoogleAusURL); test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
result = auto_blocker->GetEmbargoResult(GURL(kGoogleAusURL), result = auto_blocker->GetEmbargoResult(GURL(kGoogleAusURL),
CONTENT_SETTINGS_TYPE_GEOLOCATION); CONTENT_SETTINGS_TYPE_GEOLOCATION);
EXPECT_EQ(result.source, PermissionStatusSource::UNSPECIFIED); EXPECT_EQ(result.source, PermissionStatusSource::UNSPECIFIED);
EXPECT_EQ(result.content_setting, CONTENT_SETTING_ASK); EXPECT_EQ(result.content_setting, CONTENT_SETTING_ASK);
} }
TEST_F(SearchPermissionsServiceTest, DSEChangedButDisabled) {
SetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION,
CONTENT_SETTING_BLOCK);
test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// DSE disabled by enterprise policy
test_delegate()->ChangeDSEOrigin(std::string());
// The settings should return to their original value.
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// Now disable enterprise policy. We revert to the default ALLOW behavior.
test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
}
TEST_F(SearchPermissionsServiceTest, DSEInitializedButDisabled) {
test_delegate()->ChangeDSEOrigin(kGoogleAusURL);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// Set the DSE origin without calling OnDSEChanged.
test_delegate()->set_dse_origin(std::string());
ReinitializeService(/*clear_pref=*/false);
// Settings should revert back to default.
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
// The pref shouldn't exist anymore.
EXPECT_FALSE(
profile()->GetPrefs()->HasPrefPath(prefs::kDSEPermissionsSettings));
// Firing the DSE changed event now should not do anything.
test_delegate()->ChangeDSEOrigin(std::string());
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ASK,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_NOTIFICATIONS));
EXPECT_FALSE(
profile()->GetPrefs()->HasPrefPath(prefs::kDSEPermissionsSettings));
// Re-enabling the DSE origin should revert to the default ALLOW behavior.
test_delegate()->set_dse_origin(kGoogleAusURL);
ReinitializeService(/*clear_pref=*/false);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, CONTENT_SETTINGS_TYPE_GEOLOCATION));
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
GetContentSetting(kGoogleAusURL, 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