Commit b9eeac84 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Feed] Enable existing test and add new tests

+ Parameterized some more tests in NewTabPageTest
+ Add some tests for FeedNewTabPage on the header views

Bug: 860055
Change-Id: Ie86d67d4e852117eb4074db9c522bbc219d5d4dc
Reviewed-on: https://chromium-review.googlesource.com/1227178
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592910}
parent 6f312268
......@@ -15,7 +15,6 @@ import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ScrollView;
......@@ -323,7 +322,7 @@ public class FeedNewTabPage extends NewTabPage {
LayoutInflater inflater = LayoutInflater.from(activity);
mSectionHeaderView = (SectionHeaderView) inflater.inflate(
R.layout.new_tab_page_snippets_expandable_header, null);
R.layout.new_tab_page_snippets_expandable_header, mRootView, false);
mSectionHeaderViewMarginResizer = MarginResizer.createAndAttach(
mSectionHeaderView, mUiConfig, mDefaultMargin, mWideMargin);
......@@ -395,12 +394,8 @@ public class FeedNewTabPage extends NewTabPage {
if (mSigninPromoView == null) {
LayoutInflater inflater = LayoutInflater.from(mRootView.getContext());
mSigninPromoView = (PersonalizedSigninPromoView) inflater.inflate(
R.layout.personalized_signin_promo_view_modern_content_suggestions, null);
ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.bottomMargin = mDefaultMargin;
mSigninPromoView.setLayoutParams(lp);
R.layout.personalized_signin_promo_view_modern_content_suggestions, mRootView,
false);
mSignInPromoViewMarginResizer = MarginResizer.createAndAttach(
mSigninPromoView, mUiConfig, mDefaultMargin, mWideMargin);
}
......@@ -432,4 +427,19 @@ public class FeedNewTabPage extends NewTabPage {
FeedProcessScopeFactory.clearFeedProcessScopeForTesting();
}
}
@VisibleForTesting
FeedNewTabPageMediator getMediatorForTesting() {
return mMediator;
}
@Override
public View getSignInPromoViewForTesting() {
return getSigninPromoView();
}
@Override
public View getSectionHeaderViewForTesting() {
return getSectionHeaderView();
}
}
......@@ -15,6 +15,7 @@ import com.google.android.libraries.feed.api.stream.ScrollListener;
import com.google.android.libraries.feed.api.stream.Stream;
import org.chromium.base.MemoryPressureListener;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.memory.MemoryPressureCallback;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.native_page.ContextMenuManager;
......@@ -34,6 +35,8 @@ import org.chromium.chrome.browser.signin.SigninPromoUtil;
*/
class FeedNewTabPageMediator
implements NewTabPageLayout.ScrollDelegate, ContextMenuManager.TouchEnabledDelegate {
private static boolean sOverrideFeedEnabledForTesting;
private final FeedNewTabPage mCoordinator;
private final SnapScrollHelper mSnapScrollHelper;
private final PrefChangeRegistrar mPrefChangeRegistrar;
......@@ -84,8 +87,13 @@ class FeedNewTabPageMediator
/** Update the content based on supervised user or enterprise policy. */
private void updateContent() {
mFeedEnabled =
PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_SECTION_ENABLED);
// TODO(huayinz): Replace sOverrideFeedEnabledForTesting with the real preference in test
// once we have a decision for whether to re-enable the Feed on supervised/enterprise
// account removed within a session.
if (!sOverrideFeedEnabledForTesting) {
mFeedEnabled =
PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_SECTION_ENABLED);
}
if ((mFeedEnabled && mCoordinator.getStream() != null)
|| (!mFeedEnabled && mCoordinator.getScrollViewForPolicy() != null))
return;
......@@ -316,4 +324,26 @@ class FeedNewTabPageMediator
mCoordinator.getSigninPromoView(), null);
}
}
@VisibleForTesting
void overrideFeedEnabledForTesting(boolean override) {
sOverrideFeedEnabledForTesting = override;
}
@VisibleForTesting
void updateContentForTesting(boolean feedEnabled) {
mFeedEnabled = feedEnabled;
updateContent();
}
// TODO(huayinz): Return the Model for testing in Coordinator instead once a Model is created.
@VisibleForTesting
SectionHeader getSectionHeaderForTesting() {
return mSectionHeader;
}
@VisibleForTesting
SignInPromo getSignInPromoForTesting() {
return mSignInPromo;
}
}
......@@ -46,6 +46,7 @@ if (enable_feed_in_chrome) {
feed_test_java_sources = [
"//chrome/android/javatests/src/org/chromium/chrome/browser/feed/FeedNetworkBridgeConformanceTest.java",
"//chrome/android/javatests/src/org/chromium/chrome/browser/feed/FeedNewTabPageTest.java",
"//chrome/android/javatests/src/org/chromium/chrome/browser/feed/FeedSchedulerBridgeConformanceTest.java",
"//chrome/android/javatests/src/org/chromium/chrome/browser/feed/FeedRefreshTaskTest.java",
]
......
......@@ -15,7 +15,7 @@
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:layout_marginTop="12dp">
android:layout_marginTop="@dimen/content_suggestions_card_modern_margin">
<FrameLayout
android:layout_width="match_parent"
......
......@@ -31,6 +31,8 @@ import org.chromium.chrome.browser.download.DownloadManagerService;
import org.chromium.chrome.browser.native_page.NativePage;
import org.chromium.chrome.browser.native_page.NativePageHost;
import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
import org.chromium.chrome.browser.ntp.cards.ItemViewType;
import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter;
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.omnibox.LocationBarVoiceRecognitionHandler;
import org.chromium.chrome.browser.profiles.Profile;
......@@ -629,4 +631,22 @@ public class NewTabPage
public NewTabPageManager getManagerForTesting() {
return mNewTabPageManager;
}
@VisibleForTesting
public View getSignInPromoViewForTesting() {
RecyclerView recyclerView = mNewTabPageView.getRecyclerView();
NewTabPageAdapter adapter = (NewTabPageAdapter) recyclerView.getAdapter();
return recyclerView
.findViewHolderForAdapterPosition(
adapter.getFirstPositionForType(ItemViewType.PROMO))
.itemView;
}
@VisibleForTesting
public View getSectionHeaderViewForTesting() {
RecyclerView recyclerView = mNewTabPageView.getRecyclerView();
NewTabPageAdapter adapter = (NewTabPageAdapter) recyclerView.getAdapter();
return recyclerView.findViewHolderForAdapterPosition(adapter.getFirstHeaderPosition())
.itemView;
}
}
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.ntp.cards;
import android.support.annotation.Nullable;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.native_page.ContextMenuManager;
import org.chromium.chrome.browser.signin.DisplayableProfileData;
......@@ -65,12 +66,14 @@ public class PersonalizedPromoViewHolder extends CardViewHolder {
* @param profileData The profile data which will be used to configure the personalized
* signin promo.
*/
@VisibleForTesting
public void bindAndConfigureViewForTests(@Nullable DisplayableProfileData profileData) {
super.onBindViewHolder();
PersonalizedSigninPromoView view = (PersonalizedSigninPromoView) itemView;
mSigninPromoController.setupPromoView(view.getContext(), view, profileData, null);
}
@VisibleForTesting
public void setSigninPromoControllerForTests(@Nullable SigninPromoController controller) {
mSigninPromoController = controller;
}
......
......@@ -168,13 +168,13 @@ public class SignInPromo extends OptionalLeaf {
}
@VisibleForTesting
SigninObserver getSigninObserverForTesting() {
public SigninObserver getSigninObserverForTesting() {
return mSigninObserver;
}
@VisibleForTesting
class SigninObserver implements SignInStateObserver, SignInAllowedObserver,
ProfileDataCache.Observer, AccountsChangeObserver {
public class SigninObserver implements SignInStateObserver, SignInAllowedObserver,
ProfileDataCache.Observer, AccountsChangeObserver {
private final SigninManager mSigninManager;
/** Guards {@link #unregister()}, which can be called multiple times. */
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.feed;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.instanceOf;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.filters.MediumTest;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.ntp.cards.SignInPromo;
import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.suggestions.SiteSuggestion;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.chrome.test.util.NewTabPageTestUtils;
import org.chromium.chrome.test.util.ViewUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
import org.chromium.chrome.test.util.browser.suggestions.FakeMostVisitedSites;
import org.chromium.chrome.test.util.browser.suggestions.SuggestionsDependenciesRule;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.List;
/**
* Tests for {@link FeedNewTabPage} specifically. Other tests can be found in
* {@link org.chromium.chrome.browser.ntp.NewTabPageTest}.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
@Features.DisableFeatures("NetworkPrediction")
@Features.EnableFeatures(ChromeFeatureList.INTEREST_FEED_CONTENT_SUGGESTIONS)
public class FeedNewTabPageTest {
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public SuggestionsDependenciesRule mSuggestionsDeps = new SuggestionsDependenciesRule();
private Tab mTab;
private FeedNewTabPage mNtp;
private ViewGroup mTileGridLayout;
private FakeMostVisitedSites mMostVisitedSites;
private EmbeddedTestServer mTestServer;
private List<SiteSuggestion> mSiteSuggestions;
@Before
public void setUp() throws Exception {
mActivityTestRule.startMainActivityWithURL("about:blank");
FeedNewTabPage.setInTestMode(true);
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mSiteSuggestions = NewTabPageTestUtils.createFakeSiteSuggestions(mTestServer);
mMostVisitedSites = new FakeMostVisitedSites();
mMostVisitedSites.setTileSuggestions(mSiteSuggestions);
mSuggestionsDeps.getFactory().mostVisitedSites = mMostVisitedSites;
mActivityTestRule.loadUrl(UrlConstants.NTP_URL);
mTab = mActivityTestRule.getActivity().getActivityTab();
NewTabPageTestUtils.waitForNtpLoaded(mTab);
Assert.assertTrue(mTab.getNativePage() instanceof FeedNewTabPage);
mNtp = (FeedNewTabPage) mTab.getNativePage();
mTileGridLayout = mNtp.getView().findViewById(R.id.tile_grid_layout);
Assert.assertEquals(mSiteSuggestions.size(), mTileGridLayout.getChildCount());
}
@After
public void tearDown() {
mTestServer.stopAndDestroyServer();
ThreadUtils.runOnUiThreadBlocking(() -> FeedNewTabPage.setInTestMode(false));
}
@Test
@MediumTest
@Feature({"FeedNewTabPage"})
public void testSignInPromo() throws Exception {
SignInPromo.SigninObserver signinObserver = mNtp.getMediatorForTesting()
.getSignInPromoForTesting()
.getSigninObserverForTesting();
RecyclerView recyclerView = (RecyclerView) mNtp.getStream().getView();
// Simulate sign in, scroll to the position where sign-in promo could be placed, and verify
// that sign-in promo is not shown.
ThreadUtils.runOnUiThreadBlocking(signinObserver::onSignedIn);
RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView);
onView(instanceOf(RecyclerView.class)).perform(RecyclerViewActions.scrollToPosition(1));
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
// Simulate sign out, scroll to the position where sign-in promo could be placed, and verify
// that sign-in promo is shown.
ThreadUtils.runOnUiThreadBlocking(signinObserver::onSignedOut);
RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView);
onView(instanceOf(RecyclerView.class)).perform(RecyclerViewActions.scrollToPosition(1));
onView(withId(R.id.signin_promo_view_container)).check(matches(isDisplayed()));
// Scroll to the article section header in case it is not visible.
onView(instanceOf(RecyclerView.class)).perform(RecyclerViewActions.scrollToPosition(2));
// Hide articles and verify that the sign-in promo is not shown.
onView(withId(R.id.header_title)).perform(click());
onView(withId(R.id.signin_promo_view_container)).check(doesNotExist());
// Show articles and verify that the sign-in promo is shown.
onView(withId(R.id.header_title)).perform(click());
onView(withId(R.id.signin_promo_view_container)).check(matches(isDisplayed()));
}
@Test
@MediumTest
@Feature({"FeedNewTabPage"})
public void testArticleSectionHeader() throws Exception {
// Disable the sign-in promo so the header is visible above the fold.
SignInPromo.setDisablePromoForTests(true);
final int expectedHeaderViewsCount = 2;
// Open a new tab.
Tab tab1 = mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL);
FeedNewTabPage ntp1 = (FeedNewTabPage) tab1.getNativePage();
SectionHeader firstHeader = ntp1.getMediatorForTesting().getSectionHeaderForTesting();
RecyclerView.Adapter adapter1 = ((RecyclerView) ntp1.getStream().getView()).getAdapter();
// Check header is expanded.
Assert.assertTrue(firstHeader.isExpandable() && firstHeader.isExpanded());
Assert.assertTrue(adapter1.getItemCount() > expectedHeaderViewsCount);
Assert.assertTrue(getPreferenceForArticleSectionHeader());
// Toggle header on the current tab.
onView(withId(R.id.header_title)).perform(click());
// Check header is collapsed.
Assert.assertTrue(firstHeader.isExpandable() && !firstHeader.isExpanded());
Assert.assertEquals(expectedHeaderViewsCount, adapter1.getItemCount());
Assert.assertFalse(getPreferenceForArticleSectionHeader());
// Open a second new tab.
Tab tab2 = mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL);
FeedNewTabPage ntp2 = (FeedNewTabPage) tab2.getNativePage();
SectionHeader secondHeader = ntp2.getMediatorForTesting().getSectionHeaderForTesting();
RecyclerView.Adapter adapter2 = ((RecyclerView) ntp2.getStream().getView()).getAdapter();
// Check header on the second tab is collapsed.
Assert.assertTrue(secondHeader.isExpandable() && !secondHeader.isExpanded());
Assert.assertEquals(expectedHeaderViewsCount, adapter2.getItemCount());
Assert.assertFalse(getPreferenceForArticleSectionHeader());
// Toggle header on the second tab.
onView(withId(R.id.header_title)).perform(click());
// Check header on the second tab is expanded.
Assert.assertTrue(secondHeader.isExpandable() && secondHeader.isExpanded());
Assert.assertTrue(adapter2.getItemCount() > expectedHeaderViewsCount);
Assert.assertTrue(getPreferenceForArticleSectionHeader());
// Go back to the first tab and wait for a stable recycler view.
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), tab1.getId());
// Check header on the first tab is expanded.
Assert.assertTrue(firstHeader.isExpandable() && firstHeader.isExpanded());
Assert.assertTrue(adapter1.getItemCount() > expectedHeaderViewsCount);
Assert.assertTrue(getPreferenceForArticleSectionHeader());
// Reset state.
SignInPromo.setDisablePromoForTests(false);
}
@Test
@MediumTest
@Feature({"FeedNewTabPage"})
public void testFeedDisabledByPolicy() throws Exception {
// TODO(huayinz): Re-enable the part commented out on this test and replace
// sOverrideFeedEnabledForTesting with the real preference once we have a decision for
// whether to re-enable the Feed on supervised/enterprise account removed within a session.
FeedNewTabPageMediator mediator = mNtp.getMediatorForTesting();
mediator.overrideFeedEnabledForTesting(true);
// Policy is disabled. Verify the NTP root view contains only the Stream view as child.
ViewGroup rootView = (ViewGroup) mNtp.getView();
ViewUtils.waitForStableView(rootView);
Assert.assertNotNull(mNtp.getStream());
Assert.assertNull(mNtp.getScrollViewForPolicy());
Assert.assertEquals(1, rootView.getChildCount());
Assert.assertEquals(mNtp.getStream().getView(), rootView.getChildAt(0));
// Simulate that policy is enabled. Verify the NTP root view contains only the view for
// policy as child.
ThreadUtils.runOnUiThreadBlocking(() -> mediator.updateContentForTesting(false));
ViewUtils.waitForStableView(rootView);
Assert.assertNotNull(mNtp.getScrollViewForPolicy());
Assert.assertNull(mNtp.getStream());
Assert.assertEquals(1, rootView.getChildCount());
Assert.assertEquals(mNtp.getScrollViewForPolicy(), rootView.getChildAt(0));
// Open a new tab while policy is still enabled.
Tab tab2 = mActivityTestRule.loadUrlInNewTab(UrlConstants.NTP_URL);
FeedNewTabPage ntp2 = (FeedNewTabPage) tab2.getNativePage();
ViewGroup rootView2 = (ViewGroup) ntp2.getView();
// Verify that NTP root view contains only the view for policy as child.
ViewUtils.waitForStableView(rootView2);
Assert.assertNotNull(ntp2.getScrollViewForPolicy());
Assert.assertNull(ntp2.getStream());
Assert.assertEquals(1, rootView2.getChildCount());
Assert.assertEquals(ntp2.getScrollViewForPolicy(), rootView2.getChildAt(0));
/*
// Simulate that policy is disabled. Verify the NTP root view contains only the Stream view
// as child.
ThreadUtils.runOnUiThreadBlocking(() -> PrefServiceBridge.getInstance().setBoolean(
Pref.NTP_ARTICLES_SECTION_ENABLED, true));
ViewUtils.waitForStableView(rootView2);
Assert.assertNotNull(ntp2.getStream());
Assert.assertNull(ntp2.getScrollViewForPolicy());
Assert.assertEquals(1, rootView2.getChildCount());
Assert.assertEquals(ntp2.getStream().getView(), rootView2.getChildAt(0));
// Switch to the old tab. Verify the NTP root view contains only the Stream view as child.
ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), mTab.getId());
ViewUtils.waitForStableView(rootView);
Assert.assertNotNull(mNtp.getStream());
Assert.assertNull(mNtp.getScrollViewForPolicy());
Assert.assertEquals(1, rootView.getChildCount());
Assert.assertEquals(mNtp.getStream().getView(), rootView.getChildAt(0));
*/
// Reset state.
mediator.overrideFeedEnabledForTesting(false);
}
private boolean getPreferenceForArticleSectionHeader() throws Exception {
return ThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().getBoolean(Pref.NTP_ARTICLES_LIST_VISIBLE));
}
}
......@@ -8,9 +8,12 @@ import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.hamcrest.Matchers.instanceOf;
import android.content.ComponentCallbacks2;
import android.graphics.Canvas;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
......@@ -56,9 +59,6 @@ import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.suggestions.SiteSuggestion;
import org.chromium.chrome.browser.suggestions.TileSectionType;
import org.chromium.chrome.browser.suggestions.TileSource;
import org.chromium.chrome.browser.suggestions.TileTitleSource;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
......@@ -87,7 +87,6 @@ import org.chromium.ui.base.PageTransition;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
......@@ -147,32 +146,7 @@ public class NewTabPageTest {
public void setUp() throws Exception {
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
mSiteSuggestions = new ArrayList<>();
mSiteSuggestions.add(new SiteSuggestion("0 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#0",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("1 WHITELIST", mTestServer.getURL(TEST_PAGE) + "#1",
"/test.png", TileTitleSource.UNKNOWN, TileSource.WHITELIST,
TileSectionType.PERSONALIZED, new Date()));
mSiteSuggestions.add(new SiteSuggestion("2 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#2",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("3 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#3",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("4 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#4",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("5 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#5",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("6 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#6",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions.add(new SiteSuggestion("7 TOP_SITES", mTestServer.getURL(TEST_PAGE) + "#7",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
mSiteSuggestions = NewTabPageTestUtils.createFakeSiteSuggestions(mTestServer);
mMostVisitedSites = new FakeMostVisitedSites();
mMostVisitedSites.setTileSuggestions(mSiteSuggestions);
mSuggestionsDeps.getFactory().mostVisitedSites = mMostVisitedSites;
......@@ -221,6 +195,44 @@ public class NewTabPageTest {
mRenderTestRule.render(mNtp.getView().getRootView(), "simplified_new_tab_page");
}
@Test
@SmallTest
@Feature({"NewTabPage", "FeedNewTabPage", "RenderTest"})
@EnableFeatures({ChromeFeatureList.CONTENT_SUGGESTIONS_SCROLL_TO_LOAD})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testRender_FocusFakeBox(boolean interestFeedEnabled) throws Exception {
onView(withId(R.id.search_box)).perform(click());
mRenderTestRule.render(mNtp.getView().getRootView(), "focus_fake_box");
}
@Test
@SmallTest
@Feature({"NewTabPage", "FeedNewTabPage", "RenderTest"})
@EnableFeatures({ChromeFeatureList.CONTENT_SUGGESTIONS_SCROLL_TO_LOAD})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testRender_SignInPromo(boolean interestFeedEnabled) throws Exception {
// Scroll to the sign in promo in case it is not visible.
onView(instanceOf(RecyclerView.class)).perform(RecyclerViewActions.scrollToPosition(1));
mRenderTestRule.render(mNtp.getSignInPromoViewForTesting(), "sign_in_promo");
}
@Test
@SmallTest
@Feature({"NewTabPage", "FeedNewTabPage", "RenderTest"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testRender_ArticleSectionHeader(boolean interestFeedEnabled) throws Exception {
// Scroll to the article section header in case it is not visible.
onView(instanceOf(RecyclerView.class)).perform(RecyclerViewActions.scrollToPosition(2));
View view = mNtp.getSectionHeaderViewForTesting();
// Check header is expanded.
mRenderTestRule.render(view, "expandable_header_expanded");
// Toggle header on the current tab.
onView(withId(R.id.header_title)).perform(click());
// Check header is collapsed.
mRenderTestRule.render(view, "expandable_header_collapsed");
}
@Test
@MediumTest
@Feature({"NewTabPage"})
......@@ -267,8 +279,9 @@ public class NewTabPageTest {
*/
@Test
@SmallTest
@Feature({"NewTabPage"})
public void testFocusFakebox() {
@Feature({"NewTabPage", "FeedNewTabPage"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testFocusFakebox(boolean interestFeedEnabled) {
int initialFakeboxTop = getFakeboxTop(mNtp);
TouchCommon.singleClickView(mFakebox);
......@@ -289,9 +302,10 @@ public class NewTabPageTest {
*/
@Test
@SmallTest
@Feature({"NewTabPage"})
@Feature({"NewTabPage", "FeedNewTabPage"})
@DisableIf.Build(sdk_is_greater_than = 22, message = "crbug.com/593007")
public void testSearchFromFakebox() throws InterruptedException {
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testSearchFromFakebox(boolean interestFeedEnabled) throws InterruptedException {
TouchCommon.singleClickView(mFakebox);
waitForFakeboxFocusAnimationComplete(mNtp);
final UrlBar urlBar = (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar);
......@@ -316,8 +330,9 @@ public class NewTabPageTest {
*/
@Test
@SmallTest
@Feature({"NewTabPage"})
public void testClickMostVisitedItem() throws InterruptedException {
@Feature({"NewTabPage", "FeedNewTabPage"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testClickMostVisitedItem(boolean interestFeedEnabled) throws InterruptedException {
ChromeTabUtils.waitForTabPageLoaded(mTab, new Runnable() {
@Override
public void run() {
......@@ -334,8 +349,10 @@ public class NewTabPageTest {
@Test
@DisabledTest // Flaked on the try bot. http://crbug.com/543138
@SmallTest
@Feature({"NewTabPage"})
public void testOpenMostVisitedItemInNewTab() throws InterruptedException, ExecutionException {
@Feature({"NewTabPage", "FeedNewTabPage"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testOpenMostVisitedItemInNewTab(boolean interestFeedEnabled)
throws InterruptedException, ExecutionException {
ChromeTabUtils.invokeContextMenuAndOpenInANewTab(mActivityTestRule,
mTileGridLayout.getChildAt(0), ContextMenuManager.ContextMenuItemId.OPEN_IN_NEW_TAB,
false, mSiteSuggestions.get(0).url);
......@@ -380,8 +397,10 @@ public class NewTabPageTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testUrlFocusAnimationsDisabledOnLoad() throws InterruptedException {
@Feature({"NewTabPage", "FeedNewTabPage"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testUrlFocusAnimationsDisabledOnLoad(boolean interestFeedEnabled)
throws InterruptedException {
Assert.assertFalse(getUrlFocusAnimationsDisabled());
ChromeTabUtils.waitForTabPageLoaded(mTab, new Runnable() {
@Override
......@@ -405,8 +424,10 @@ public class NewTabPageTest {
@Test
@LargeTest
@Feature({"NewTabPage"})
public void testUrlFocusAnimationsEnabledOnFailedLoad() throws Exception {
@Feature({"NewTabPage", "FeedNewTabPage"})
@ParameterAnnotations.UseMethodParameter(InterestFeedParams.class)
public void testUrlFocusAnimationsEnabledOnFailedLoad(boolean interestFeedEnabled)
throws Exception {
// TODO(jbudorick): switch this to EmbeddedTestServer.
TestWebServer webServer = TestWebServer.start();
try {
......@@ -621,27 +642,6 @@ public class NewTabPageTest {
SignInPromo.setDisablePromoForTests(false);
}
@Test
@SmallTest
@Feature({"NewTabPage", "RenderTest"})
public void testArticleExpandableHeaderAppearance() throws Exception {
NewTabPage ntp =
(NewTabPage) mActivityTestRule.getActivity().getActivityTab().getNativePage();
RecyclerView recyclerView = ntp.getNewTabPageView().getRecyclerView();
NewTabPageAdapter adapter = (NewTabPageAdapter) recyclerView.getAdapter();
int position = adapter.getFirstHeaderPosition();
RecyclerViewTestUtils.scrollToView(recyclerView, position);
RecyclerViewTestUtils.waitForStableRecyclerView(recyclerView);
View view = recyclerView.findViewHolderForAdapterPosition(position).itemView;
// Check header is expanded.
mRenderTestRule.render(view, "expandable_header_expanded");
// Toggle header on the current tab.
onView(withId(R.id.header_title)).perform(click());
// Check header is collapsed.
mRenderTestRule.render(view, "expandable_header_collapsed");
}
@Test
@SmallTest
@Feature({"NewTabPage", "FeedNewTabPage"})
......
......@@ -9,14 +9,24 @@ import android.os.Build;
import org.chromium.chrome.browser.ntp.IncognitoNewTabPage;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.suggestions.SiteSuggestion;
import org.chromium.chrome.browser.suggestions.TileSectionType;
import org.chromium.chrome.browser.suggestions.TileSource;
import org.chromium.chrome.browser.suggestions.TileTitleSource;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* Utilities for testing the NTP.
*/
public class NewTabPageTestUtils {
private static final String TEST_PAGE = "/chrome/test/data/android/navigate/simple.html";
/**
* Waits for the NTP owned by the passed in tab to be fully loaded.
......@@ -45,4 +55,32 @@ public class NewTabPageTestUtils {
});
}
public static List<SiteSuggestion> createFakeSiteSuggestions(EmbeddedTestServer testServer) {
List<SiteSuggestion> siteSuggestions = new ArrayList<>();
siteSuggestions.add(new SiteSuggestion("0 TOP_SITES", testServer.getURL(TEST_PAGE) + "#0",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("1 WHITELIST", testServer.getURL(TEST_PAGE) + "#1",
"/test.png", TileTitleSource.UNKNOWN, TileSource.WHITELIST,
TileSectionType.PERSONALIZED, new Date()));
siteSuggestions.add(new SiteSuggestion("2 TOP_SITES", testServer.getURL(TEST_PAGE) + "#2",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("3 TOP_SITES", testServer.getURL(TEST_PAGE) + "#3",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("4 TOP_SITES", testServer.getURL(TEST_PAGE) + "#4",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("5 TOP_SITES", testServer.getURL(TEST_PAGE) + "#5",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("6 TOP_SITES", testServer.getURL(TEST_PAGE) + "#6",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
siteSuggestions.add(new SiteSuggestion("7 TOP_SITES", testServer.getURL(TEST_PAGE) + "#7",
"", TileTitleSource.TITLE_TAG, TileSource.TOP_SITES, TileSectionType.PERSONALIZED,
new Date()));
return siteSuggestions;
}
}
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