Commit c9e213f4 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

Reland "[HomepagePromo] Add finch param supressing_sign_in_promo"

This reverts commit c41c5c46.

Reason for revert: Changed to a different implementation, and fix the flaky test failed on M+ bots.

Original change's description:
> Revert "[HomepagePromo] Add finch param supressing_sign_in_promo"
>
> This reverts commit 25269f24.
>
> Reason for revert: test testSetUp_SuppressingSignInPromo fails constantly in android-arm64-proguard-rel (and fyi builder android-marshmallow-x86-fyi-rel) since
> * https://ci.chromium.org/p/chromium/builders/ci/android-arm64-proguard-rel/2020
> * https://ci.chromium.org/p/chromium/builders/ci/android-marshmallow-x86-fyi-rel/767
>
> Original change's description:
> > [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: Theresa  <twellington@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#781109}
>
> TBR=twellington@chromium.org,wenyufu@chromium.org
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> Bug: 1068831
> Change-Id: I97f226e93962469cc8a705e922a3db72d7e84cd8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2265398
> Reviewed-by: Haiyang Pan <hypan@google.com>
> Reviewed-by: Wenyu Fu <wenyufu@chromium.org>
> Commit-Queue: Haiyang Pan <hypan@google.com>
> Cr-Commit-Position: refs/heads/master@{#782189}

TBR=twellington@chromium.org,hypan@google.com,wenyufu@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1068831
Change-Id: Id652d450f84f44f4d15b2409c61c3cf84fa7c48e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2269484
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785953}
parent 90d2f5c0
...@@ -233,20 +233,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -233,20 +233,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
mTracker = TrackerFactory.getTrackerForProfile(profile); mTracker = TrackerFactory.getTrackerForProfile(profile);
// Mediator should be created before any Stream changes. if (ChromeFeatureList.isEnabled(ChromeFeatureList.HOMEPAGE_PROMO_CARD)) {
mMediator = new FeedSurfaceMediator(this, snapScrollHelper, mPageNavigationDelegate);
// Add the homepage promo card when the feed is enabled and the feature is enabled. A null
// mStream object means that the feed is disabled. The intialization of the mStream object
// is handled during the construction of the FeedSurfaceMediator where there might be cases
// where the mStream object remains null because the feed is disabled, in which case the
// homepage promo card cannot be added to the feed even if the feature is enabled.
if (mStream != null && ChromeFeatureList.isEnabled(ChromeFeatureList.HOMEPAGE_PROMO_CARD)) {
mHomepagePromoController = mHomepagePromoController =
new HomepagePromoController(mActivity, mSnackbarManager, mTracker, mMediator); new HomepagePromoController(mActivity, mSnackbarManager, mTracker);
mMediator.onHomepagePromoStateChange();
} }
// Mediator should be created before any Stream changes.
mMediator = new FeedSurfaceMediator(this, snapScrollHelper, mPageNavigationDelegate);
mUserEducationHelper = new UserEducationHelper(mActivity, mHandler); mUserEducationHelper = new UserEducationHelper(mActivity, mHandler);
} }
...@@ -449,8 +443,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -449,8 +443,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
return mSigninPromoView; return mSigninPromoView;
} }
/** Update header views in the Stream. */ /**
void updateHeaderViews(boolean isSignInPromoVisible) { * Update header views in the Stream.
* */
void updateHeaderViews(boolean isSignInPromoVisible, View homepagePromoView) {
if (mStream == null) return; if (mStream == null) return;
List<Header> headers = new ArrayList<>(); List<Header> headers = new ArrayList<>();
...@@ -459,14 +455,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -459,14 +455,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
headers.add(new NonDismissibleHeader(mNtpHeader)); headers.add(new NonDismissibleHeader(mNtpHeader));
} }
// TODO(wenyufu): check Finch flag for whether sign-in takes precedence over homepage promo if (homepagePromoView != null) {
if (!isSignInPromoVisible && mHomepagePromoController != null) { mHomepagePromoView = homepagePromoView;
View promoView = mHomepagePromoController.getPromoView();
if (promoView != null) {
mHomepagePromoView = promoView;
headers.add(new HomepagePromoHeader()); headers.add(new HomepagePromoHeader());
} }
}
if (mSectionHeaderView != null) { if (mSectionHeaderView != null) {
headers.add(new NonDismissibleHeader(mSectionHeaderView)); headers.add(new NonDismissibleHeader(mSectionHeaderView));
...@@ -519,6 +511,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider { ...@@ -519,6 +511,10 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
return mUserEducationHelper; return mUserEducationHelper;
} }
HomepagePromoController getHomepagePromoController() {
return mHomepagePromoController;
}
@VisibleForTesting @VisibleForTesting
FeedSurfaceMediator getMediatorForTesting() { FeedSurfaceMediator getMediatorForTesting() {
return mMediator; return mMediator;
......
...@@ -28,9 +28,11 @@ import org.chromium.chrome.browser.ntp.NewTabPageLayout; ...@@ -28,9 +28,11 @@ import org.chromium.chrome.browser.ntp.NewTabPageLayout;
import org.chromium.chrome.browser.ntp.SnapScrollHelper; import org.chromium.chrome.browser.ntp.SnapScrollHelper;
import org.chromium.chrome.browser.ntp.cards.SignInPromo; import org.chromium.chrome.browser.ntp.cards.SignInPromo;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoController.HomepagePromoStateListener; import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoController.HomepagePromoStateListener;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoVariationManager;
import org.chromium.chrome.browser.ntp.snippets.SectionHeader; import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
import org.chromium.chrome.browser.preferences.Pref; import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar; import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory; import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.signin.IdentityServicesProvider; import org.chromium.chrome.browser.signin.IdentityServicesProvider;
...@@ -253,15 +255,58 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate, ...@@ -253,15 +255,58 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
// This is currently only relevant for the two panes start surface. // This is currently only relevant for the two panes start surface.
stream.setStreamContentVisibility(mHasHeader ? mSectionHeader.isExpanded() : true); stream.setStreamContentVisibility(mHasHeader ? mSectionHeader.isExpanded() : true);
if (SignInPromo.shouldCreatePromo()) { initStreamHeaderViews();
mMemoryPressureCallback = pressure -> mCoordinator.getStream().trim();
MemoryPressureListener.addCallback(mMemoryPressureCallback);
}
private void initStreamHeaderViews() {
View homepagePromoView = null;
boolean signInPromoVisible = false;
if (!HomepagePromoVariationManager.getInstance().isSuppressingSignInPromo()) {
signInPromoVisible = createSignInPromoIfNeeded();
if (!signInPromoVisible) homepagePromoView = createHomepagePromoIfNeeded();
} else {
homepagePromoView = createHomepagePromoIfNeeded();
if (homepagePromoView == null) signInPromoVisible = createSignInPromoIfNeeded();
}
// Post processing - if HomepagePromo is showing, then we set the SignInPromo to null.
if (homepagePromoView != null && mSignInPromo != null) {
mSignInPromo.destroy();
mSignInPromo = null;
}
// We are not going to show two promos at the same time.
mCoordinator.updateHeaderViews(signInPromoVisible, homepagePromoView);
}
/**
* Create and setup the SignInPromo if necessary.
* @return Whether the SignPromo is visible.
*/
private boolean createSignInPromoIfNeeded() {
if (!SignInPromo.shouldCreatePromo()) return false;
if (mSignInPromo == null) {
boolean suggestionsVisible =
PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
mSignInPromo = new FeedSignInPromo(mSigninManager); mSignInPromo = new FeedSignInPromo(mSigninManager);
mSignInPromo.setCanShowPersonalizedSuggestions(suggestionsVisible); mSignInPromo.setCanShowPersonalizedSuggestions(suggestionsVisible);
} }
return mSignInPromo.isVisible();
}
mCoordinator.updateHeaderViews(mSignInPromo != null && mSignInPromo.isVisible()); private View createHomepagePromoIfNeeded() {
if (mCoordinator.getHomepagePromoController() == null) return null;
mMemoryPressureCallback = pressure -> mCoordinator.getStream().trim(); View homepagePromoView = mCoordinator.getHomepagePromoController().getPromoView();
MemoryPressureListener.addCallback(mMemoryPressureCallback); if (homepagePromoView != null) {
mCoordinator.getHomepagePromoController().setHomepagePromoStateListener(this);
}
return homepagePromoView;
} }
/** Clear any dependencies related to the {@link Stream}. */ /** Clear any dependencies related to the {@link Stream}. */
...@@ -508,7 +553,10 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate, ...@@ -508,7 +553,10 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
@Override @Override
public void onHomepagePromoStateChange() { public void onHomepagePromoStateChange() {
mCoordinator.updateHeaderViews(mSignInPromo != null && mSignInPromo.isVisible()); // If the homepage has status update, we'll not show the HomepagePromo again.
// There are cases where the user has their homepage reset to default. This is an edge case
// and we don't have to reflect that change immediately.
mCoordinator.updateHeaderViews(false, null);
} }
// IdentityManager.Delegate interface. // IdentityManager.Delegate interface.
...@@ -542,7 +590,7 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate, ...@@ -542,7 +590,7 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
if (isVisible() == visible) return; if (isVisible() == visible) return;
super.setVisibilityInternal(visible); super.setVisibilityInternal(visible);
mCoordinator.updateHeaderViews(visible); mCoordinator.updateHeaderViews(visible, null);
maybeUpdateSignInPromo(); maybeUpdateSignInPromo();
} }
......
...@@ -63,17 +63,21 @@ public class HomepagePromoController implements HomepageStateListener { ...@@ -63,17 +63,21 @@ public class HomepagePromoController implements HomepageStateListener {
* @param context Context from the activity. * @param context Context from the activity.
* @param snackbarManager SnackbarManager used to display snackbar. * @param snackbarManager SnackbarManager used to display snackbar.
* @param tracker Tracker for the feature engagement system. * @param tracker Tracker for the feature engagement system.
* @param listener Listener to be notified when the promo should be removed from the parent
* view.
*/ */
public HomepagePromoController(Context context, SnackbarManager snackbarManager, public HomepagePromoController(
Tracker tracker, HomepagePromoStateListener listener) { Context context, SnackbarManager snackbarManager, Tracker tracker) {
mContext = context; mContext = context;
mSnackbarController = new HomepagePromoSnackbarController(context, snackbarManager); mSnackbarController = new HomepagePromoSnackbarController(context, snackbarManager);
// Inform event of creation. // Inform event of creation.
mTracker = tracker; mTracker = tracker;
}
/**
* @param listener Listener to be notified when the promo should be removed from the parent
* view.
*/
public void setHomepagePromoStateListener(@Nullable HomepagePromoStateListener listener) {
mStateListener = listener; mStateListener = listener;
} }
......
...@@ -122,6 +122,14 @@ public class HomepagePromoVariationManager { ...@@ -122,6 +122,14 @@ public class HomepagePromoVariationManager {
return LayoutStyle.COMPACT; 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. * If the user has ever seen the homepage promo, add a synthetic tag to the user.
*/ */
......
...@@ -8,6 +8,7 @@ import static androidx.test.espresso.Espresso.onView; ...@@ -8,6 +8,7 @@ import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
...@@ -54,7 +55,10 @@ import org.chromium.chrome.browser.ntp.cards.SignInPromo; ...@@ -54,7 +55,10 @@ import org.chromium.chrome.browser.ntp.cards.SignInPromo;
import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoUtils.HomepagePromoAction; import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoUtils.HomepagePromoAction;
import org.chromium.chrome.browser.partnercustomizations.BasePartnerBrowserCustomizationIntegrationTestRule; import org.chromium.chrome.browser.partnercustomizations.BasePartnerBrowserCustomizationIntegrationTestRule;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.HomeButton; import org.chromium.chrome.browser.toolbar.HomeButton;
import org.chromium.chrome.browser.toolbar.ToolbarManager; import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar; import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
...@@ -62,6 +66,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager; ...@@ -62,6 +66,7 @@ import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.NewTabPageTestUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.Features.EnableFeatures; import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.browser_ui.widget.promo.PromoCardCoordinator.LayoutStyle; import org.chromium.components.browser_ui.widget.promo.PromoCardCoordinator.LayoutStyle;
...@@ -80,7 +85,8 @@ import org.chromium.content_public.browser.test.util.TouchCommon; ...@@ -80,7 +85,8 @@ import org.chromium.content_public.browser.test.util.TouchCommon;
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@EnableFeatures(ChromeFeatureList.HOMEPAGE_PROMO_CARD) @EnableFeatures(ChromeFeatureList.HOMEPAGE_PROMO_CARD)
@Features.DisableFeatures(ChromeFeatureList.QUERY_TILES) @Features.
DisableFeatures({ChromeFeatureList.QUERY_TILES, ChromeFeatureList.REPORT_FEED_USER_ACTIONS})
public class HomepagePromoTest { public class HomepagePromoTest {
public static final String PARTNER_HOMEPAGE_URL = "http://127.0.0.1:8000/foo.html"; public static final String PARTNER_HOMEPAGE_URL = "http://127.0.0.1:8000/foo.html";
public static final String CUSTOM_TEST_URL = "http://127.0.0.1:8000/bar.html"; public static final String CUSTOM_TEST_URL = "http://127.0.0.1:8000/bar.html";
...@@ -203,7 +209,8 @@ public class HomepagePromoTest { ...@@ -203,7 +209,8 @@ public class HomepagePromoTest {
SharedPreferencesManager.getInstance().writeBoolean( SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_DISMISSED, true); ChromePreferenceKeys.SIGNIN_PROMO_NTP_PROMO_DISMISSED, true);
mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL); mActivityTestRule.loadUrlInNewTab("about:blank");
launchNewTabPage();
Assert.assertNull("SignInPromo should be dismissed.", Assert.assertNull("SignInPromo should be dismissed.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container)); mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
...@@ -216,6 +223,105 @@ public class HomepagePromoTest { ...@@ -216,6 +223,105 @@ public class HomepagePromoTest {
METRICS_HOMEPAGE_PROMO, HomepagePromoAction.CREATED)); METRICS_HOMEPAGE_PROMO, HomepagePromoAction.CREATED));
} }
@Test
@SmallTest
public void testSetUp_SuppressingSignInPromo() {
// Adding another check in case Mockito does not prepare the mock correctly.
Mockito.doReturn(true).when(mMockVariationManager).isSuppressingSignInPromo();
Assert.assertTrue(mMockVariationManager.isSuppressingSignInPromo());
launchNewTabPage();
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("about:blank");
launchNewTabPage();
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));
}
@Test
@SmallTest
public void testToggleFeed_WithSignIn() {
// Test to toggle stream when HomepagePromo is hide. Toggle feed should hide promo still.
launchNewTabPage();
Assert.assertNull("Homepage promo should not show for this NTP visit.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNotNull("SignInPromo should be displayed on the screen.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
NewTabPage ntp = getNewTabPage();
RecyclerView recyclerView =
(RecyclerView) ntp.getCoordinatorForTesting().getStreamForTesting().getView();
toggleFeedHeader(NTP_HEADER_POSITION + 1, recyclerView, false);
Assert.assertNull("Homepage promo should not show for this NTP visit.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNull("SignInPromo should be hidden from the screen.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
toggleFeedHeader(NTP_HEADER_POSITION + 1, recyclerView, true);
Assert.assertNull("Homepage promo should not show for this NTP visit.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNotNull("SignInPromo should be displayed on the screen.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
}
@Test
@SmallTest
public void testToggleFeed_WithHomepage() {
// Test to toggle NTP when feed is hidden.
TestThreadUtils.runOnUiThreadBlocking(() -> {
PrefServiceBridge.getInstance().setBoolean(Pref.ARTICLES_LIST_VISIBLE, false);
});
launchNewTabPage();
Assert.assertNotNull("Homepage promo should show.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNull("SignInPromo should not displayed on the screen as feed collapse.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
NewTabPage ntp = getNewTabPage();
RecyclerView recyclerView =
(RecyclerView) ntp.getCoordinatorForTesting().getStreamForTesting().getView();
int feedHeaderPosition = NTP_HEADER_POSITION + 2;
// As HomepagePromo exists, feed header is at
toggleFeedHeader(feedHeaderPosition, recyclerView, true);
Assert.assertNotNull("Homepage promo should keep being displayed.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNull("SignInPromo should be hidden from the screen for this NTP visit.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
toggleFeedHeader(feedHeaderPosition, recyclerView, false);
Assert.assertNotNull("Homepage promo should keep being displayed.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
Assert.assertNull("SignInPromo should be hidden from the screen for this NTP visit.",
mActivityTestRule.getActivity().findViewById(R.id.signin_promo_view_container));
}
/** /**
* Clicking on dismiss button should hide the promo. * Clicking on dismiss button should hide the promo.
*/ */
...@@ -254,7 +360,8 @@ public class HomepagePromoTest { ...@@ -254,7 +360,8 @@ public class HomepagePromoTest {
Mockito.verify(mTracker, times(1)).dismissed(FeatureConstants.HOMEPAGE_PROMO_CARD_FEATURE); Mockito.verify(mTracker, times(1)).dismissed(FeatureConstants.HOMEPAGE_PROMO_CARD_FEATURE);
// Load to NTP one more time. The promo should not show. // Load to NTP one more time. The promo should not show.
mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL); mActivityTestRule.loadUrlInNewTab("about:blank");
launchNewTabPage();
Assert.assertNull("Homepage promo should not be added to NTP.", Assert.assertNull("Homepage promo should not be added to NTP.",
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo)); mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
} }
...@@ -402,4 +509,32 @@ public class HomepagePromoTest { ...@@ -402,4 +509,32 @@ public class HomepagePromoTest {
private void setVariationForTests(@LayoutStyle int variation) { private void setVariationForTests(@LayoutStyle int variation) {
Mockito.when(mMockVariationManager.getLayoutVariation()).thenReturn(variation); Mockito.when(mMockVariationManager.getLayoutVariation()).thenReturn(variation);
} }
private void launchNewTabPage() {
mActivityTestRule.loadUrl(UrlConstants.NTP_URL);
Tab tab = mActivityTestRule.getActivity().getActivityTab();
NewTabPageTestUtils.waitForNtpLoaded(tab);
}
private NewTabPage getNewTabPage() {
Tab tab = mActivityTestRule.getActivity().getActivityTab();
NewTabPageTestUtils.waitForNtpLoaded(tab);
Assert.assertTrue(tab.getNativePage() instanceof NewTabPage);
return (NewTabPage) tab.getNativePage();
}
private void toggleFeedHeader(int feedHeaderPosition, ViewGroup rootView, boolean expanded) {
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition),
RecyclerViewActions.actionOnItemAtPosition(feedHeaderPosition, click()));
// Scroll to the same position in case the refresh brings the section header out of the
// screen.
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition));
waitForView(rootView,
allOf(withId(R.id.header_status),
withText(expanded ? R.string.hide : R.string.show)));
}
} }
...@@ -1488,6 +1488,9 @@ const FeatureEntry::FeatureParam kHomepagePromoCardCompact[] = { ...@@ -1488,6 +1488,9 @@ const FeatureEntry::FeatureParam kHomepagePromoCardCompact[] = {
{"promo-card-variation", "Compact"}}; {"promo-card-variation", "Compact"}};
const FeatureEntry::FeatureParam kHomepagePromoCardSlim[] = { const FeatureEntry::FeatureParam kHomepagePromoCardSlim[] = {
{"promo-card-variation", "Slim"}}; {"promo-card-variation", "Slim"}};
const FeatureEntry::FeatureParam kHomepagePromoCardSuppressing[] = {
{"promo-card-variation", "Compact"},
{"suppressing_sign_in_promo", "true"}};
const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = { const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = {
{"Large", kHomepagePromoCardLarge, base::size(kHomepagePromoCardLarge), {"Large", kHomepagePromoCardLarge, base::size(kHomepagePromoCardLarge),
...@@ -1495,7 +1498,9 @@ const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = { ...@@ -1495,7 +1498,9 @@ const FeatureEntry::FeatureVariation kHomepagePromoCardVariations[] = {
{"Compact", kHomepagePromoCardCompact, {"Compact", kHomepagePromoCardCompact,
base::size(kHomepagePromoCardCompact), nullptr}, base::size(kHomepagePromoCardCompact), nullptr},
{"Slim", kHomepagePromoCardSlim, base::size(kHomepagePromoCardSlim), {"Slim", kHomepagePromoCardSlim, base::size(kHomepagePromoCardSlim),
nullptr}}; nullptr},
{"Compact_SuppressingSignInPromo", kHomepagePromoCardSuppressing,
base::size(kHomepagePromoCardSuppressing), nullptr}};
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -5417,7 +5422,7 @@ const FeatureEntry kFeatureEntries[] = { ...@@ -5417,7 +5422,7 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kHomepagePromoCardDescription, kOsAndroid, flag_descriptions::kHomepagePromoCardDescription, kOsAndroid,
FEATURE_WITH_PARAMS_VALUE_TYPE(chrome::android::kHomepagePromoCard, FEATURE_WITH_PARAMS_VALUE_TYPE(chrome::android::kHomepagePromoCard,
kHomepagePromoCardVariations, kHomepagePromoCardVariations,
"HomepagePromoCard")}, "HomepagePromoAndroid")},
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
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