Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| index 79a6a435b77c693134925d517c8aed9411119b51..dfef4c60ca5d9c7059fea43ffdde56dd6518545b 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerViewTest.java |
| @@ -4,6 +4,7 @@ |
| package org.chromium.chrome.browser.ntp.cards; |
| +import android.content.res.Resources; |
| import android.support.test.filters.MediumTest; |
| import android.support.v7.widget.RecyclerView; |
| import android.support.v7.widget.RecyclerView.ViewHolder; |
| @@ -14,6 +15,7 @@ import org.chromium.base.test.util.CommandLineFlags; |
| import org.chromium.base.test.util.Feature; |
| import org.chromium.base.test.util.RetryOnFailure; |
| import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ChromeFeatureList; |
| import org.chromium.chrome.browser.UrlConstants; |
| import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| import org.chromium.chrome.browser.ntp.NTPTileSource; |
| @@ -117,7 +119,6 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| - @CommandLineFlags.Add("enable-features=NTPSnippets") |
| public void testClickSuggestion() throws InterruptedException { |
| setSuggestionsAndWaitForUpdate(10); |
| List<SnippetArticle> suggestions = mSource.getSuggestionsForCategory(TEST_CATEGORY); |
| @@ -137,7 +138,6 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| - @CommandLineFlags.Add("enable-features=NTPSnippets,NTPSuggestionsSectionDismissal") |
| public void testAllDismissed() throws InterruptedException, TimeoutException { |
| setSuggestionsAndWaitForUpdate(3); |
| assertEquals(3, mSource.getSuggestionsForCategory(TEST_CATEGORY).size()); |
| @@ -170,7 +170,6 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| - @CommandLineFlags.Add("enable-features=NTPSnippets") |
| public void testDismissArticleWithContextMenu() throws InterruptedException, TimeoutException { |
| setSuggestionsAndWaitForUpdate(10); |
| List<SnippetArticle> suggestions = mSource.getSuggestionsForCategory(TEST_CATEGORY); |
| @@ -190,7 +189,6 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| - @CommandLineFlags.Add("enable-features=NTPSnippets,NTPSuggestionsSectionDismissal") |
| public void testDismissStatusCardWithContextMenu() |
| throws InterruptedException, TimeoutException { |
| setSuggestionsAndWaitForUpdate(0); |
| @@ -211,7 +209,6 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| @MediumTest |
| @Feature({"NewTabPage"}) |
| - @CommandLineFlags.Add("enable-features=NTPSnippets,NTPSuggestionsSectionDismissal") |
| public void testDismissActionItemWithContextMenu() |
| throws InterruptedException, TimeoutException { |
| setSuggestionsAndWaitForUpdate(0); |
| @@ -229,6 +226,70 @@ public class NewTabPageRecyclerViewTest extends ChromeTabbedActivityTestBase { |
| assertArrayEquals(new int[0], mSource.getCategories()); |
| } |
| + @MediumTest |
| + @Feature({"NewTabPage"}) |
| + @CommandLineFlags.Add({"disable-features=" + ChromeFeatureList.NTP_CONDENSED_LAYOUT}) |
| + public void testSnapScrollNoCondensedLayout() { |
| + setSuggestionsAndWaitForUpdate(0); |
| + |
| + Resources res = getInstrumentation().getTargetContext().getResources(); |
| + int toolbarHeight = res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow) |
| + + res.getDimensionPixelSize(R.dimen.toolbar_progress_bar_height); |
| + View searchBox = getNtpView().findViewById(R.id.search_box); |
| + int searchBoxTop = searchBox.getTop() + searchBox.getPaddingTop(); |
| + int searchBoxTransitionLength = |
| + res.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length); |
| + |
| + // Two different snapping regions with the default behavior: snapping back up to the |
| + // watershed point in the middle, snapping forward after that. |
| + assertEquals(0, getSnapPosition(0)); |
| + assertEquals(0, getSnapPosition(toolbarHeight / 2 - 1)); |
| + assertEquals(toolbarHeight, getSnapPosition(toolbarHeight / 2)); |
| + assertEquals(toolbarHeight, getSnapPosition(toolbarHeight)); |
| + assertEquals(toolbarHeight + 1, getSnapPosition(toolbarHeight + 1)); |
| + |
| + assertEquals(searchBoxTop - searchBoxTransitionLength - 1, |
|
PEConn
2017/02/21 14:43:24
It might increase readability to add convenience m
Bernhard Bauer
2017/02/21 15:04:34
The one thing I don't like about that is that it w
|
| + getSnapPosition(searchBoxTop - searchBoxTransitionLength - 1)); |
| + assertEquals(searchBoxTop - searchBoxTransitionLength, |
| + getSnapPosition(searchBoxTop - searchBoxTransitionLength)); |
| + assertEquals(searchBoxTop - searchBoxTransitionLength, |
| + getSnapPosition(searchBoxTop - searchBoxTransitionLength / 2 - 1)); |
| + assertEquals(searchBoxTop, getSnapPosition(searchBoxTop - searchBoxTransitionLength / 2)); |
| + assertEquals(searchBoxTop, getSnapPosition(searchBoxTop)); |
| + assertEquals(searchBoxTop + 1, getSnapPosition(searchBoxTop + 1)); |
| + } |
| + |
| + @MediumTest |
| + @Feature({"NewTabPage"}) |
| + @CommandLineFlags.Add({"enable-features=" + ChromeFeatureList.NTP_CONDENSED_LAYOUT}) |
| + public void testSnapScrollCondensedLayout() { |
| + setSuggestionsAndWaitForUpdate(0); |
| + |
| + Resources res = getInstrumentation().getTargetContext().getResources(); |
| + int toolbarHeight = res.getDimensionPixelSize(R.dimen.toolbar_height_no_shadow) |
| + + res.getDimensionPixelSize(R.dimen.toolbar_progress_bar_height); |
| + View searchBox = getNtpView().findViewById(R.id.search_box); |
| + int searchBoxTop = searchBox.getTop() + searchBox.getPaddingTop(); |
| + int searchBoxTransitionLength = |
| + res.getDimensionPixelSize(R.dimen.ntp_search_box_transition_length); |
| + |
| + // With the condensed layout, the snapping regions overlap, so the effect is that of a |
| + // single snapping region. |
| + assertEquals(0, getSnapPosition(0)); |
| + assertEquals(0, getSnapPosition(toolbarHeight / 2 - 1)); |
| + assertEquals(searchBoxTop, getSnapPosition(toolbarHeight / 2)); |
| + assertEquals(searchBoxTop, getSnapPosition(searchBoxTop - searchBoxTransitionLength)); |
| + assertEquals(searchBoxTop, getSnapPosition(toolbarHeight)); |
| + assertEquals(searchBoxTop, getSnapPosition(searchBoxTop)); |
| + assertEquals(searchBoxTop + 1, getSnapPosition(searchBoxTop + 1)); |
| + } |
| + |
| + private int getSnapPosition(int scrollPosition) { |
| + NewTabPageView ntpView = getNtpView(); |
| + return getRecyclerView().calculateSnapPosition( |
| + scrollPosition, ntpView.findViewById(R.id.search_box), ntpView.getHeight()); |
| + } |
| + |
| private NewTabPageView getNtpView() { |
| return mNtp.getNewTabPageView(); |
| } |