Commit 25269f24 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

[HomepagePromo] Add finch param supressing_sign_in_promo

Adding the option for homepage promo to suppress the sign in promo when
user is not signed in.

Bug: 1068831
Change-Id: I854109c4623c47f98aab1faa34f94f2d55961474
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252379
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781109}
parent 57ff3c59
......@@ -39,6 +39,7 @@ import org.chromium.chrome.browser.native_page.NativePageNavigationDelegate;
import org.chromium.chrome.browser.ntp.NewTabPageLayout;
import org.chromium.chrome.browser.ntp.SnapScrollHelper;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoController;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoVariationManager;
import org.chromium.chrome.browser.ntp.snippets.SectionHeaderView;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
......@@ -449,12 +450,16 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
headers.add(new NonDismissibleHeader(mNtpHeader));
}
// TODO(wenyufu): check Finch flag for whether sign-in takes precedence over homepage promo
if (!isSignInPromoVisible && mHomepagePromoController != null) {
View promoView = mHomepagePromoController.getPromoView();
if (promoView != null) {
mHomepagePromoView = promoView;
headers.add(new HomepagePromoHeader());
// TODO(wenyufu): Consider moving priority logic into Mediator
if (mHomepagePromoController != null) {
if (!isSignInPromoVisible
|| HomepagePromoVariationManager.getInstance().isSuppressingSignInPromo()) {
View promoView = mHomepagePromoController.getPromoView();
if (promoView != null) {
mHomepagePromoView = promoView;
headers.add(new HomepagePromoHeader());
isSignInPromoVisible = false;
}
}
}
......
......@@ -122,6 +122,14 @@ public class HomepagePromoVariationManager {
return LayoutStyle.COMPACT;
}
/**
* @return Whether the homepage promo has a higher priority than SignInPromo.
*/
public boolean isSuppressingSignInPromo() {
return ChromeFeatureList.getFieldTrialParamByFeatureAsBoolean(
ChromeFeatureList.HOMEPAGE_PROMO_CARD, "suppressing_sign_in_promo", false);
}
/**
* If the user has ever seen the homepage promo, add a synthetic tag to the user.
*/
......
......@@ -216,6 +216,37 @@ public class HomepagePromoTest {
METRICS_HOMEPAGE_PROMO, HomepagePromoAction.CREATED));
}
@Test
@SmallTest
@DisableIf.Build(sdk_is_greater_than = VERSION_CODES.O, message = "crbug.com/1097179")
public void testSetUp_SuppressingSignInPromo() {
Mockito.doReturn(true).when(mMockVariationManager).isSuppressingSignInPromo();
mActivityTestRule.loadUrl(UrlConstants.NTP_URL);
Assert.assertTrue("Homepage Promo should match creation criteria.",
HomepagePromoUtils.shouldCreatePromo(null));
View homepagePromo = mActivityTestRule.getActivity().findViewById(R.id.homepage_promo);
Assert.assertNotNull("Homepage promo should be added to NTP.", homepagePromo);
Assert.assertEquals(
"Homepage promo should be visible.", View.VISIBLE, homepagePromo.getVisibility());
Assert.assertEquals("Promo created should be recorded once.", 1,
RecordHistogram.getHistogramValueCountForTesting(
METRICS_HOMEPAGE_PROMO, HomepagePromoAction.CREATED));
// Dismiss the HomepagePromo in shared preference, then load another NTP page.
HomepagePromoUtils.setPromoDismissedInSharedPreference(true);
mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL);
Assert.assertNotNull("SignInPromo should be displayed on the screen.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
Assert.assertFalse("Homepage Promo should not match creation criteria.",
HomepagePromoUtils.shouldCreatePromo(null));
Assert.assertNull("Homepage promo should not show on the screen.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
}
/**
* Clicking on dismiss button should hide the promo.
*/
......
......@@ -1538,6 +1538,8 @@ const FeatureEntry::FeatureParam kHomepagePromoCardCompact[] = {
{"promo-card-variation", "Compact"}};
const FeatureEntry::FeatureParam kHomepagePromoCardSlim[] = {
{"promo-card-variation", "Slim"}};
const FeatureEntry::FeatureParam kHomepagePromoCardSupressing[] = {
{"suppressing_sign_in_promo", "SuppressingSignInPromo"}};
const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = {
{"Large", kHomepagePromoCardLarge, base::size(kHomepagePromoCardLarge),
......@@ -1545,7 +1547,9 @@ const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = {
{"Compact", kHomepagePromoCardCompact,
base::size(kHomepagePromoCardCompact), nullptr},
{"Slim", kHomepagePromoCardSlim, base::size(kHomepagePromoCardSlim),
nullptr}};
nullptr},
{"Compact_SuppressingSignInPromo", kHomepagePromoCardSupressing,
base::size(kHomepagePromoCardSupressing), nullptr}};
#endif // defined(OS_ANDROID)
#if defined(OS_ANDROID)
......
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