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

[Android][Test] Test profile data update from IdentityManager

This CL adds a test to check the profile data updata from
IdentityManager.

Bug: 1135087
Change-Id: I6b7f4d1b5a591810d754935c07f6a5f7aba5fc10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2449332Reviewed-by: default avatarTanmoy Mollik <triploblastic@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814640}
parent 2de5c134
......@@ -6,6 +6,8 @@ package org.chromium.chrome.browser.signin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
......@@ -22,6 +24,7 @@ import android.widget.ImageView;
import androidx.annotation.Px;
import androidx.test.filters.MediumTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -34,11 +37,15 @@ import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.base.AccountInfo;
import org.chromium.components.signin.base.CoreAccountId;
import org.chromium.components.signin.identitymanager.IdentityManager;
import org.chromium.components.signin.identitymanager.IdentityManagerJni;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
......@@ -73,12 +80,18 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
public ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
@Rule
public final JniMocker mocker = new JniMocker();
@Mock
private Profile mProfileMock;
@Mock
private IdentityServicesProvider mIdentityServicesProviderMock;
@Mock
private IdentityManager.Natives mIdentityManagerNativeMock;
private final IdentityManager mIdentityManager =
new IdentityManager(0 /* nativeIdentityManager */, null /* OAuth2TokenService */);
......@@ -90,10 +103,12 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
@Before
public void setUp() {
initMocks(this);
mocker.mock(IdentityManagerJni.TEST_HOOKS, mIdentityManagerNativeMock);
Profile.setLastUsedProfileForTesting(mProfileMock);
when(mIdentityServicesProviderMock.getIdentityManager(mProfileMock))
.thenReturn(mIdentityManager);
IdentityServicesProvider.setInstanceForTests(mIdentityServicesProviderMock);
TestThreadUtils.runOnUiThreadBlocking(() -> {
Activity activity = getActivity();
mContentView = new FrameLayout(activity);
......@@ -109,6 +124,34 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
});
}
@After
public void tearDown() {
IdentityServicesProvider.setInstanceForTests(null);
Profile.setLastUsedProfileForTesting(null);
}
@Test
@MediumTest
@Feature("RenderTest")
public void testProfileDataUpdatedFromIdentityManager() throws IOException {
String accountEmail = "test@example.com";
when(mIdentityManagerNativeMock
.findExtendedAccountInfoForAccountWithRefreshTokenByEmailAddress(
anyLong(), eq(accountEmail)))
.thenReturn(new AccountInfo(
new CoreAccountId("gaia-id-test"), accountEmail, "gaia-id-test", null));
TestThreadUtils.runOnUiThreadBlocking(() -> {
mProfileDataSource.setProfileData(accountEmail,
new ProfileDataSource.ProfileData(
accountEmail, null, "Full Name", "Given Name"));
});
mIdentityManager.onExtendedAccountInfoUpdated(new AccountInfo(
new CoreAccountId("gaia-id-test"), accountEmail, "gaia-id-test", createAvatar()));
TestThreadUtils.runOnUiThreadBlocking(() -> { checkImageIsScaled(accountEmail); });
mRenderTestRule.render(mImageView, "profile_data_cache_avatar" + mImageSize);
}
@Test
@MediumTest
@Feature("RenderTest")
......
......@@ -135,7 +135,8 @@ public class IdentityManager {
* Called after an account is updated.
*/
@CalledByNative
private void onExtendedAccountInfoUpdated(AccountInfo accountInfo) {
@VisibleForTesting
public void onExtendedAccountInfoUpdated(AccountInfo accountInfo) {
for (Observer observer : mObservers) {
observer.onExtendedAccountInfoUpdated(accountInfo);
}
......
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