Commit a8ab82e7 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Android][Test] Test IdentityDisc shows on NTP when sign-in not sync

This CL adds a test to check that IdentityDisc shows on NTP when user
is signed in but not sync.

Bug: 1132238
Change-Id: Ib68be2ea5198bc7cbcca76761d2e4dc9c40b4201
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431924
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812040}
parent ee7d8be9
......@@ -240,7 +240,12 @@ public class IdentityDiscController implements NativeInitObserver, ProfileDataCa
}
}
// IdentityManager.Observer implementation.
/**
* Implements {@link IdentityManager.Observer}.
*
* TODO(https://crbug.com/1132291): This method only observes sign-in with sync, we should also
* observe sign-in without sync.
*/
@Override
public void onPrimaryAccountSet(CoreAccountInfo account) {
resetIdentityDiscCache();
......
......@@ -41,6 +41,7 @@ import org.chromium.chrome.test.util.NewTabPageTestUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.ContentUrlConstants;
/**
......@@ -87,7 +88,35 @@ public class IdentityDiscControllerTest {
@Test
@MediumTest
public void testIdentityDiscWithSignInState() {
@Features.EnableFeatures(ChromeFeatureList.MOBILE_IDENTITY_CONSISTENCY)
public void testIdentityDiscWithSignin() {
// When user is signed out, Identity Disc should not be visible on the NTP.
onView(withId(R.id.optional_toolbar_button)).check((view, noViewException) -> {
if (view != null) {
ViewMatchers.assertThat("IdentityDisc view should be gone if it exists",
view.getVisibility(), Matchers.is(View.GONE));
}
});
// Identity Disc should be shown on sign-in state change with a NTP refresh.
mAccountManagerTestRule.addTestAccountThenSignin();
// TODO(https://crbug.com/1132291): Remove the reload once the sign-in without sync observer
// is implemented.
TestThreadUtils.runOnUiThreadBlocking(mTab::reload);
waitForView(allOf(withId(R.id.optional_toolbar_button), isDisplayed()));
onView(withId(R.id.optional_toolbar_button))
.check(matches(
withContentDescription(R.string.accessibility_toolbar_btn_identity_disc)));
mAccountManagerTestRule.signOut();
waitForView(allOf(withId(R.id.optional_toolbar_button),
withEffectiveVisibility(ViewMatchers.Visibility.GONE)));
}
@Test
@MediumTest
public void testIdentityDiscWithSigninAndEnableSync() {
// When user is signed out, Identity Disc should not be visible on the NTP.
onView(withId(R.id.optional_toolbar_button)).check((view, noViewException) -> {
if (view != null) {
......
......@@ -142,6 +142,20 @@ public class AccountManagerTestRule implements TestRule {
waitForSeeding();
}
/**
* Add and sign in an account with the default name.
*
* This method does not enable sync.
*/
public CoreAccountInfo addTestAccountThenSignin() {
assert !mIsSignedIn : "An account is already signed in!";
Account account = addAccountAndWaitForSeeding(TEST_ACCOUNT_EMAIL);
CoreAccountInfo coreAccountInfo = toCoreAccountInfo(account.name);
SigninTestUtil.signin(coreAccountInfo);
mIsSignedIn = true;
return coreAccountInfo;
}
/**
* Add and sign in an account with the default name.
*
......
......@@ -42,6 +42,40 @@ public final class SigninTestUtil {
});
}
/**
* Signs the user into the given account.
*/
static void signin(CoreAccountInfo coreAccountInfo) {
CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> {
SigninManager signinManager = IdentityServicesProvider.get().getSigninManager(
Profile.getLastUsedRegularProfile());
signinManager.onFirstRunCheckDone(); // Allow sign-in
signinManager.signin(coreAccountInfo, new SigninManager.SignInCallback() {
@Override
public void onSignInComplete() {
callbackHelper.notifyCalled();
}
@Override
public void onSignInAborted() {
Assert.fail("Sign-in was aborted");
}
});
});
try {
callbackHelper.waitForFirst();
} catch (TimeoutException e) {
throw new RuntimeException("Timed out waiting for callback", e);
}
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals(coreAccountInfo,
IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.NOT_REQUIRED));
});
}
/**
* Signs into an account and enables the sync if given a {@link ProfileSyncService} object.
*
......
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