Commit 5c9e565a authored by Alice Wang's avatar Alice Wang Committed by Chromium LUCI CQ

[Signin][Android] Make AccountPickerDelegateImpl independent of incognito package

This CL makes AccountPickerDelegateImpl independent of incognito package
by moving the incognito mode policy check to SigninBridge.

Bug: 1149857
Change-Id: Ib5ae49f71ea84a08131c70ecd3998eaefe5ac66e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2640654Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846057}
parent 7574d4ad
......@@ -12,6 +12,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.account_picker.AccountPickerDelegateImpl;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
......@@ -103,7 +104,8 @@ final class SigninBridge {
activity, bottomSheetController,
new AccountPickerDelegateImpl(windowAndroid, activity.getActivityTab(),
new WebSigninBridge.Factory(), continueUrl),
regularTabModel, incognitoTabCreator, HelpAndFeedbackLauncherImpl.getInstance());
regularTabModel, incognitoTabCreator, HelpAndFeedbackLauncherImpl.getInstance(),
/* showIncognitoRow= */ IncognitoUtils.isIncognitoModeEnabled());
}
private SigninBridge() {}
......
......@@ -13,7 +13,6 @@ import androidx.annotation.Nullable;
import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.incognito.IncognitoUtils;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.services.SigninManager;
......@@ -148,14 +147,6 @@ public class AccountPickerDelegateImpl implements WebSigninBridge.Listener, Acco
onUpdateCredentialsCallback);
}
/**
* Whether the incognito mode is enabled by policy.
*/
@Override
public boolean isIncognitoModeEnabled() {
return IncognitoUtils.isIncognitoModeEnabled();
}
/**
* Sign-in completed successfully and the primary account is available in the cookie jar.
*/
......
......@@ -14,7 +14,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import android.view.View;
......@@ -114,7 +113,6 @@ public class AccountPickerBottomSheetRenderTest {
@Before
public void setUp() {
initMocks(this);
when(mAccountPickerDelegateMock.isIncognitoModeEnabled()).thenReturn(true);
mActivityTestRule.startMainActivityOnBlankPage();
}
......@@ -332,7 +330,7 @@ public class AccountPickerBottomSheetRenderTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(mActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock,
mIncognitoInterstitialDelegateMock);
mIncognitoInterstitialDelegateMock, true);
});
CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById(
R.id.account_picker_selected_account)::isShown);
......
......@@ -24,7 +24,6 @@ import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import android.view.View;
......@@ -145,7 +144,6 @@ public class AccountPickerBottomSheetTest {
@Before
public void setUp() {
initMocks(this);
when(mAccountPickerDelegateMock.isIncognitoModeEnabled()).thenReturn(true);
mAccountManagerTestRule.addAccount(PROFILE_DATA1);
mAccountManagerTestRule.addAccount(PROFILE_DATA2);
SharedPreferencesManager.getInstance().removeKey(
......@@ -202,8 +200,14 @@ public class AccountPickerBottomSheetTest {
@Test
@MediumTest
public void testExpandedSheetWithIncognitoModeDisabled() {
when(mAccountPickerDelegateMock.isIncognitoModeEnabled()).thenReturn(false);
buildAndShowExpandedBottomSheet();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(sActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock,
mIncognitoInterstitialDelegateMock, false);
});
CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById(
R.id.account_picker_selected_account)::isShown);
onView(withText(PROFILE_DATA1.getFullName())).perform(click());
onVisibleView(withText(PROFILE_DATA1.getAccountEmail())).check(matches(isDisplayed()));
onVisibleView(withText(PROFILE_DATA1.getFullName())).check(matches(isDisplayed()));
onView(withText(PROFILE_DATA2.getAccountEmail())).check(matches(isDisplayed()));
......@@ -226,7 +230,7 @@ public class AccountPickerBottomSheetTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(sActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock,
mIncognitoInterstitialDelegateMock);
mIncognitoInterstitialDelegateMock, true);
});
checkZeroAccountBottomSheet();
}
......@@ -331,7 +335,7 @@ public class AccountPickerBottomSheetTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(sActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock,
mIncognitoInterstitialDelegateMock);
mIncognitoInterstitialDelegateMock, true);
});
checkZeroAccountBottomSheet();
......@@ -695,7 +699,7 @@ public class AccountPickerBottomSheetTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(sActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock, mTabModelMock,
mTabCreatorMock, mHelpAndFeedbackLauncherMock);
mTabCreatorMock, mHelpAndFeedbackLauncherMock, true);
});
CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById(
R.id.account_picker_selected_account)::isShown);
......@@ -705,7 +709,7 @@ public class AccountPickerBottomSheetTest {
TestThreadUtils.runOnUiThreadBlocking(() -> {
mCoordinator = new AccountPickerBottomSheetCoordinator(sActivityTestRule.getActivity(),
getBottomSheetController(), mAccountPickerDelegateMock,
mIncognitoInterstitialDelegateMock);
mIncognitoInterstitialDelegateMock, true);
});
CriteriaHelper.pollUiThread(mCoordinator.getBottomSheetViewForTesting().findViewById(
R.id.account_picker_selected_account)::isShown);
......
......@@ -32,7 +32,6 @@ import org.robolectric.Robolectric;
import org.chromium.base.Callback;
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.services.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.services.SigninManager;
......@@ -117,7 +116,6 @@ public class AccountPickerDelegateTest {
@After
public void tearDown() {
IncognitoUtils.setEnabledForTesting(null);
mDelegate.onDismiss();
}
......@@ -186,12 +184,4 @@ public class AccountPickerDelegateTest {
AccountManagerTestRule.TEST_ACCOUNT_EMAIL),
mActivity, callback);
}
@Test
public void testIsIncognitoModeEnabled() {
IncognitoUtils.setEnabledForTesting(true);
Assert.assertTrue(mDelegate.isIncognitoModeEnabled());
IncognitoUtils.setEnabledForTesting(false);
Assert.assertFalse(mDelegate.isIncognitoModeEnabled());
}
}
......@@ -65,10 +65,12 @@ public class AccountPickerBottomSheetCoordinator {
public AccountPickerBottomSheetCoordinator(Activity activity,
BottomSheetController bottomSheetController,
AccountPickerDelegate accountPickerDelegate, TabModel regularTabModel,
TabCreator incognitoTabCreator, HelpAndFeedbackLauncher helpAndFeedbackLauncher) {
TabCreator incognitoTabCreator, HelpAndFeedbackLauncher helpAndFeedbackLauncher,
boolean showIncognitoRow) {
this(activity, bottomSheetController, accountPickerDelegate,
new IncognitoInterstitialDelegate(
activity, regularTabModel, incognitoTabCreator, helpAndFeedbackLauncher));
activity, regularTabModel, incognitoTabCreator, helpAndFeedbackLauncher),
showIncognitoRow);
}
/**
......@@ -80,7 +82,7 @@ public class AccountPickerBottomSheetCoordinator {
public AccountPickerBottomSheetCoordinator(Activity activity,
BottomSheetController bottomSheetController,
AccountPickerDelegate accountPickerDelegate,
IncognitoInterstitialDelegate incognitoInterstitialDelegate) {
IncognitoInterstitialDelegate incognitoInterstitialDelegate, boolean showIncognitoRow) {
SigninPreferencesManager.getInstance().incrementAccountPickerBottomSheetShownCount();
SigninMetricsUtils.logAccountConsistencyPromoAction(AccountConsistencyPromoAction.SHOWN);
SigninMetricsUtils.logAccountConsistencyPromoShownCount(
......@@ -91,13 +93,16 @@ public class AccountPickerBottomSheetCoordinator {
mView = new AccountPickerBottomSheetView(activity, mAccountPickerBottomSheetMediator);
mAccountPickerCoordinator = new AccountPickerCoordinator(mView.getAccountListView(),
mAccountPickerBottomSheetMediator, /* selectedAccountName= */ null,
/* showIncognitoRow= */ accountPickerDelegate.isIncognitoModeEnabled());
IncognitoInterstitialCoordinator incognitoInterstitialCoordinator =
new IncognitoInterstitialCoordinator(
mView.getIncognitoInterstitialView(), incognitoInterstitialDelegate, () -> {
SigninMetricsUtils.logAccountConsistencyPromoAction(
AccountConsistencyPromoAction.STARTED_INCOGNITO_SESSION);
});
/* showIncognitoRow= */ showIncognitoRow);
if (showIncognitoRow) {
IncognitoInterstitialCoordinator incognitoInterstitialCoordinator =
new IncognitoInterstitialCoordinator(mView.getIncognitoInterstitialView(),
incognitoInterstitialDelegate, () -> {
SigninMetricsUtils.logAccountConsistencyPromoAction(
AccountConsistencyPromoAction.STARTED_INCOGNITO_SESSION);
});
}
mBottomSheetController = bottomSheetController;
PropertyModelChangeProcessor.create(mAccountPickerBottomSheetMediator.getModel(), mView,
AccountPickerBottomSheetViewBinder::bind);
......
......@@ -32,9 +32,4 @@ public interface AccountPickerDelegate {
* Updates credentials of the given account name.
*/
void updateCredentials(String accountName, Callback<Boolean> onUpdateCredentialsCallback);
/**
* Whether the incognito mode is enabled by policy.
*/
boolean isIncognitoModeEnabled();
}
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