| Index: chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java
|
| index 9b9bedaa77d97d63e25a0b2c798e21bb3c71f5f2..69398e01d9b48103d2d941dbe69447b72c046f5a 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java
|
| @@ -4,24 +4,36 @@
|
|
|
| package org.chromium.chrome.browser.suggestions;
|
|
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.MediumTest;
|
| import android.view.View;
|
| import android.view.ViewGroup;
|
| import android.widget.TextView;
|
|
|
| +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.CallbackHelper;
|
| +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.ChromeActivity;
|
| +import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.UrlConstants;
|
| import org.chromium.chrome.browser.ntp.ContextMenuManager;
|
| import org.chromium.chrome.browser.ntp.NewTabPage;
|
| import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView;
|
| import org.chromium.chrome.browser.snackbar.SnackbarManager;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| -import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
|
| import org.chromium.chrome.test.util.NewTabPageTestUtils;
|
| import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
|
| import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource;
|
| @@ -35,8 +47,16 @@ import java.util.concurrent.TimeoutException;
|
| /**
|
| * Instrumentation tests for {@link TileGroup} on the New Tab Page.
|
| */
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({
|
| + ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
|
| +})
|
| @RetryOnFailure
|
| -public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
| +public class TileGroupTest {
|
| + @Rule
|
| + public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
|
| +
|
| private static final String[] FAKE_MOST_VISITED_URLS =
|
| new String[] {"/chrome/test/data/android/navigate/one.html",
|
| "/chrome/test/data/android/navigate/two.html",
|
| @@ -47,9 +67,10 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
| private FakeMostVisitedSites mMostVisitedSites;
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(
|
| + InstrumentationRegistry.getInstrumentation().getContext());
|
|
|
| mSiteSuggestionUrls = new String[] {mTestServer.getURL(FAKE_MOST_VISITED_URLS[0]),
|
| mTestServer.getURL(FAKE_MOST_VISITED_URLS[1]),
|
| @@ -62,30 +83,25 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
| FakeSuggestionsSource mSource = new FakeSuggestionsSource();
|
| NewTabPage.setSuggestionsSourceForTests(mSource);
|
|
|
| - super.setUp();
|
| + mActivityTestRule.startMainActivityWithURL(UrlConstants.NTP_URL);
|
| + Tab mTab = mActivityTestRule.getActivity().getActivityTab();
|
| + NewTabPageTestUtils.waitForNtpLoaded(mTab);
|
| +
|
| + Assert.assertTrue(mTab.getNativePage() instanceof NewTabPage);
|
| + mNtp = (NewTabPage) mTab.getNativePage();
|
| +
|
| + RecyclerViewTestUtils.waitForStableRecyclerView(getRecyclerView());
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| + @After
|
| + public void tearDown() throws Exception {
|
| TileGroupDelegateImpl.setMostVisitedSitesForTests(null);
|
| NewTabPage.setSuggestionsSourceForTests(null);
|
| mTestServer.stopAndDestroyServer();
|
|
|
| - super.tearDown();
|
| - }
|
| -
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityWithURL(UrlConstants.NTP_URL);
|
| - Tab mTab = getActivity().getActivityTab();
|
| - NewTabPageTestUtils.waitForNtpLoaded(mTab);
|
| -
|
| - assertTrue(mTab.getNativePage() instanceof NewTabPage);
|
| - mNtp = (NewTabPage) mTab.getNativePage();
|
| -
|
| - RecyclerViewTestUtils.waitForStableRecyclerView(getRecyclerView());
|
| }
|
|
|
| + @Test
|
| @MediumTest
|
| @Feature({"NewTabPage"})
|
| public void testDismissTileWithContextMenu() throws InterruptedException, TimeoutException {
|
| @@ -93,21 +109,22 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
|
|
| // Dismiss the tile using the context menu.
|
| invokeContextMenu(tileView, ContextMenuManager.ID_REMOVE);
|
| - assertTrue(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
| + Assert.assertTrue(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
|
|
| // Ensure that undoing the removal is reflected in the ui.
|
| - assertEquals(3, getTileGridLayout().getChildCount());
|
| + Assert.assertEquals(3, getTileGridLayout().getChildCount());
|
| mMostVisitedSites.setTileSuggestions(mSiteSuggestionUrls[1], mSiteSuggestionUrls[2]);
|
| waitForTileRemoved(mSiteSuggestionUrls[0]);
|
| - assertEquals(2, getTileGridLayout().getChildCount());
|
| + Assert.assertEquals(2, getTileGridLayout().getChildCount());
|
| }
|
|
|
| + @Test
|
| @MediumTest
|
| @Feature({"NewTabPage"})
|
| public void testDismissTileUndo() throws InterruptedException, TimeoutException {
|
| final ViewGroup tileContainer = getTileGridLayout();
|
| final View tileView = getTileViewForUrl(mSiteSuggestionUrls[0]);
|
| - assertEquals(3, tileContainer.getChildCount());
|
| + Assert.assertEquals(3, tileContainer.getChildCount());
|
|
|
| // Dismiss the tile using the context menu.
|
| invokeContextMenu(tileView, ContextMenuManager.ID_REMOVE);
|
| @@ -115,10 +132,10 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
| // Ensure that the removal update goes through.
|
| mMostVisitedSites.setTileSuggestions(mSiteSuggestionUrls[1], mSiteSuggestionUrls[2]);
|
| waitForTileRemoved(mSiteSuggestionUrls[0]);
|
| - assertEquals(2, tileContainer.getChildCount());
|
| - final View snackbarButton = waitForSnackbar(getActivity());
|
| + Assert.assertEquals(2, tileContainer.getChildCount());
|
| + final View snackbarButton = waitForSnackbar(mActivityTestRule.getActivity());
|
|
|
| - assertTrue(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
| + Assert.assertTrue(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
| ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| @@ -126,12 +143,12 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
| }
|
| });
|
|
|
| - assertFalse(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
| + Assert.assertFalse(mMostVisitedSites.isUrlBlacklisted(mSiteSuggestionUrls[0]));
|
|
|
| // Ensure that the removal of the update goes through.
|
| mMostVisitedSites.setTileSuggestions(mSiteSuggestionUrls);
|
| waitForTileAdded(mSiteSuggestionUrls[0]);
|
| - assertEquals(3, tileContainer.getChildCount());
|
| + Assert.assertEquals(3, tileContainer.getChildCount());
|
| }
|
|
|
| private NewTabPageRecyclerView getRecyclerView() {
|
| @@ -140,25 +157,25 @@ public class TileGroupTest extends ChromeTabbedActivityTestBase {
|
|
|
| private TileGridLayout getTileGridLayout() {
|
| ViewGroup aboveTheFoldView = getRecyclerView().getAboveTheFoldView();
|
| - assertNotNull("Unable to retrieve the AboveTheFold view.", aboveTheFoldView);
|
| + Assert.assertNotNull("Unable to retrieve the AboveTheFold view.", aboveTheFoldView);
|
|
|
| TileGridLayout tileGridLayout =
|
| (TileGridLayout) aboveTheFoldView.findViewById(R.id.tile_grid_layout);
|
| - assertNotNull("Unable to retrieve the TileGridLayout.", tileGridLayout);
|
| + Assert.assertNotNull("Unable to retrieve the TileGridLayout.", tileGridLayout);
|
| return tileGridLayout;
|
| }
|
|
|
| private View getTileViewForUrl(String url) {
|
| View tileView = getTileGridLayout().getTileView(url);
|
| - assertNotNull("Tile not found for url " + url, tileView);
|
| + Assert.assertNotNull("Tile not found for url " + url, tileView);
|
|
|
| return tileView;
|
| }
|
|
|
| private void invokeContextMenu(View view, int contextMenuItemId) {
|
| - TestTouchUtils.longClickView(getInstrumentation(), view);
|
| - assertTrue(
|
| - getInstrumentation().invokeContextMenuAction(getActivity(), contextMenuItemId, 0));
|
| + TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), view);
|
| + Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
|
| + mActivityTestRule.getActivity(), contextMenuItemId, 0));
|
| }
|
|
|
| /** Wait for the snackbar associated to a tile dismissal to be shown and returns its button. */
|
|
|