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

Reland "[Android] Show signed in account in sync promo"

This is a reland of adc862b0

Original change's description:
> [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: Alice Wang <aliceywang@chromium.org>
> Reviewed-by: Marc Treib <treib@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#810545}

Bug: 1131465
Change-Id: I26bfac6b772f37371c1953af8bbefacbf66364ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435104Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811157}
parent e1cc7c73
...@@ -19,6 +19,8 @@ import org.chromium.chrome.browser.preferences.Pref; ...@@ -19,6 +19,8 @@ import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.signin.AccountManagerFacadeProvider; import org.chromium.components.signin.AccountManagerFacadeProvider;
import org.chromium.components.signin.AccountUtils; 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.signin.metrics.SigninAccessPoint;
import org.chromium.components.user_prefs.UserPrefs; import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -130,7 +132,17 @@ public class SigninPromoUtil { ...@@ -130,7 +132,17 @@ public class SigninPromoUtil {
public static void setupSyncPromoViewFromCache(SigninPromoController signinPromoController, public static void setupSyncPromoViewFromCache(SigninPromoController signinPromoController,
ProfileDataCache profileDataCache, PersonalizedSigninPromoView view, ProfileDataCache profileDataCache, PersonalizedSigninPromoView view,
SigninPromoController.OnDismissListener listener) { 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.getPrimaryButton().setText(R.string.sync_promo_turn_on_sync);
view.getSecondaryButton().setVisibility(View.GONE); view.getSecondaryButton().setVisibility(View.GONE);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.bookmarks; package org.chromium.chrome.browser.bookmarks;
import android.accounts.Account;
import android.view.View; import android.view.View;
import androidx.test.filters.MediumTest; import androidx.test.filters.MediumTest;
...@@ -34,6 +35,7 @@ import org.chromium.chrome.test.util.ChromeRenderTestRule; ...@@ -34,6 +35,7 @@ import org.chromium.chrome.test.util.ChromeRenderTestRule;
import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule; import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.components.signin.ProfileDataSource; import org.chromium.components.signin.ProfileDataSource;
import org.chromium.components.signin.test.util.FakeProfileDataSource; 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.NightModeTestUtils;
import org.chromium.ui.test.util.UiDisableIf; import org.chromium.ui.test.util.UiDisableIf;
...@@ -47,8 +49,10 @@ import org.chromium.ui.test.util.UiDisableIf; ...@@ -47,8 +49,10 @@ import org.chromium.ui.test.util.UiDisableIf;
public class BookmarkPersonalizedPromoRenderTest { public class BookmarkPersonalizedPromoRenderTest {
// FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge // FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge
// for Sync promo. // for Sync promo.
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
private final AccountManagerTestRule mAccountManagerTestRule = private final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource()); new AccountManagerTestRule(mFakeProfileDataSource);
private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule = private final ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
new ChromeActivityTestRule<>(ChromeActivity.class); new ChromeActivityTestRule<>(ChromeActivity.class);
...@@ -78,9 +82,14 @@ public class BookmarkPersonalizedPromoRenderTest { ...@@ -78,9 +82,14 @@ public class BookmarkPersonalizedPromoRenderTest {
@Before @Before
public void setUp() { public void setUp() {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData( // Native side needs to loaded before signing in test account.
"test@gmail.com", null, "Full Name", "Given Name"));
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, null, "Full Name", "Given Name")));
} }
@After @After
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.ntp; package org.chromium.chrome.browser.ntp;
import android.accounts.Account;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
...@@ -54,9 +55,11 @@ import java.util.concurrent.ExecutionException; ...@@ -54,9 +55,11 @@ import java.util.concurrent.ExecutionException;
public class RecentTabsPageTest { public class RecentTabsPageTest {
// FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge // FakeProfileDataSource is required to create the ProfileDataCache entry with sync_off badge
// for Sync promo. // for Sync promo.
private final FakeProfileDataSource mFakeProfileDataSource = new FakeProfileDataSource();
@Rule @Rule
public final AccountManagerTestRule mAccountManagerTestRule = public final AccountManagerTestRule mAccountManagerTestRule =
new AccountManagerTestRule(new FakeProfileDataSource()); new AccountManagerTestRule(mFakeProfileDataSource);
@Rule @Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule(); public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
...@@ -106,8 +109,12 @@ public class RecentTabsPageTest { ...@@ -106,8 +109,12 @@ public class RecentTabsPageTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testPersonalizedSigninPromoInRecentTabsPage() throws Exception { public void testPersonalizedSigninPromoInRecentTabsPage() throws Exception {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData( Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
"test@gmail.com", createAvatar(), "Full Name", "Given Name")); TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, createAvatar(), "Full Name", "Given Name")));
RecentTabsManager.forcePromoStateForTests( RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED); RecentTabsManager.PromoState.PROMO_SIGNIN_PERSONALIZED);
mPage = loadRecentTabsPage(); mPage = loadRecentTabsPage();
...@@ -118,8 +125,12 @@ public class RecentTabsPageTest { ...@@ -118,8 +125,12 @@ public class RecentTabsPageTest {
@LargeTest @LargeTest
@Feature("RenderTest") @Feature("RenderTest")
public void testPersonalizedSyncPromoInRecentTabsPage() throws Exception { public void testPersonalizedSyncPromoInRecentTabsPage() throws Exception {
mAccountManagerTestRule.addAccount(new ProfileDataSource.ProfileData( Account account = mAccountManagerTestRule.addTestAccountThenSigninAndEnableSync();
"test@gmail.com", createAvatar(), "Full Name", "Given Name")); TestThreadUtils.runOnUiThreadBlocking(
()
-> mFakeProfileDataSource.setProfileData(account.name,
new ProfileDataSource.ProfileData(
account.name, createAvatar(), "Full Name", "Given Name")));
RecentTabsManager.forcePromoStateForTests( RecentTabsManager.forcePromoStateForTests(
RecentTabsManager.PromoState.PROMO_SYNC_PERSONALIZED); RecentTabsManager.PromoState.PROMO_SYNC_PERSONALIZED);
mPage = loadRecentTabsPage(); 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