Commit a12e370a authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

[Android] Add ProfileData when adding accounts in AccountManagerTestRule

If AccountManagerTestRule is initialized with a FakeProfileDataSource
then it should add profileData objects when adding accounts.

Bug: 1136470
Change-Id: I015389190e93725875601c926658ed4a207301df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2455986Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817511}
parent 97a3e0a4
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.bookmarks;
import android.accounts.Account;
import android.view.View;
import androidx.test.filters.MediumTest;
......@@ -33,9 +32,7 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.BookmarkTestRule;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.NightModeTestUtils;
import org.chromium.ui.test.util.UiDisableIf;
......@@ -49,10 +46,8 @@ import org.chromium.ui.test.util.UiDisableIf;
public class BookmarkPersonalizedPromoRenderTest {
// FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge
// for Sync promo.
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
private final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(mFakeProfileDataSource);
new AccountManagerTestRule(new FakeProfileDataSource());
private final ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule();
......@@ -67,7 +62,7 @@ public class BookmarkPersonalizedPromoRenderTest {
@Rule
public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
ChromeRenderTestRule.Builder.withPublicCorpus().setRevision(2).build();
@ParameterAnnotations.UseMethodParameterBefore(NightModeTestUtils.NightModeParams.class)
public void setupNightMode(boolean nightModeEnabled) {
......@@ -84,13 +79,7 @@ public class BookmarkPersonalizedPromoRenderTest {
public void setUp() {
// Native side needs to loaded before signing in test account.
mActivityTestRule.startMainActivityOnBlankPage();
Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(account.name,
mAccountManagerTestRule.createProfileImage(), "Full Name",
"Given Name")));
mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
}
@After
......
......@@ -29,7 +29,6 @@ import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.RecentTabsPageTestUtils;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
......@@ -49,18 +48,16 @@ import java.util.concurrent.ExecutionException;
public class RecentTabsPageTest {
// FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge
// for Sync promo.
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(mFakeProfileDataSource);
new AccountManagerTestRule(new FakeProfileDataSource());
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
ChromeRenderTestRule.Builder.withPublicCorpus().setRevision(2).build();
private FakeRecentlyClosedTabManager mManager;
private Tab mTab;
......@@ -104,12 +101,6 @@ public class RecentTabsPageTest {
@Feature("RenderTest")
public void testPersonalizedSigninPromoInRecentTabsPage() throws Exception {
Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(account.name,
mAccountManagerTestRule.createProfileImage(), "Full Name",
"Given Name")));
RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED);
mPage = loadRecentTabsPage();
......@@ -121,12 +112,6 @@ public class RecentTabsPageTest {
@Feature("RenderTest")
public void testPersonalizedSyncPromoInRecentTabsPage() throws Exception {
Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(account.name,
mAccountManagerTestRule.createProfileImage(), "Full Name",
"Given Name")));
RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SYNC_PERSONALIZED);
mPage = loadRecentTabsPage();
......
......@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.sync;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import android.accounts.Account;
import android.view.View;
import androidx.test.filters.LargeTest;
......@@ -38,8 +37,6 @@ import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.AccountUtils;
import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.base.GoogleServiceAuthError;
import org.chromium.components.signin.test.util.FakeProfileDataSource;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -55,11 +52,9 @@ import org.chromium.ui.test.util.NightModeTestUtils;
public class SyncErrorCardPreferenceTest {
// FakeProfileDataSource is required to create the ProfileDataCache entry with sync_error badge
// for Sync error card.
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
@Rule
public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(mFakeProfileDataSource);
new AccountManagerTestRule(new FakeProfileDataSource());
@Rule
public final ChromeTabbedActivityTestRule mActivityTestRule =
......@@ -71,7 +66,7 @@ public class SyncErrorCardPreferenceTest {
@Rule
public final ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();
ChromeRenderTestRule.Builder.withPublicCorpus().setRevision(2).build();
@Mock
private AndroidSyncSettings mAndroidSyncSettingsMock;
......@@ -96,15 +91,9 @@ public class SyncErrorCardPreferenceTest {
// ProfileSyncService.
mActivityTestRule.startMainActivityOnBlankPage();
Account account =
AccountUtils.createAccountFromName(AccountManagerTestRule.TEST_ACCOUNT_EMAIL);
TestThreadUtils.runOnUiThreadBlocking(() -> {
mFakeProfileSyncService = new FakeProfileSyncService();
ProfileSyncService.overrideForTests(mFakeProfileSyncService);
mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(account.name,
mAccountManagerTestRule.createProfileImage(), "Full Name",
"Given Name"));
AndroidSyncSettings.overrideForTests(mAndroidSyncSettingsMock);
when(mAndroidSyncSettingsMock.isChromeSyncEnabled()).thenReturn(true);
});
......@@ -114,7 +103,6 @@ public class SyncErrorCardPreferenceTest {
public void tearDown() {
TestThreadUtils.runOnUiThreadBlocking(() -> {
ProfileSyncService.resetForTests();
mFakeProfileDataSource.setProfileData(AccountManagerTestRule.TEST_ACCOUNT_EMAIL, null);
});
}
......
......@@ -128,12 +128,15 @@ public class AccountManagerTestRule implements TestRule {
}
/**
* Adds an account and seed it in native code.
* Adds an account and seed it in native code. Will create a ProfileData entry for the account
* if ProfileDataSource is not null.
*
* This method invokes native code. It shouldn't be called in a Robolectric test.
*/
public Account addAccountAndWaitForSeeding(String accountName) {
Account account = addAccount(accountName);
Account account = mFakeAccountManagerFacade.getProfileDataSource() == null
? addAccount(accountName)
: addAccount(createProfileDataFromName(accountName));
waitForSeeding();
return account;
}
......@@ -190,6 +193,17 @@ public class AccountManagerTestRule implements TestRule {
return account;
}
/**
* Creates ProfileData object from accountName.
*/
public ProfileDataSource.ProfileData createProfileDataFromName(String accountName) {
String email = accountName.split("@", 2)[0];
String givenName = email + ".given";
String fullName = email + ".full";
return new ProfileDataSource.ProfileData(
accountName, createProfileImage(), fullName, givenName);
}
/**
* Returns the currently signed in account.
*
......
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