Commit bd984b81 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][WebSignin] Hide incognito row when incognito disabled

This CL hides the incognito row when incognito mode is disabled by
the policy IncognitoModeAvailability.

Bug: 1136777
Change-Id: I44c004870d6cd51b67951bbcbd853a8b11636c95
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461319
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815634}
parent f7fb04ec
......@@ -12,6 +12,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.ProfileDataCache;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerCoordinator.AccountPickerAccessPoint;
......@@ -104,7 +105,10 @@ class AccountPickerMediator {
mListModel.add(new MVCListAdapter.ListItem(ItemType.ADD_ACCOUNT_ROW, model));
// Add a "Go incognito mode" row
if (mAccessPoint == AccountPickerAccessPoint.WEB) {
// TODO(https://crbug.com/1136802): Let ctor receive a boolean directly to control
// the visibility of the incognito row.
if (mAccessPoint == AccountPickerAccessPoint.WEB
&& IncognitoUtils.isIncognitoModeEnabled()) {
PropertyModel incognitoModel = IncognitoAccountRowProperties.createModel(
mAccountPickerListener::goIncognitoMode);
mListModel.add(
......
......@@ -39,6 +39,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.night_mode.ChromeNightModeTestUtils;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator;
......@@ -114,6 +115,7 @@ public class AccountPickerBottomSheetRenderTest {
@Before
public void setUp() {
initMocks(this);
IncognitoUtils.setEnabledForTesting(true);
mActivityTestRule.startMainActivityOnBlankPage();
}
......
......@@ -48,6 +48,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerDelegate;
......@@ -125,6 +126,7 @@ public class AccountPickerBottomSheetTest {
@Before
public void setUp() {
initMocks(this);
IncognitoUtils.setEnabledForTesting(true);
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
mAccountManagerTestRule.addAccount(PROFILE_DATA2);
}
......@@ -140,17 +142,39 @@ public class AccountPickerBottomSheetTest {
@MediumTest
public void testExpandedSheet() {
buildAndShowExpandedBottomSheet();
// Since PROFILE_DATA1 exists also in the hidden view of the selected account,
// withEffectiveVisibility(VISIBLE) is needed here
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed()));
onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed()));
onView(withText(R.string.signin_incognito_button)).check(matches(isDisplayed()));
onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed())));
onView(withId(R.id.account_picker_continue_as_button)).check(matches(not(isDisplayed())));
}
@Test
@MediumTest
public void testExpandedSheetWithIncognitoModeDisabled() {
IncognitoUtils.setEnabledForTesting(false);
buildAndShowExpandedBottomSheet();
// Since PROFILE_DATA1 exists also in the hidden view of the selected account,
// withEffectiveVisibility(VISIBLE) is needed here
onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).check(matches(isDisplayed()));
onView(withText(R.string.signin_add_account_to_device)).check(matches(isDisplayed()));
onView(withId(R.id.account_picker_selected_account)).check(matches(not(isDisplayed())));
onView(withId(R.id.account_picker_continue_as_button)).check(matches(not(isDisplayed())));
onView(withText(R.string.signin_incognito_button)).check(doesNotExist());
}
@Test
@MediumTest
public void testCollapsedSheetWithZeroAccount() {
......
......@@ -20,6 +20,7 @@ import org.mockito.Mock;
import org.robolectric.RuntimeEnvironment;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.IdentityServicesProvider;
......@@ -70,6 +71,7 @@ public class AccountPickerMediatorTest {
.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
anyString()))
.thenReturn(null);
IncognitoUtils.setEnabledForTesting(true);
}
@After
......@@ -77,6 +79,7 @@ public class AccountPickerMediatorTest {
if (mMediator != null) {
mMediator.destroy();
}
IncognitoUtils.setEnabledForTesting(null);
IdentityServicesProvider.setInstanceForTests(null);
Profile.setLastUsedProfileForTesting(null);
}
......
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