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

[Signin][Test] Use AccountManagerTestRule instead of SyncTestRule in signin tests

This CL uses AccountManagerTestRule instead of SyncTestRule in
SigninFragmentTest to facilitate ProfileDataCache update tests in the
future.

Bug: 1167672
Change-Id: If3d8753b5a894a76b9db2d961aaa336306b717ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2632678
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845742}
parent 5148848a
...@@ -46,6 +46,7 @@ import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDialogF ...@@ -46,6 +46,7 @@ import org.chromium.chrome.browser.signin.ui.account_picker.AccountPickerDialogF
import org.chromium.chrome.browser.sync.SyncUserDataWiper; import org.chromium.chrome.browser.sync.SyncUserDataWiper;
import org.chromium.components.externalauth.UserRecoverableErrorHandler; import org.chromium.components.externalauth.UserRecoverableErrorHandler;
import org.chromium.components.signin.AccountManagerDelegateException; import org.chromium.components.signin.AccountManagerDelegateException;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.AccountManagerFacadeProvider; import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.AccountManagerResult; import org.chromium.components.signin.AccountManagerResult;
import org.chromium.components.signin.AccountTrackerService; import org.chromium.components.signin.AccountTrackerService;
...@@ -95,6 +96,7 @@ public abstract class SigninFragmentBase ...@@ -95,6 +96,7 @@ public abstract class SigninFragmentBase
int ADD_ACCOUNT = 3; int ADD_ACCOUNT = 3;
} }
private final AccountManagerFacade mAccountManagerFacade;
private @SigninFlowType int mSigninFlowType; private @SigninFlowType int mSigninFlowType;
private @ChildAccountStatus.Status int mChildAccountStatus; private @ChildAccountStatus.Status int mChildAccountStatus;
...@@ -170,6 +172,7 @@ public abstract class SigninFragmentBase ...@@ -170,6 +172,7 @@ public abstract class SigninFragmentBase
} }
protected SigninFragmentBase() { protected SigninFragmentBase() {
mAccountManagerFacade = AccountManagerFacadeProvider.getInstance();
mAccountsChangedObserver = this::triggerUpdateAccounts; mAccountsChangedObserver = this::triggerUpdateAccounts;
mProfileDataCacheObserver = this::updateProfileData; mProfileDataCacheObserver = this::updateProfileData;
} }
...@@ -472,8 +475,7 @@ public abstract class SigninFragmentBase ...@@ -472,8 +475,7 @@ public abstract class SigninFragmentBase
new AsyncTask<String>() { new AsyncTask<String>() {
@Override @Override
public String doInBackground() { public String doInBackground() {
return AccountManagerFacadeProvider.getInstance().getAccountGaiaId( return mAccountManagerFacade.getAccountGaiaId(mSelectedAccountName);
mSelectedAccountName);
} }
@Override @Override
...@@ -512,17 +514,16 @@ public abstract class SigninFragmentBase ...@@ -512,17 +514,16 @@ public abstract class SigninFragmentBase
public void addAccount() { public void addAccount() {
RecordUserAction.record("Signin_AddAccountToDevice"); RecordUserAction.record("Signin_AddAccountToDevice");
// TODO(https://crbug.com/842860): Revise createAddAccountIntent and AccountAdder. // TODO(https://crbug.com/842860): Revise createAddAccountIntent and AccountAdder.
AccountManagerFacadeProvider.getInstance().createAddAccountIntent( mAccountManagerFacade.createAddAccountIntent((@Nullable Intent intent) -> {
(@Nullable Intent intent) -> { if (intent != null) {
if (intent != null) { startActivityForResult(intent, ADD_ACCOUNT_REQUEST_CODE);
startActivityForResult(intent, ADD_ACCOUNT_REQUEST_CODE); return;
return; }
}
// AccountManagerFacade couldn't create intent, use SigninUtils to open settings // AccountManagerFacade couldn't create intent, use SigninUtils to open settings
// instead. // instead.
SigninUtils.openSettingsForAllAccounts(getActivity()); SigninUtils.openSettingsForAllAccounts(getActivity());
}); });
} }
@Override @Override
...@@ -539,7 +540,7 @@ public abstract class SigninFragmentBase ...@@ -539,7 +540,7 @@ public abstract class SigninFragmentBase
} }
// Wait for the account cache to be updated and select newly-added account. // Wait for the account cache to be updated and select newly-added account.
AccountManagerFacadeProvider.getInstance().waitForPendingUpdates(() -> { mAccountManagerFacade.waitForPendingUpdates(() -> {
mAccountSelectionPending = true; mAccountSelectionPending = true;
mRequestedAccountName = addedAccountName; mRequestedAccountName = addedAccountName;
triggerUpdateAccounts(); triggerUpdateAccounts();
...@@ -551,7 +552,7 @@ public abstract class SigninFragmentBase ...@@ -551,7 +552,7 @@ public abstract class SigninFragmentBase
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mResumed = true; mResumed = true;
AccountManagerFacadeProvider.getInstance().addObserver(mAccountsChangedObserver); mAccountManagerFacade.addObserver(mAccountsChangedObserver);
mProfileDataCache.addObserver(mProfileDataCacheObserver); mProfileDataCache.addObserver(mProfileDataCacheObserver);
triggerUpdateAccounts(); triggerUpdateAccounts();
...@@ -563,7 +564,7 @@ public abstract class SigninFragmentBase ...@@ -563,7 +564,7 @@ public abstract class SigninFragmentBase
super.onPause(); super.onPause();
mResumed = false; mResumed = false;
mProfileDataCache.removeObserver(mProfileDataCacheObserver); mProfileDataCache.removeObserver(mProfileDataCacheObserver);
AccountManagerFacadeProvider.getInstance().removeObserver(mAccountsChangedObserver); mAccountManagerFacade.removeObserver(mAccountsChangedObserver);
mView.stopAnimations(); mView.stopAnimations();
} }
...@@ -581,7 +582,7 @@ public abstract class SigninFragmentBase ...@@ -581,7 +582,7 @@ public abstract class SigninFragmentBase
} }
private void triggerUpdateAccounts() { private void triggerUpdateAccounts() {
AccountManagerFacadeProvider.getInstance().getGoogleAccounts(this::updateAccounts); mAccountManagerFacade.getGoogleAccounts(this::updateAccounts);
} }
private void updateAccounts(AccountManagerResult<List<Account>> accounts) { private void updateAccounts(AccountManagerResult<List<Account>> accounts) {
......
...@@ -31,6 +31,7 @@ import androidx.test.filters.MediumTest; ...@@ -31,6 +31,7 @@ import androidx.test.filters.MediumTest;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -52,14 +53,16 @@ import org.chromium.chrome.browser.flags.ChromeSwitches; ...@@ -52,14 +53,16 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider; import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
import org.chromium.chrome.browser.sync.ProfileSyncService; import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.sync.SyncTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ActivityUtils; import org.chromium.chrome.test.util.ActivityUtils;
import org.chromium.chrome.test.util.ChromeRenderTestRule; import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.chrome.test.util.browser.sync.SyncTestUtil; import org.chromium.chrome.test.util.browser.sync.SyncTestUtil;
import org.chromium.components.signin.ChildAccountStatus; import org.chromium.components.signin.ChildAccountStatus;
import org.chromium.components.signin.base.CoreAccountInfo; import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.DisableAnimationsTestRule; import org.chromium.ui.test.util.DisableAnimationsTestRule;
import org.chromium.ui.test.util.DummyUiActivity; import org.chromium.ui.test.util.DummyUiActivity;
...@@ -95,7 +98,12 @@ public class SigninFragmentTest { ...@@ -95,7 +98,12 @@ public class SigninFragmentTest {
public final MockitoRule mMockitoRule = MockitoJUnit.rule(); public final MockitoRule mMockitoRule = MockitoJUnit.rule();
@Rule @Rule
public final SyncTestRule mSyncTestRule = new SyncTestRule(); public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource());
@Rule
public final ChromeTabbedActivityTestRule mChromeActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule @Rule
public final BaseActivityTestRule<DummyUiActivity> mActivityTestRule = public final BaseActivityTestRule<DummyUiActivity> mActivityTestRule =
...@@ -110,6 +118,12 @@ public class SigninFragmentTest { ...@@ -110,6 +118,12 @@ public class SigninFragmentTest {
private SigninActivity mSigninActivity; private SigninActivity mSigninActivity;
@Before
public void setUp() {
mActivityTestRule.setFinishActivity(true);
mChromeActivityTestRule.startMainActivityOnBlankPage();
}
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
// Since SigninActivity is launched inside this test class, we need to // Since SigninActivity is launched inside this test class, we need to
...@@ -126,7 +140,8 @@ public class SigninFragmentTest { ...@@ -126,7 +140,8 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoAddAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoAddAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER); mChromeActivityTestRule.getActivity(),
SigninAccessPoint.BOOKMARK_MANAGER);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_new_account"); "signin_fragment_new_account");
...@@ -136,13 +151,14 @@ public class SigninFragmentTest { ...@@ -136,13 +151,14 @@ public class SigninFragmentTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testSigninFragmentNotDefaultAccountWithPrimaryAccount() throws IOException { public void testSigninFragmentNotDefaultAccountWithPrimaryAccount() throws IOException {
CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo =
mSyncTestRule.addAccount("test.second.account@gmail.com"); mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
mAccountManagerTestRule.addAccount("test.second.account@gmail.com");
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mChromeActivityTestRule.getActivity(),
accountInfo.getEmail()); SigninAccessPoint.BOOKMARK_MANAGER, accountInfo.getEmail());
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_choose_primary_account"); "signin_fragment_choose_primary_account");
...@@ -152,14 +168,14 @@ public class SigninFragmentTest { ...@@ -152,14 +168,14 @@ public class SigninFragmentTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testSigninFragmentNotDefaultAccountWithSecondaryAccount() throws IOException { public void testSigninFragmentNotDefaultAccountWithSecondaryAccount() throws IOException {
mSyncTestRule.addTestAccount(); mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
String secondAccountName = "test.second.account@gmail.com"; String secondAccountName = "test.second.account@gmail.com";
mSyncTestRule.addAccount(secondAccountName); mAccountManagerTestRule.addAccount(secondAccountName);
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow( SigninActivityLauncherImpl.get().launchActivityForPromoChooseAccountFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mChromeActivityTestRule.getActivity(),
secondAccountName); SigninAccessPoint.BOOKMARK_MANAGER, secondAccountName);
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_choose_secondary_account"); "signin_fragment_choose_secondary_account");
...@@ -169,12 +185,13 @@ public class SigninFragmentTest { ...@@ -169,12 +185,13 @@ public class SigninFragmentTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testSigninFragmentDefaultAccount() throws IOException { public void testSigninFragmentDefaultAccount() throws IOException {
CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mChromeActivityTestRule.getActivity(),
accountInfo.getEmail()); SigninAccessPoint.BOOKMARK_MANAGER, accountInfo.getEmail());
}); });
mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container), mRenderTestRule.render(mSigninActivity.findViewById(R.id.fragment_container),
"signin_fragment_default_account"); "signin_fragment_default_account");
...@@ -217,7 +234,7 @@ public class SigninFragmentTest { ...@@ -217,7 +234,7 @@ public class SigninFragmentTest {
new HistogramDelta("Signin.AndroidDeviceAccountsNumberWhenEnteringFRE", 1); new HistogramDelta("Signin.AndroidDeviceAccountsNumberWhenEnteringFRE", 1);
HistogramDelta startPageHistogram = HistogramDelta startPageHistogram =
new HistogramDelta("Signin.SigninStartedAccessPoint", SigninAccessPoint.START_PAGE); new HistogramDelta("Signin.SigninStartedAccessPoint", SigninAccessPoint.START_PAGE);
mSyncTestRule.addTestAccount(); mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CustomSigninFirstRunFragment fragment = new CustomSigninFirstRunFragment(); CustomSigninFirstRunFragment fragment = new CustomSigninFirstRunFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(SigninFirstRunFragment.CHILD_ACCOUNT_STATUS, ChildAccountStatus.NOT_CHILD); bundle.putInt(SigninFirstRunFragment.CHILD_ACCOUNT_STATUS, ChildAccountStatus.NOT_CHILD);
...@@ -247,7 +264,7 @@ public class SigninFragmentTest { ...@@ -247,7 +264,7 @@ public class SigninFragmentTest {
new HistogramDelta("Signin.AndroidDeviceAccountsNumberWhenEnteringFRE", 1); new HistogramDelta("Signin.AndroidDeviceAccountsNumberWhenEnteringFRE", 1);
HistogramDelta startPageHistogram = HistogramDelta startPageHistogram =
new HistogramDelta("Signin.SigninStartedAccessPoint", SigninAccessPoint.START_PAGE); new HistogramDelta("Signin.SigninStartedAccessPoint", SigninAccessPoint.START_PAGE);
mSyncTestRule.addTestAccount(); mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
CustomSigninFirstRunFragment fragment = new CustomSigninFirstRunFragment(); CustomSigninFirstRunFragment fragment = new CustomSigninFirstRunFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt( bundle.putInt(
...@@ -273,11 +290,12 @@ public class SigninFragmentTest { ...@@ -273,11 +290,12 @@ public class SigninFragmentTest {
@Test @Test
@LargeTest @LargeTest
public void testClickingSettingsDoesNotSetFirstSetupComplete() { public void testClickingSettingsDoesNotSetFirstSetupComplete() {
CoreAccountInfo accountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo accountInfo =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.SETTINGS, mChromeActivityTestRule.getActivity(), SigninAccessPoint.SETTINGS,
accountInfo.getEmail()); accountInfo.getEmail());
}); });
onView(withText(accountInfo.getEmail())).check(matches(isDisplayed())); onView(withText(accountInfo.getEmail())).check(matches(isDisplayed()));
...@@ -304,7 +322,7 @@ public class SigninFragmentTest { ...@@ -304,7 +322,7 @@ public class SigninFragmentTest {
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivity( SigninActivityLauncherImpl.get().launchActivity(
mSyncTestRule.getActivity(), SigninAccessPoint.SETTINGS); mChromeActivityTestRule.getActivity(), SigninAccessPoint.SETTINGS);
}); });
onView(withId(R.id.positive_button)).check(matches(withText(R.string.signin_add_account))); onView(withId(R.id.positive_button)).check(matches(withText(R.string.signin_add_account)));
onView(withId(R.id.negative_button)).check(matches(withText(R.string.cancel))); onView(withId(R.id.negative_button)).check(matches(withText(R.string.cancel)));
...@@ -316,14 +334,15 @@ public class SigninFragmentTest { ...@@ -316,14 +334,15 @@ public class SigninFragmentTest {
public void testSelectNonDefaultAccountInAccountPickerDialog() { public void testSelectNonDefaultAccountInAccountPickerDialog() {
HistogramDelta bookmarkHistogram = new HistogramDelta( HistogramDelta bookmarkHistogram = new HistogramDelta(
"Signin.SigninStartedAccessPoint", SigninAccessPoint.BOOKMARK_MANAGER); "Signin.SigninStartedAccessPoint", SigninAccessPoint.BOOKMARK_MANAGER);
CoreAccountInfo defaultAccountInfo = mSyncTestRule.addTestAccount(); CoreAccountInfo defaultAccountInfo =
mAccountManagerTestRule.addAccount(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
String nonDefaultAccountName = "test.account.nondefault@gmail.com"; String nonDefaultAccountName = "test.account.nondefault@gmail.com";
mSyncTestRule.addAccount(nonDefaultAccountName); mAccountManagerTestRule.addAccount(nonDefaultAccountName);
mSigninActivity = ActivityUtils.waitForActivity( mSigninActivity = ActivityUtils.waitForActivity(
InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> { InstrumentationRegistry.getInstrumentation(), SigninActivity.class, () -> {
SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow( SigninActivityLauncherImpl.get().launchActivityForPromoDefaultFlow(
mSyncTestRule.getActivity(), SigninAccessPoint.BOOKMARK_MANAGER, mChromeActivityTestRule.getActivity(),
defaultAccountInfo.getEmail()); SigninAccessPoint.BOOKMARK_MANAGER, defaultAccountInfo.getEmail());
}); });
onView(withText(defaultAccountInfo.getEmail())) onView(withText(defaultAccountInfo.getEmail()))
.check(matches(isDisplayed())) .check(matches(isDisplayed()))
......
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