Commit 76c8ca54 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Test] Refactor AccountPickerDelegateTest

This CL refactors AccountPickerDelegateTest by moving some common part
to the test setup.

Bug: 1121536
Change-Id: I758ed411a0e9e91129e917d214a3ad4e0afb3e38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444313Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813260}
parent e16cd9fc
......@@ -93,6 +93,8 @@ public class AccountPickerDelegateTest {
private AccountPickerDelegate mDelegate;
private CoreAccountInfo mCoreAccountInfo;
@Before
public void setUp() {
initMocks(this);
......@@ -105,6 +107,10 @@ public class AccountPickerDelegateTest {
.thenReturn(mIdentityManagerMock);
when(IdentityServicesProvider.get().getSigninManager(any())).thenReturn(mSigninManagerMock);
Account account =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
mCoreAccountInfo = mAccountManagerTestRule.toCoreAccountInfo(account.name);
mDelegate = new AccountPickerDelegate(
mWindowAndroidMock, mTabMock, mWebSigninBridgeFactoryMock, CONTINUE_URL);
when(mWebSigninBridgeFactoryMock.create(eq(mProfileMock), any(), eq(mDelegate)))
......@@ -118,14 +124,11 @@ public class AccountPickerDelegateTest {
@Test
public void testSignInSucceeded() {
Account account =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CoreAccountInfo coreAccountInfo = mAccountManagerTestRule.toCoreAccountInfo(account.name);
mDelegate.signIn(coreAccountInfo, error -> {});
mDelegate.signIn(mCoreAccountInfo, error -> {});
InOrder calledInOrder = inOrder(mWebSigninBridgeFactoryMock, mSigninManagerMock);
calledInOrder.verify(mWebSigninBridgeFactoryMock)
.create(mProfileMock, coreAccountInfo, mDelegate);
calledInOrder.verify(mSigninManagerMock).signin(eq(coreAccountInfo), any());
.create(mProfileMock, mCoreAccountInfo, mDelegate);
calledInOrder.verify(mSigninManagerMock).signin(eq(mCoreAccountInfo), any());
mDelegate.onSigninSucceeded();
verify(mTabMock).loadUrl(mLoadUrlParamsCaptor.capture());
LoadUrlParams loadUrlParams = mLoadUrlParamsCaptor.getValue();
......@@ -134,17 +137,14 @@ public class AccountPickerDelegateTest {
@Test
public void testSignInAborted() {
Account account =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CoreAccountInfo coreAccountInfo = mAccountManagerTestRule.toCoreAccountInfo(account.name);
doAnswer(invocation -> {
SigninManager.SignInCallback callback = invocation.getArgument(1);
callback.onSignInAborted();
return null;
})
.when(mSigninManagerMock)
.signin(eq(coreAccountInfo), any());
mDelegate.signIn(coreAccountInfo, error -> {});
.signin(eq(mCoreAccountInfo), any());
mDelegate.signIn(mCoreAccountInfo, error -> {});
verify(mWebSigninBridgeMock).destroy();
}
......@@ -153,30 +153,24 @@ public class AccountPickerDelegateTest {
// In case an error is fired because cookies are taking longer to generate than usual,
// if user retries the sign-in from the error screen, we need to sign out the user
// first before signing in again.
Account account =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CoreAccountInfo coreAccountInfo = mAccountManagerTestRule.toCoreAccountInfo(account.name);
mDelegate.signIn(coreAccountInfo, error -> {});
when(mIdentityManagerMock.getPrimaryAccountInfo(anyInt())).thenReturn(coreAccountInfo);
mDelegate.signIn(mCoreAccountInfo, error -> {});
when(mIdentityManagerMock.getPrimaryAccountInfo(anyInt())).thenReturn(mCoreAccountInfo);
mDelegate.signIn(coreAccountInfo, error -> {});
mDelegate.signIn(mCoreAccountInfo, error -> {});
InOrder calledInOrder = inOrder(mWebSigninBridgeMock, mSigninManagerMock,
mWebSigninBridgeFactoryMock, mSigninManagerMock);
calledInOrder.verify(mWebSigninBridgeMock).destroy();
calledInOrder.verify(mSigninManagerMock).signOut(anyInt());
calledInOrder.verify(mWebSigninBridgeFactoryMock)
.create(mProfileMock, coreAccountInfo, mDelegate);
calledInOrder.verify(mSigninManagerMock).signin(eq(coreAccountInfo), any());
.create(mProfileMock, mCoreAccountInfo, mDelegate);
calledInOrder.verify(mSigninManagerMock).signin(eq(mCoreAccountInfo), any());
}
@Test
public void testSignInFailedWithConnectionError() {
Account account =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CoreAccountInfo coreAccountInfo = mAccountManagerTestRule.toCoreAccountInfo(account.name);
Callback<GoogleServiceAuthError> mockCallback = mock(Callback.class);
GoogleServiceAuthError error = new GoogleServiceAuthError(State.CONNECTION_FAILED);
mDelegate.signIn(coreAccountInfo, mockCallback);
mDelegate.signIn(mCoreAccountInfo, mockCallback);
mDelegate.onSigninFailed(error);
verify(mockCallback).onResult(error);
// WebSigninBridge should be kept alive in case cookies are taking longer to
......
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