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; ...@@ -12,6 +12,7 @@ import androidx.annotation.Nullable;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.R; 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.DisplayableProfileData;
import org.chromium.chrome.browser.signin.ProfileDataCache; import org.chromium.chrome.browser.signin.ProfileDataCache;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerCoordinator.AccountPickerAccessPoint; import org.chromium.chrome.browser.signin.account_picker.AccountPickerCoordinator.AccountPickerAccessPoint;
...@@ -104,7 +105,10 @@ class AccountPickerMediator { ...@@ -104,7 +105,10 @@ class AccountPickerMediator {
mListModel.add(new MVCListAdapter.ListItem(ItemType.ADD_ACCOUNT_ROW, model)); mListModel.add(new MVCListAdapter.ListItem(ItemType.ADD_ACCOUNT_ROW, model));
// Add a "Go incognito mode" row // 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( PropertyModel incognitoModel = IncognitoAccountRowProperties.createModel(
mAccountPickerListener::goIncognitoMode); mAccountPickerListener::goIncognitoMode);
mListModel.add( mListModel.add(
......
...@@ -39,6 +39,7 @@ import org.chromium.base.test.util.Feature; ...@@ -39,6 +39,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; 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.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.night_mode.ChromeNightModeTestUtils; import org.chromium.chrome.browser.night_mode.ChromeNightModeTestUtils;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator; import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator;
...@@ -114,6 +115,7 @@ public class AccountPickerBottomSheetRenderTest { ...@@ -114,6 +115,7 @@ public class AccountPickerBottomSheetRenderTest {
@Before @Before
public void setUp() { public void setUp() {
initMocks(this); initMocks(this);
IncognitoUtils.setEnabledForTesting(true);
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
} }
......
...@@ -48,6 +48,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -48,6 +48,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; 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.incognito.interstitial.IncognitoInterstitialDelegate;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator; import org.chromium.chrome.browser.signin.account_picker.AccountPickerBottomSheetCoordinator;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerDelegate; import org.chromium.chrome.browser.signin.account_picker.AccountPickerDelegate;
...@@ -125,6 +126,7 @@ public class AccountPickerBottomSheetTest { ...@@ -125,6 +126,7 @@ public class AccountPickerBottomSheetTest {
@Before @Before
public void setUp() { public void setUp() {
initMocks(this); initMocks(this);
IncognitoUtils.setEnabledForTesting(true);
mAccountManagerTestRule.addAccount(PROFILE_DATA1); mAccountManagerTestRule.addAccount(PROFILE_DATA1);
mAccountManagerTestRule.addAccount(PROFILE_DATA2); mAccountManagerTestRule.addAccount(PROFILE_DATA2);
} }
...@@ -140,17 +142,39 @@ public class AccountPickerBottomSheetTest { ...@@ -140,17 +142,39 @@ public class AccountPickerBottomSheetTest {
@MediumTest @MediumTest
public void testExpandedSheet() { public void testExpandedSheet() {
buildAndShowExpandedBottomSheet(); 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))) onView(allOf(withText(PROFILE_DATA1.getAccountName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed())); .check(matches(isDisplayed()));
onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE))) onView(allOf(withText(PROFILE_DATA1.getFullName()), withEffectiveVisibility(VISIBLE)))
.check(matches(isDisplayed())); .check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountName())).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_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_selected_account)).check(matches(not(isDisplayed())));
onView(withId(R.id.account_picker_continue_as_button)).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 @Test
@MediumTest @MediumTest
public void testCollapsedSheetWithZeroAccount() { public void testCollapsedSheetWithZeroAccount() {
......
...@@ -20,6 +20,7 @@ import org.mockito.Mock; ...@@ -20,6 +20,7 @@ import org.mockito.Mock;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
import org.chromium.base.test.BaseRobolectricTestRunner; 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.profiles.Profile;
import org.chromium.chrome.browser.signin.DisplayableProfileData; import org.chromium.chrome.browser.signin.DisplayableProfileData;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
...@@ -70,6 +71,7 @@ public class AccountPickerMediatorTest { ...@@ -70,6 +71,7 @@ public class AccountPickerMediatorTest {
.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress( .findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
anyString())) anyString()))
.thenReturn(null); .thenReturn(null);
IncognitoUtils.setEnabledForTesting(true);
} }
@After @After
...@@ -77,6 +79,7 @@ public class AccountPickerMediatorTest { ...@@ -77,6 +79,7 @@ public class AccountPickerMediatorTest {
if (mMediator != null) { if (mMediator != null) {
mMediator.destroy(); mMediator.destroy();
} }
IncognitoUtils.setEnabledForTesting(null);
IdentityServicesProvider.setInstanceForTests(null); IdentityServicesProvider.setInstanceForTests(null);
Profile.setLastUsedProfileForTesting(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