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; ...@@ -26,6 +26,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
...@@ -43,7 +44,7 @@ import org.chromium.chrome.test.ChromeActivityTestRule; ...@@ -43,7 +44,7 @@ import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.BookmarkTestUtil; 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.ChromeSigninController;
import org.chromium.components.signin.GAIAServiceType; import org.chromium.components.signin.GAIAServiceType;
import org.chromium.components.signin.identitymanager.ConsentLevel; import org.chromium.components.signin.identitymanager.ConsentLevel;
...@@ -64,16 +65,23 @@ public class SigninSignoutIntegrationTest { ...@@ -64,16 +65,23 @@ public class SigninSignoutIntegrationTest {
public final SettingsActivityTestRule<AccountManagementFragment> mSettingsActivityTestRule = public final SettingsActivityTestRule<AccountManagementFragment> mSettingsActivityTestRule =
new SettingsActivityTestRule<>(AccountManagementFragment.class); 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 @Rule
public final JniMocker mocker = new JniMocker(); public final JniMocker mocker = new JniMocker();
@Mock @Mock
private SigninUtils.Natives mSigninUtilsNativeMock; private SigninUtils.Natives mSigninUtilsNativeMock;
@Rule
public final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
@Mock @Mock
private SigninManager.SignInStateObserver mSignInStateObserverMock; private SigninManager.SignInStateObserver mSignInStateObserverMock;
...@@ -85,7 +93,6 @@ public class SigninSignoutIntegrationTest { ...@@ -85,7 +93,6 @@ public class SigninSignoutIntegrationTest {
public void setUp() { public void setUp() {
initMocks(this); initMocks(this);
mocker.mock(SigninUtilsJni.TEST_HOOKS, mSigninUtilsNativeMock); mocker.mock(SigninUtilsJni.TEST_HOOKS, mSigninUtilsNativeMock);
SigninTestUtil.setUpAuthForTesting();
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> { mSigninManager = IdentityServicesProvider.get().getSigninManager(); }); () -> { mSigninManager = IdentityServicesProvider.get().getSigninManager(); });
...@@ -95,13 +102,13 @@ public class SigninSignoutIntegrationTest { ...@@ -95,13 +102,13 @@ public class SigninSignoutIntegrationTest {
@After @After
public void tearDown() { public void tearDown() {
mSigninManager.removeSignInStateObserver(mSignInStateObserverMock); mSigninManager.removeSignInStateObserver(mSignInStateObserverMock);
SigninTestUtil.tearDownAuthForTesting();
} }
@Test @Test
@LargeTest @LargeTest
public void testSignIn() { public void testSignIn() {
Account account = SigninTestUtil.addTestAccount(); Account account = mAccountManagerTestRule.addAccountAndWaitForSeeding(
AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
ActivityUtils.waitForActivity( ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncher.get().launchActivity( SigninActivityLauncher.get().launchActivity(
...@@ -215,7 +222,8 @@ public class SigninSignoutIntegrationTest { ...@@ -215,7 +222,8 @@ public class SigninSignoutIntegrationTest {
} }
private void signIn() { private void signIn() {
Account account = SigninTestUtil.addTestAccount(); Account account = mAccountManagerTestRule.addAccountAndWaitForSeeding(
AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> { mSigninManager.signIn(SigninAccessPoint.SETTINGS, account, null); }); () -> { mSigninManager.signIn(SigninAccessPoint.SETTINGS, account, null); });
assertSignedIn(); assertSignedIn();
......
...@@ -93,7 +93,9 @@ public class FakeAccountManagerFacade implements AccountManagerFacade { ...@@ -93,7 +93,9 @@ public class FakeAccountManagerFacade implements AccountManagerFacade {
} }
@Override @Override
public void getGoogleAccounts(Callback<AccountManagerResult<List<Account>>> callback) {} public void getGoogleAccounts(Callback<AccountManagerResult<List<Account>>> callback) {
callback.onResult(new AccountManagerResult<>(getGoogleAccounts()));
}
@Override @Override
public boolean hasGoogleAccountAuthenticator() { 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