Commit f3ccd6a7 authored by Theresa's avatar Theresa Committed by Commit Bot

Another attempt to deflake NewTabPageTest

Replace sending motion events to perform a long click with a direct call
to View#performLongClick. Locally this fixes the weird blue highlighting
after sending motion events.

BUG=813589

Change-Id: I36ebfa69eedbd169bab2a1625963e14cf822b99b
Reviewed-on: https://chromium-review.googlesource.com/976051Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545868}
parent 6f8d7da0
......@@ -79,6 +79,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
......@@ -319,7 +320,7 @@ public class NewTabPageTest {
@DisabledTest // Flaked on the try bot. http://crbug.com/543138
@SmallTest
@Feature({"NewTabPage"})
public void testOpenMostVisitedItemInNewTab() throws InterruptedException {
public void testOpenMostVisitedItemInNewTab() throws InterruptedException, ExecutionException {
invokeContextMenuAndOpenInANewTab(mTileGridLayout.getChildAt(0),
ContextMenuManager.ID_OPEN_IN_NEW_TAB, false, mSiteSuggestions.get(0).url);
}
......@@ -330,7 +331,8 @@ public class NewTabPageTest {
@Test
@SmallTest
@Feature({"NewTabPage"})
public void testOpenMostVisitedItemInIncognitoTab() throws InterruptedException {
public void testOpenMostVisitedItemInIncognitoTab()
throws InterruptedException, ExecutionException {
invokeContextMenuAndOpenInANewTab(mTileGridLayout.getChildAt(0),
ContextMenuManager.ID_OPEN_IN_INCOGNITO_TAB, true, mSiteSuggestions.get(0).url);
}
......@@ -341,14 +343,15 @@ public class NewTabPageTest {
@Test
@SmallTest
@Feature({"NewTabPage"})
public void testRemoveMostVisitedItem() {
public void testRemoveMostVisitedItem() throws ExecutionException {
SiteSuggestion testSite = mSiteSuggestions.get(0);
View mostVisitedItem = mTileGridLayout.getChildAt(0);
ArrayList<View> views = new ArrayList<>();
mTileGridLayout.findViewsWithText(views, testSite.title, View.FIND_VIEWS_WITH_TEXT);
Assert.assertEquals(1, views.size());
TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), mostVisitedItem);
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), mostVisitedItem);
Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), ContextMenuManager.ID_REMOVE, 0));
......@@ -656,8 +659,9 @@ public class NewTabPageTest {
* @param expectIncognito Whether the opened tab is expected to be incognito.
* @param expectedUrl The expected url for the new tab.
*/
private void invokeContextMenuAndOpenInANewTab(View view, int contextMenuItemId,
boolean expectIncognito, final String expectedUrl) throws InterruptedException {
private void invokeContextMenuAndOpenInANewTab(
View view, int contextMenuItemId, boolean expectIncognito, final String expectedUrl)
throws InterruptedException, ExecutionException {
final CallbackHelper createdCallback = new CallbackHelper();
final TabModel tabModel =
mActivityTestRule.getActivity().getTabModelSelector().getModel(expectIncognito);
......@@ -671,7 +675,8 @@ public class NewTabPageTest {
}
});
TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), view);
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), view);
Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), contextMenuItemId, 0));
......
......@@ -31,6 +31,7 @@ import org.chromium.content_public.common.ContentUrlConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* Instrumentation tests for {@link RecentTabsPage}.
......@@ -64,7 +65,7 @@ public class RecentTabsPageTest {
@Test
@MediumTest
@Feature({"RecentTabsPage"})
public void testRecentlyClosedTabs() throws InterruptedException {
public void testRecentlyClosedTabs() throws InterruptedException, ExecutionException {
// Set a recently closed tab and confirm a view is rendered for it.
List<RecentlyClosedTab> tabs = setRecentlyClosedTabs(1);
Assert.assertEquals(1, mManager.getRecentlyClosedTabs(1).size());
......@@ -149,8 +150,9 @@ public class RecentTabsPageTest {
});
}
private void invokeContextMenu(View view, int contextMenuItemId) {
TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), view);
private void invokeContextMenu(View view, int contextMenuItemId) throws ExecutionException {
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), view);
Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), contextMenuItemId, 0));
}
......
......@@ -56,6 +56,7 @@ import org.chromium.ui.test.util.UiRestriction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
......@@ -180,7 +181,7 @@ public class NewTabPageRecyclerViewTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissArticleWithContextMenu() throws InterruptedException, TimeoutException {
public void testDismissArticleWithContextMenu() throws Exception {
setSuggestionsAndWaitForUpdate(10);
List<SnippetArticle> suggestions = mSource.getSuggestionsForCategory(TEST_CATEGORY);
assertEquals(10, suggestions.size());
......@@ -200,8 +201,7 @@ public class NewTabPageRecyclerViewTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissStatusCardWithContextMenu()
throws InterruptedException, TimeoutException {
public void testDismissStatusCardWithContextMenu() throws Exception {
setSuggestionsAndWaitForUpdate(0);
assertArrayEquals(new int[] {TEST_CATEGORY}, mSource.getCategories());
......@@ -221,8 +221,7 @@ public class NewTabPageRecyclerViewTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissActionItemWithContextMenu()
throws InterruptedException, TimeoutException {
public void testDismissActionItemWithContextMenu() throws Exception {
setSuggestionsAndWaitForUpdate(0);
assertArrayEquals(new int[] {TEST_CATEGORY}, mSource.getCategories());
......@@ -396,8 +395,9 @@ public class NewTabPageRecyclerViewTest {
return suggestions;
}
private void invokeContextMenu(View view, int contextMenuItemId) {
TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), view);
private void invokeContextMenu(View view, int contextMenuItemId) throws ExecutionException {
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), view);
assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), contextMenuItemId, 0));
}
......
......@@ -29,6 +29,8 @@ import org.chromium.chrome.test.util.browser.suggestions.SuggestionsDependencies
import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.ui.test.util.UiRestriction;
import java.util.concurrent.ExecutionException;
/**
* Instrumentation tests for {@link SuggestionsBottomSheetContent}.
*/
......@@ -52,12 +54,12 @@ public class SuggestionsBottomSheetTest {
@Test
@RetryOnFailure
@MediumTest
public void testContextMenu() throws InterruptedException {
public void testContextMenu() throws InterruptedException, ExecutionException {
ViewHolder suggestionViewHolder =
mActivityRule.scrollToFirstItemOfType(ItemViewType.SNIPPET);
assertFalse(mActivityRule.getBottomSheet().onInterceptTouchEvent(createTapEvent()));
TestTouchUtils.longClickView(
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), suggestionViewHolder.itemView);
assertTrue(mActivityRule.getBottomSheet().onInterceptTouchEvent(createTapEvent()));
......
......@@ -43,6 +43,7 @@ import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
......@@ -99,7 +100,7 @@ public class TileGroupTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissTileWithContextMenu() throws InterruptedException, TimeoutException {
public void testDismissTileWithContextMenu() throws Exception {
SiteSuggestion siteToDismiss = mMostVisitedSites.getCurrentSites().get(0);
final View tileView = getTileViewFor(siteToDismiss);
......@@ -123,7 +124,7 @@ public class TileGroupTest {
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissTileUndo() throws InterruptedException, TimeoutException {
public void testDismissTileUndo() throws Exception {
SiteSuggestion siteToDismiss = mMostVisitedSites.getCurrentSites().get(0);
final ViewGroup tileContainer = getTileGridLayout();
final View tileView = getTileViewFor(siteToDismiss);
......@@ -185,8 +186,9 @@ public class TileGroupTest {
return tileView;
}
private void invokeContextMenu(View view, int contextMenuItemId) {
TestTouchUtils.longClickView(InstrumentationRegistry.getInstrumentation(), view);
private void invokeContextMenu(View view, int contextMenuItemId) throws ExecutionException {
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), view);
Assert.assertTrue(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), contextMenuItemId, 0));
}
......
......@@ -10,6 +10,10 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import org.chromium.base.ThreadUtils;
import java.util.concurrent.ExecutionException;
/**
* Collection of utilities for generating touch events.
* Based on android.test.TouchUtils, but slightly more flexible (allows to
......@@ -135,7 +139,7 @@ public class TestTouchUtils {
}
/**
* Drags / moves (synchronously) to the specified coordinates. Normally preceeded by
* Drags / moves (synchronously) to the specified coordinates. Normally preceded by
* dragStart() and followed by dragEnd()
*
* @param instrumentation Instrumentation object used by the test.
......@@ -161,7 +165,7 @@ public class TestTouchUtils {
/**
* Finishes (synchronously) a drag / move at the specified coordinate.
* Normally preceeded by dragStart() and dragTo().
* Normally preceded by dragStart() and dragTo().
*
* @param instrumentation Instrumentation object used by the test.
* @param x The x location.
......@@ -201,11 +205,17 @@ public class TestTouchUtils {
* @param v The view to call performClick on.
*/
public static void performClickOnMainSync(Instrumentation instrumentation, final View v) {
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
v.performClick();
}
});
instrumentation.runOnMainSync(() -> v.performClick());
}
/**
* Calls performLongClick on a View on the main UI thread.
*
* @param instrumentation Instrumentation object used by the test.
* @param v The view to call performLongClick on.
*/
public static void performLongClickOnMainSync(Instrumentation instrumentation, final View v)
throws ExecutionException {
ThreadUtils.runOnUiThreadBlocking(() -> v.performLongClick());
}
}
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