Commit 8f800c08 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android] Migrate to AccountManagerTestRule in signin integration tests

This CL migrates the usage of SigninTestUtil in signin integration
tests to AccountManagerTestRule.

Bug: 1092474
Change-Id: Ie21d8409ad9359a55919221c99adbba566cc0881
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2267317Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782958}
parent 002d1164
......@@ -26,6 +26,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import org.mockito.Mock;
......@@ -43,7 +44,7 @@ import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.BookmarkTestUtil;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ChromeSigninController;
import org.chromium.components.signin.GAIAServiceType;
import org.chromium.components.signin.identitymanager.ConsentLevel;
......@@ -64,16 +65,23 @@ public class SigninSignoutIntegrationTest {
public final SettingsActivityTestRule<AccountManagementFragment> mSettingsActivityTestRule =
new SettingsActivityTestRule<>(AccountManagementFragment.class);
private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
private final AccountManagerTestRule mAccountManagerTestRule = new AccountManagerTestRule();
// Mock sign-in environment needs to be destroyed after ChromeActivity in case there are
// observers registered in the AccountManagerFacade mock.
@Rule
public final RuleChain mRuleChain =
RuleChain.outerRule(mAccountManagerTestRule).around(mActivityTestRule);
@Rule
public final JniMocker mocker = new JniMocker();
@Mock
private SigninUtils.Natives mSigninUtilsNativeMock;
@Rule
public final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
@Mock
private SigninManager.SignInStateObserver mSignInStateObserverMock;
......@@ -85,7 +93,6 @@ public class SigninSignoutIntegrationTest {
public void setUp() {
initMocks(this);
mocker.mock(SigninUtilsJni.TEST_HOOKS, mSigninUtilsNativeMock);
SigninTestUtil.setUpAuthForTesting();
mActivityTestRule.startMainActivityOnBlankPage();
TestThreadUtils.runOnUiThreadBlocking(
() -> { mSigninManager = IdentityServicesProvider.get().getSigninManager(); });
......@@ -95,13 +102,13 @@ public class SigninSignoutIntegrationTest {
@After
public void tearDown() {
mSigninManager.removeSignInStateObserver(mSignInStateObserverMock);
SigninTestUtil.tearDownAuthForTesting();
}
@Test
@LargeTest
public void testSignIn() {
Account account = SigninTestUtil.addTestAccount();
Account account = mAccountManagerTestRule.addAccountAndWaitForSeeding(
AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncher.get().launchActivity(
......@@ -215,7 +222,8 @@ public class SigninSignoutIntegrationTest {
}
private void signIn() {
Account account = SigninTestUtil.addTestAccount();
Account account = mAccountManagerTestRule.addAccountAndWaitForSeeding(
AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
TestThreadUtils.runOnUiThreadBlocking(
() -> { mSigninManager.signIn(SigninAccessPoint.SETTINGS, account, null); });
assertSignedIn();
......
......@@ -93,7 +93,9 @@ public class FakeAccountManagerFacade implements AccountManagerFacade {
}
@Override
public void getGoogleAccounts(Callback<AccountManagerResult<List<Account>>> callback) {}
public void getGoogleAccounts(Callback<AccountManagerResult<List<Account>>> callback) {
callback.onResult(new AccountManagerResult<>(getGoogleAccounts()));
}
@Override
public boolean hasGoogleAccountAuthenticator() {
......
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