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

[HomepagePromo] Add swipe to dismiss

Adding swipe to dismiss for all variation, so the user can swipe to
dismiss the slim variation that does not have a "No thanks" button.

Bug: 1068831, 1084756
Change-Id: I445ae547bdfdc32866ff457653a778c00f5043ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209677
Commit-Queue: Wenyu Fu <wenyufu@chromium.org>
Auto-Submit: Wenyu Fu <wenyufu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770696}
parent 36e0bc46
......@@ -232,11 +232,14 @@ public class FeedSurfaceCoordinator implements FeedSurfaceProvider {
@Override
public boolean isDismissible() {
return false;
return true;
}
@Override
public void onDismissed() {}
public void onDismissed() {
assert mHomepagePromoController != null;
mHomepagePromoController.dismissPromo();
}
}
/**
......
......@@ -201,7 +201,7 @@ public class HomepagePromoController implements HomepageStateListener {
/**
* Dismissed the promo and record the user action.
*/
private void dismissPromo() {
public void dismissPromo() {
HomepagePromoUtils.setPromoDismissedInSharedPreference(true);
HomepagePromoUtils.recordHomepagePromoEvent(HomepagePromoAction.DISMISSED);
dismissPromoInternal();
......
......@@ -16,6 +16,11 @@ import static org.mockito.Mockito.times;
import static org.chromium.chrome.test.util.ViewUtils.waitForView;
import android.os.Build.VERSION_CODES;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.GeneralLocation;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.view.View;
import android.view.ViewGroup;
......@@ -64,6 +69,8 @@ import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.feature_engagement.EventConstants;
import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TouchCommon;
......@@ -250,6 +257,43 @@ public class HomepagePromoTest {
mActivityTestRule.getActivity().findViewById(R.id.homepage_promo));
}
/**
* Test dismiss by swipe left. This dismissal works in general for any variations.
*/
@Test
@SmallTest
public void testDismiss_SwipeToDismiss() {
setVariationForTests(LayoutStyle.SLIM);
SignInPromo.setDisablePromoForTests(true);
mActivityTestRule.loadUrl(UrlConstants.NTP_URL);
scrollToHomepagePromo();
// Swipe left and wait until the promo is dismissed.
ViewAction swipeLeft = new GeneralSwipeAction(
Swipe.FAST, GeneralLocation.CENTER, GeneralLocation.CENTER_LEFT, Press.FINGER);
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.actionOnItemAtPosition(
NTP_HEADER_POSITION + 1, swipeLeft));
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return mActivityTestRule.getActivity().findViewById(R.id.homepage_promo) == null;
}
});
// Verification for metrics
Assert.assertEquals("Promo dismissed should be recorded once. ", 1,
RecordHistogram.getHistogramValueCountForTesting(
METRICS_HOMEPAGE_PROMO, HomepagePromoAction.DISMISSED));
Assert.assertEquals("Promo impression until dismissed should be recorded once.", 1,
RecordHistogram.getHistogramTotalCountForTesting(
METRICS_HOMEPAGE_PROMO_IMPRESSION_DISMISSAL));
Mockito.verify(mTracker, times(1)).dismissed(FeatureConstants.HOMEPAGE_PROMO_CARD_FEATURE);
}
@Test
@MediumTest
@DisableIf.Build(sdk_is_greater_than = VERSION_CODES.O, message = "crbug.com/1077316")
......
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