Commit 73240199 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Remove state variables from FourStateCookieSettingsPreference

The preference only needs to know which radio button is selected
to determine its state. Removing the variables avoids inconsistencies.
The values used for initialization are moved into a class to avoid a
large number of boolean parameters.

Change-Id: I1cde64d6c14c396b2997aafdcbaf26a49453b25d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139727
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758881}
parent e7ea3e9e
...@@ -21,8 +21,6 @@ import org.chromium.components.browser_ui.widget.RadioButtonWithDescription; ...@@ -21,8 +21,6 @@ import org.chromium.components.browser_ui.widget.RadioButtonWithDescription;
import org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables; import org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables;
import org.chromium.components.content_settings.CookieControlsMode; import org.chromium.components.content_settings.CookieControlsMode;
import java.util.Arrays;
/** /**
* A 4-state radio group Preference used for the Cookies subpage of SiteSettings. * A 4-state radio group Preference used for the Cookies subpage of SiteSettings.
*/ */
...@@ -36,14 +34,25 @@ public class FourStateCookieSettingsPreference ...@@ -36,14 +34,25 @@ public class FourStateCookieSettingsPreference
BLOCK BLOCK
} }
// Signals used to determine the view and button states. /**
private boolean mCookiesContentSettingEnforced; * Signals used to determine the view and button states.
private boolean mThirdPartyBlockingEnforced; */
private boolean mAllowCookies; public static class Params {
private boolean mBlockThirdPartyCookies; // Whether the cookies content setting is enabled.
// An enum indicating when to block third-party cookies. public boolean allowCookies;
private @CookieControlsMode int mCookieControlsMode; // Whether third-party blocking is enabled.
private CookieSettingsState mState = CookieSettingsState.UNINITIALIZED; public boolean blockThirdPartyCookies;
// An enum indicating when to block third-party cookies.
public @CookieControlsMode int cookieControlsMode;
// Whether the cookies content setting is enforced.
public boolean cookiesContentSettingEnforced;
// Whether third-party blocking is enforced.
public boolean thirdPartyBlockingEnforced;
}
// Keeps the params that are applied to the UI if the params are set before the UI is ready.
private Params mInitializationParams;
// UI Elements. // UI Elements.
private RadioButtonWithDescription mAllowButton; private RadioButtonWithDescription mAllowButton;
...@@ -66,23 +75,12 @@ public class FourStateCookieSettingsPreference ...@@ -66,23 +75,12 @@ public class FourStateCookieSettingsPreference
/** /**
* Sets the cookie settings state and updates the radio buttons. * Sets the cookie settings state and updates the radio buttons.
* @param cookiesContentSettingEnforced Whether the cookies content setting is enforced.
* @param thirdPartyBlockingEnforced Whether third-party blocking is enforced.
* @param allowCookies Whether the cookies content setting is enabled.
* @param blockThirdPartyCookies Whether third-party blocking is enabled.
* @param cookieControlsMode The CookieControlsMode enum for the current cookie settings state.
*/ */
public void setState(boolean cookiesContentSettingEnforced, boolean thirdPartyBlockingEnforced, public void setState(Params state) {
boolean allowCookies, boolean blockThirdPartyCookies,
@CookieControlsMode int cookieControlsMode) {
mCookiesContentSettingEnforced = cookiesContentSettingEnforced;
mThirdPartyBlockingEnforced = thirdPartyBlockingEnforced;
mAllowCookies = allowCookies;
mBlockThirdPartyCookies = blockThirdPartyCookies;
mCookieControlsMode = cookieControlsMode;
if (mRadioGroup != null) { if (mRadioGroup != null) {
setRadioButtons(); configureRadioButtons(state);
} else {
mInitializationParams = state;
} }
} }
...@@ -90,22 +88,30 @@ public class FourStateCookieSettingsPreference ...@@ -90,22 +88,30 @@ public class FourStateCookieSettingsPreference
* @return The state that is currently selected. * @return The state that is currently selected.
*/ */
public CookieSettingsState getState() { public CookieSettingsState getState() {
return mState; if (mRadioGroup == null && mInitializationParams == null) {
} return CookieSettingsState.UNINITIALIZED;
}
// Calculate the state from mInitializationParams if the UI is not initialized yet.
if (mInitializationParams != null) {
return getActiveState(mInitializationParams);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (mAllowButton.isChecked()) { if (mAllowButton.isChecked()) {
mState = CookieSettingsState.ALLOW; return CookieSettingsState.ALLOW;
} else if (mBlockThirdPartyIncognitoButton.isChecked()) { } else if (mBlockThirdPartyIncognitoButton.isChecked()) {
mState = CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO; return CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO;
} else if (mBlockThirdPartyButton.isChecked()) { } else if (mBlockThirdPartyButton.isChecked()) {
mState = CookieSettingsState.BLOCK_THIRD_PARTY; return CookieSettingsState.BLOCK_THIRD_PARTY;
} else if (mBlockButton.isChecked()) { } else {
mState = CookieSettingsState.BLOCK; assert mBlockButton.isChecked();
return CookieSettingsState.BLOCK;
} }
}
callChangeListener(mState); @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
callChangeListener(getState());
} }
@Override @Override
...@@ -128,48 +134,51 @@ public class FourStateCookieSettingsPreference ...@@ -128,48 +134,51 @@ public class FourStateCookieSettingsPreference
mManagedView.setCompoundDrawablesRelativeWithIntrinsicBounds( mManagedView.setCompoundDrawablesRelativeWithIntrinsicBounds(
managedIcon, drawables[1], drawables[2], drawables[3]); managedIcon, drawables[1], drawables[2], drawables[3]);
setRadioButtons(); if (mInitializationParams != null) {
configureRadioButtons(mInitializationParams);
}
} }
private RadioButtonWithDescription getActiveRadioButton() { private CookieSettingsState getActiveState(Params params) {
// These conditions only check the preference combinations that deterministically decide // These conditions only check the preference combinations that deterministically decide
// your cookie settings state. In the future we would refactor the backend preferences to // your cookie settings state. In the future we would refactor the backend preferences to
// reflect the only possible states you can be in // reflect the only possible states you can be in
// (Allow/BlockThirdPartyIncognito/BlockThirdParty/Block), instead of using this // (Allow/BlockThirdPartyIncognito/BlockThirdParty/Block), instead of using this
// combination of multiple signals. // combination of multiple signals.
if (!mAllowCookies) { if (!params.allowCookies) {
mState = CookieSettingsState.BLOCK; return CookieSettingsState.BLOCK;
return mBlockButton; } else if (params.blockThirdPartyCookies
} else if (mBlockThirdPartyCookies || mCookieControlsMode == CookieControlsMode.ON) { || params.cookieControlsMode == CookieControlsMode.ON) {
// Having CookieControlsMode.ON is equivalent to having the BLOCK_THIRD_PARTY_COOKIES // Having CookieControlsMode.ON is equivalent to having the BLOCK_THIRD_PARTY_COOKIES
// pref set to enabled, because it means third party cookie blocking is always on. // pref set to enabled, because it means third party cookie blocking is always on.
mState = CookieSettingsState.BLOCK_THIRD_PARTY; return CookieSettingsState.BLOCK_THIRD_PARTY;
return mBlockThirdPartyButton; } else if (params.cookieControlsMode == CookieControlsMode.INCOGNITO_ONLY) {
} else if (mCookieControlsMode == CookieControlsMode.INCOGNITO_ONLY) { return CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO;
mState = CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO;
return mBlockThirdPartyIncognitoButton;
} else { } else {
mState = CookieSettingsState.ALLOW; return CookieSettingsState.ALLOW;
return mAllowButton;
} }
} }
private void setRadioButtons() { private void configureRadioButtons(Params params) {
assert (mRadioGroup != null);
mAllowButton.setEnabled(true); mAllowButton.setEnabled(true);
mBlockThirdPartyIncognitoButton.setEnabled(true); mBlockThirdPartyIncognitoButton.setEnabled(true);
mBlockThirdPartyButton.setEnabled(true); mBlockThirdPartyButton.setEnabled(true);
mBlockButton.setEnabled(true); mBlockButton.setEnabled(true);
for (RadioButtonWithDescription button : getEnforcedButtons()) { for (RadioButtonWithDescription button : getEnforcedButtons(params)) {
button.setEnabled(false); button.setEnabled(false);
} }
mManagedView.setVisibility((mCookiesContentSettingEnforced || mThirdPartyBlockingEnforced) mManagedView.setVisibility(
(params.cookiesContentSettingEnforced || params.thirdPartyBlockingEnforced)
? View.VISIBLE ? View.VISIBLE
: View.GONE); : View.GONE);
RadioButtonWithDescription button = getActiveRadioButton(); RadioButtonWithDescription button = getButton(getActiveState(params));
// Always want to enable the selected option. // Always want to enable the selected option.
button.setEnabled(true); button.setEnabled(true);
button.setChecked(true); button.setChecked(true);
mInitializationParams = null;
} }
/** /**
...@@ -179,27 +188,45 @@ public class FourStateCookieSettingsPreference ...@@ -179,27 +188,45 @@ public class FourStateCookieSettingsPreference
return args; return args;
} }
private RadioButtonWithDescription getButton(CookieSettingsState state) {
switch (state) {
case ALLOW:
return mAllowButton;
case BLOCK_THIRD_PARTY_INCOGNITO:
return mBlockThirdPartyIncognitoButton;
case BLOCK_THIRD_PARTY:
return mBlockThirdPartyButton;
case BLOCK:
return mBlockButton;
case UNINITIALIZED:
assert false;
return null;
}
assert false;
return null;
}
/** /**
* @return An array of radio buttons that have to be disabled as they can't be selected due to * @return An array of radio buttons that have to be disabled as they can't be selected due to
* policy restrictions. * policy restrictions.
*/ */
private RadioButtonWithDescription[] getEnforcedButtons() { private RadioButtonWithDescription[] getEnforcedButtons(Params params) {
if (!mCookiesContentSettingEnforced && !mThirdPartyBlockingEnforced) { if (!params.cookiesContentSettingEnforced && !params.thirdPartyBlockingEnforced) {
return buttons(); return buttons();
} }
if (mCookiesContentSettingEnforced && mThirdPartyBlockingEnforced) { if (params.cookiesContentSettingEnforced && params.thirdPartyBlockingEnforced) {
return buttons(mAllowButton, mBlockThirdPartyIncognitoButton, mBlockThirdPartyButton, return buttons(mAllowButton, mBlockThirdPartyIncognitoButton, mBlockThirdPartyButton,
mBlockButton); mBlockButton);
} }
if (mCookiesContentSettingEnforced) { if (params.cookiesContentSettingEnforced) {
if (mAllowCookies) { if (params.allowCookies) {
return buttons(mBlockButton); return buttons(mBlockButton);
} else { } else {
return buttons(mAllowButton, mBlockThirdPartyIncognitoButton, return buttons(mAllowButton, mBlockThirdPartyIncognitoButton,
mBlockThirdPartyButton, mBlockButton); mBlockThirdPartyButton, mBlockButton);
} }
} }
if (mBlockThirdPartyCookies) { if (params.blockThirdPartyCookies) {
return buttons(mAllowButton, mBlockThirdPartyIncognitoButton); return buttons(mAllowButton, mBlockThirdPartyIncognitoButton);
} else { } else {
return buttons(mBlockThirdPartyIncognitoButton, mBlockThirdPartyButton); return buttons(mBlockThirdPartyIncognitoButton, mBlockThirdPartyButton);
...@@ -207,24 +234,8 @@ public class FourStateCookieSettingsPreference ...@@ -207,24 +234,8 @@ public class FourStateCookieSettingsPreference
} }
@VisibleForTesting @VisibleForTesting
public boolean isStateEnforced(CookieSettingsState state) { boolean isButtonEnabledForTesting(CookieSettingsState state) {
RadioButtonWithDescription button; assert getButton(state) != null;
switch (state) { return getButton(state).isEnabled();
case ALLOW:
button = mAllowButton;
break;
case BLOCK_THIRD_PARTY_INCOGNITO:
button = mBlockThirdPartyIncognitoButton;
break;
case BLOCK_THIRD_PARTY:
button = mBlockThirdPartyButton;
break;
case BLOCK:
button = mBlockButton;
break;
default:
return false;
}
return Arrays.asList(getEnforcedButtons()).contains(button);
} }
} }
...@@ -1034,11 +1034,18 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment ...@@ -1034,11 +1034,18 @@ public class SingleCategorySettings extends SiteSettingsPreferenceFragment
private void configureFourStateCookieToggle( private void configureFourStateCookieToggle(
FourStateCookieSettingsPreference fourStateCookieToggle) { FourStateCookieSettingsPreference fourStateCookieToggle) {
fourStateCookieToggle.setOnPreferenceChangeListener(this); fourStateCookieToggle.setOnPreferenceChangeListener(this);
fourStateCookieToggle.setState(mCategory.isManaged(), FourStateCookieSettingsPreference.Params params =
PrefServiceBridge.getInstance().isManagedPreference(Pref.BLOCK_THIRD_PARTY_COOKIES), new FourStateCookieSettingsPreference.Params();
WebsitePreferenceBridge.isCategoryEnabled(ContentSettingsType.COOKIES), params.allowCookies =
PrefServiceBridge.getInstance().getBoolean(Pref.BLOCK_THIRD_PARTY_COOKIES), WebsitePreferenceBridge.isCategoryEnabled(ContentSettingsType.COOKIES);
PrefServiceBridge.getInstance().getInteger(Pref.COOKIE_CONTROLS_MODE)); params.blockThirdPartyCookies =
PrefServiceBridge.getInstance().getBoolean(Pref.BLOCK_THIRD_PARTY_COOKIES);
params.cookieControlsMode =
PrefServiceBridge.getInstance().getInteger(Pref.COOKIE_CONTROLS_MODE);
params.cookiesContentSettingEnforced = mCategory.isManaged();
params.thirdPartyBlockingEnforced =
PrefServiceBridge.getInstance().isManagedPreference(Pref.BLOCK_THIRD_PARTY_COOKIES);
fourStateCookieToggle.setState(params);
} }
private void configureTriStateToggle( private void configureTriStateToggle(
......
...@@ -261,7 +261,7 @@ public class SiteSettingsTest { ...@@ -261,7 +261,7 @@ public class SiteSettingsTest {
/** /**
* Checks if the button representing the given state matches the managed expectation. * Checks if the button representing the given state matches the managed expectation.
*/ */
private void checkFourStateCookieToggleButtonUnmanaged(final SettingsActivity settingsActivity, private void checkFourStateCookieToggleButtonEnabled(final SettingsActivity settingsActivity,
final CookieSettingsState state, final boolean expected) { final CookieSettingsState state, final boolean expected) {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
SingleCategorySettings preferences = SingleCategorySettings preferences =
...@@ -269,8 +269,8 @@ public class SiteSettingsTest { ...@@ -269,8 +269,8 @@ public class SiteSettingsTest {
FourStateCookieSettingsPreference fourStateCookieToggle = FourStateCookieSettingsPreference fourStateCookieToggle =
(FourStateCookieSettingsPreference) preferences.findPreference( (FourStateCookieSettingsPreference) preferences.findPreference(
SingleCategorySettings.FOUR_STATE_COOKIE_TOGGLE_KEY); SingleCategorySettings.FOUR_STATE_COOKIE_TOGGLE_KEY);
Assert.assertNotEquals("Button should be " + (expected ? "unmanaged" : "managed"), Assert.assertEquals(state + " button should be " + (expected ? "enabled" : "disabled"),
fourStateCookieToggle.isStateEnforced(state), expected); fourStateCookieToggle.isButtonEnabledForTesting(state), expected);
}); });
} }
...@@ -544,58 +544,57 @@ public class SiteSettingsTest { ...@@ -544,58 +544,57 @@ public class SiteSettingsTest {
} }
/** /**
* Set the cookie content setting to managed and ensure the correct radio buttons are enforced. * Set the cookie content setting to allow through policy and ensure the correct radio buttons
* are enabled.
*/ */
@Test @Test
@SmallTest @SmallTest
@Feature({"Preferences"}) @Feature({"Preferences"})
@Policies.Add({ @Policies.Item(key = "DefaultCookiesSetting", string = "1") }) @Policies.Add({ @Policies.Item(key = "DefaultCookiesSetting", string = "1") })
public void testDefaultCookiesSettingManagedTrue() throws Exception { public void testDefaultCookiesSettingManagedAllow() throws Exception {
checkDefaultCookiesSettingManaged(true); checkDefaultCookiesSettingManaged(true);
checkThirdPartyCookieBlockingManaged(false); checkThirdPartyCookieBlockingManaged(false);
// The ContentSetting is managed (and set to true) while ThirdPartyCookieBlocking is not // The ContentSetting is managed (and set to ALLOW) while ThirdPartyCookieBlocking is not
// managed. This means that every button other than BLOCKED is unmanaged. // managed. This means that every button other than BLOCK is enabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, true);
settingsActivity, CookieSettingsState.ALLOW, true); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, true); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, true);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, false);
settingsActivity, CookieSettingsState.BLOCK, false);
settingsActivity.finish(); settingsActivity.finish();
} }
/** /**
* Set the cookie content setting to managed and ensure the correct radio buttons are enforced. * Set the cookie content setting to block through a policy and ensure the correct radio buttons
* are enabled.
*/ */
@Test @Test
@SmallTest @SmallTest
@Feature({"Preferences"}) @Feature({"Preferences"})
@Policies.Add({ @Policies.Item(key = "DefaultCookiesSetting", string = "2") }) @Policies.Add({ @Policies.Item(key = "DefaultCookiesSetting", string = "2") })
public void testDefaultCookiesSettingManagedFalse() throws Exception { public void testDefaultCookiesSettingManagedBlock() {
checkDefaultCookiesSettingManaged(true); checkDefaultCookiesSettingManaged(true);
checkThirdPartyCookieBlockingManaged(false); checkThirdPartyCookieBlockingManaged(false);
// The ContentSetting is managed (and set to false) while ThirdPartyCookieBlocking is not // The ContentSetting is managed (and set to BLOCK) while ThirdPartyCookieBlocking is not
// managed. This means cookies should always be blocked, so the user cannot choose any other // managed. This means cookies should always be blocked, so the user cannot choose any other
// options and all buttons should be managed. // options and all buttons except the active one should be disabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, false);
settingsActivity, CookieSettingsState.ALLOW, false); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity, CookieSettingsState.BLOCK, false);
settingsActivity.finish(); settingsActivity.finish();
} }
/** /**
* Set third-party cookie blocking to managed and ensure the correct radio buttons are enforced. * Enable third-party cookie blocking through policy and ensure the correct radio buttons are
* enabled.
*/ */
@Test @Test
@SmallTest @SmallTest
...@@ -607,22 +606,21 @@ public class SiteSettingsTest { ...@@ -607,22 +606,21 @@ public class SiteSettingsTest {
checkThirdPartyCookieBlockingManaged(true); checkThirdPartyCookieBlockingManaged(true);
// ThirdPartyCookieBlocking is managed (and set to true) while the ContentSetting is not // ThirdPartyCookieBlocking is managed (and set to true) while the ContentSetting is not
// managed. This means a user can choose only between BLOCK_THIRD_PARTY and BLOCK, so only // managed. This means a user can choose only between BLOCK_THIRD_PARTY and BLOCK, so only
// these should be unmanaged. // these should be enabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, false);
settingsActivity, CookieSettingsState.ALLOW, false); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity.finish(); settingsActivity.finish();
} }
/** /**
* Set third-party cookie blocking to managed and ensure the correct radio buttons are enforced. * Disable third-party cookie blocking through policy and ensure the correct radio buttons are
* enabled.
*/ */
@Test @Test
@SmallTest @SmallTest
...@@ -634,23 +632,21 @@ public class SiteSettingsTest { ...@@ -634,23 +632,21 @@ public class SiteSettingsTest {
checkThirdPartyCookieBlockingManaged(true); checkThirdPartyCookieBlockingManaged(true);
// ThirdPartyCookieBlocking is managed (and set to false) while the ContentSetting is not // ThirdPartyCookieBlocking is managed (and set to false) while the ContentSetting is not
// managed. This means a user can only choose to ALLOW all cookies or BLOCK all cookies, so // managed. This means a user can only choose to ALLOW all cookies or BLOCK all cookies, so
// only these should be unmanaged. // only these should be enabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, true);
settingsActivity, CookieSettingsState.ALLOW, true); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity.finish(); settingsActivity.finish();
} }
/** /**
* Set both the cookie content setting and third-party cookie blocking to managed and ensure the * Set both the cookie content setting and third-party cookie blocking through policy and ensure
* correct radio buttons are enforced. * the correct radio buttons are enabled.
*/ */
@Test @Test
@SmallTest @SmallTest
...@@ -664,18 +660,16 @@ public class SiteSettingsTest { ...@@ -664,18 +660,16 @@ public class SiteSettingsTest {
checkDefaultCookiesSettingManaged(true); checkDefaultCookiesSettingManaged(true);
checkThirdPartyCookieBlockingManaged(true); checkThirdPartyCookieBlockingManaged(true);
// The ContentSetting and ThirdPartyCookieBlocking are managed. This means a user has a // The ContentSetting and ThirdPartyCookieBlocking are managed. This means a user has a
// fixed setting for cookies that they cannot change. Therefore, all buttons should be // fixed setting for cookies that they cannot change. Therefore, all buttons except the
// managed. // selected one should be disabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, true);
settingsActivity, CookieSettingsState.ALLOW, false); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, false);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, false);
settingsActivity, CookieSettingsState.BLOCK, false);
settingsActivity.finish(); settingsActivity.finish();
} }
...@@ -689,17 +683,15 @@ public class SiteSettingsTest { ...@@ -689,17 +683,15 @@ public class SiteSettingsTest {
checkDefaultCookiesSettingManaged(false); checkDefaultCookiesSettingManaged(false);
checkThirdPartyCookieBlockingManaged(false); checkThirdPartyCookieBlockingManaged(false);
// The ContentSetting and ThirdPartyCookieBlocking are unmanaged. This means all buttons // The ContentSetting and ThirdPartyCookieBlocking are unmanaged. This means all buttons
// should be unmanaged. // should be enabled.
SettingsActivity settingsActivity = SettingsActivity settingsActivity =
SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES); SiteSettingsTestUtils.startSiteSettingsCategory(SiteSettingsCategory.Type.COOKIES);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.ALLOW, true);
settingsActivity, CookieSettingsState.ALLOW, true); checkFourStateCookieToggleButtonEnabled(
checkFourStateCookieToggleButtonUnmanaged(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, true); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY_INCOGNITO, true);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(
settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true); settingsActivity, CookieSettingsState.BLOCK_THIRD_PARTY, true);
checkFourStateCookieToggleButtonUnmanaged( checkFourStateCookieToggleButtonEnabled(settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity, CookieSettingsState.BLOCK, true);
settingsActivity.finish(); settingsActivity.finish();
} }
......
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