Commit 7fb8ba12 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Signin][Android] Migrate SigninManager.isSignInAllowed to use IdentityManager

Replace ChromeSigninController in SigninManager.isSignInAllowed with
IdentityManager.GetPrimaryAccountInfo(). This is safe to do, because
the native side is already loaded if SigninManager exists.

Bug: 1058981
Change-Id: I34d469463fe6d5f03ba8ce02a9efd326474b7ab9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089763Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757046}
parent bad271a7
...@@ -285,7 +285,7 @@ public class SigninManager ...@@ -285,7 +285,7 @@ public class SigninManager
*/ */
public boolean isSignInAllowed() { public boolean isSignInAllowed() {
return !mFirstRunCheckIsPending && mSignInState == null && mSigninAllowedByPolicy return !mFirstRunCheckIsPending && mSignInState == null && mSigninAllowedByPolicy
&& ChromeSigninController.get().getSignedInUser() == null && isSigninSupported(); && mIdentityManager.getPrimaryAccountInfo() == null && isSigninSupported();
} }
/** /**
......
...@@ -26,6 +26,7 @@ import org.junit.Rule; ...@@ -26,6 +26,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner; import org.chromium.base.test.BaseRobolectricTestRunner;
...@@ -242,10 +243,13 @@ public class SigninManagerTest { ...@@ -242,10 +243,13 @@ public class SigninManagerTest {
doReturn(account) doReturn(account)
.when(mIdentityManager) .when(mIdentityManager)
.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(any()); .findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(any());
// TODO(https://crbug.com/1054780): Mock getPrimaryAccountInfo instead. doReturn(null).when(mIdentityManager).getPrimaryAccountInfo();
doReturn(false).when(mIdentityManager).hasPrimaryAccount(); Answer<Boolean> setPrimaryAccountAnswer = invocation -> {
doReturn(true).when(mIdentityMutator).setPrimaryAccount(any()); // From now on getPrimaryAccountInfo should return account.
doReturn(account).when(mIdentityManager).getPrimaryAccountInfo(); doReturn(account).when(mIdentityManager).getPrimaryAccountInfo();
return true;
};
doAnswer(setPrimaryAccountAnswer).when(mIdentityMutator).setPrimaryAccount(account.getId());
doNothing().when(mIdentityMutator).reloadAllAccountsFromSystemWithPrimaryAccount(any()); doNothing().when(mIdentityMutator).reloadAllAccountsFromSystemWithPrimaryAccount(any());
mSigninManager.onFirstRunCheckDone(); // Allow sign-in. mSigninManager.onFirstRunCheckDone(); // Allow sign-in.
......
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