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

[Android] Show signed in account in sync promo

Sync promo always shows the first account returned by AccountManagerFacade
which might not be signed in. This cl makes sure that the account that
is shown is the first signed in account.

This cl also refactors some of the tests regrading sync promos. The
behavior of the tests are not changed.

Bug: 1131465
Change-Id: I46f2e607494c68d3b0608543095da4b22471f710
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426485
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810545}
parent 884cd390
......@@ -19,6 +19,8 @@ import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.AccountUtils;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.identitymanager.ConsentLevel;
import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.ui.base.WindowAndroid;
......@@ -130,7 +132,17 @@ public class SigninPromoUtil {
public static void setupSyncPromoViewFromCache(SigninPromoController signinPromoController,
ProfileDataCache profileDataCache, PersonalizedSigninPromoView view,
SigninPromoController.OnDismissListener listener) {
setupSigninPromoViewFromCache(signinPromoController, profileDataCache, view, listener);
String signedInAccount = CoreAccountInfo.getEmailFrom(
IdentityServicesProvider.get()
.getIdentityManager(Profile.getLastUsedRegularProfile())
.getPrimaryAccountInfo(ConsentLevel.NOT_REQUIRED));
assert signedInAccount != null : "Sync promo should only be shown for a signed in account";
profileDataCache.update(Collections.singletonList(signedInAccount));
DisplayableProfileData profileData =
profileDataCache.getProfileDataOrDefault(signedInAccount);
signinPromoController.detach();
signinPromoController.setupPromoView(view.getContext(), view, profileData, listener);
view.getPrimaryButton().setText(R.string.sync_promo_turn_on_sync);
view.getSecondaryButton().setVisibility(View.GONE);
}
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.bookmarks;
import android.accounts.Account;
import android.view.View;
import androidx.test.filters.MediumTest;
......@@ -34,6 +35,7 @@ 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;
......@@ -47,8 +49,10 @@ 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(new FakeProfileDataSource());
new AccountManagerTestRule(mFakeProfileDataSource);
private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class);
......@@ -78,9 +82,14 @@ public class BookmarkPersonalizedPromoRenderTest {
@Before
public void setUp() {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData(
"test@gmail.com", null, "Full Name", "Given Name"));
// Native side needs to loaded before signing in test account.
mActivityTestRule.startMainActivityOnBlankPage();
Account account = mAccountManagerTestRule.addAndSignInTestAccount();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, null, "Full Name", "Given Name")));
}
@After
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.ntp;
import android.accounts.Account;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
......@@ -53,9 +54,11 @@ 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(new FakeProfileDataSource());
new AccountManagerTestRule(mFakeProfileDataSource);
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
......@@ -105,8 +108,12 @@ public class RecentTabsPageTest {
@LargeTest
@Feature("RenderTest")
public void testPersonalizedSigninPromoInRecentTabsPage() throws Exception {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData(
"test@gmail.com", createAvatar(), "Full Name", "Given Name"));
Account account = mAccountManagerTestRule.addAndSignInTestAccount();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, createAvatar(), "Full Name", "Given Name")));
RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED);
mPage = loadRecentTabsPage();
......@@ -117,8 +124,12 @@ public class RecentTabsPageTest {
@LargeTest
@Feature("RenderTest")
public void testPersonalizedSyncPromoInRecentTabsPage() throws Exception {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData(
"test@gmail.com", createAvatar(), "Full Name", "Given Name"));
Account account = mAccountManagerTestRule.addAndSignInTestAccount();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, createAvatar(), "Full Name", "Given Name")));
RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SYNC_PERSONALIZED);
mPage = loadRecentTabsPage();
......
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