Commit 5c9a7b68 authored by Matt Jones's avatar Matt Jones Committed by Commit Bot

Attempt to resolve more flakes in TabsTest

Tests still flake occasionally post https://crrev.com/c/2128790,
this patch does the following:

- Dispatches events to the control container directly.
- Accesses the toolbar via the ToolbarManager rather than by lookup.
- Increases the number of "move" events sent to the view.

Bug: 813584
Change-Id: I71f15318354842bd0462d478941e92c35e0e7728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132846Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755563}
parent b9e7313b
...@@ -1617,9 +1617,9 @@ public class TabsTest { ...@@ -1617,9 +1617,9 @@ public class TabsTest {
} }
}); });
int callLayouChangeCount = staticLayoutCallbackHelper.getCallCount(); int callLayoutChangeCount = staticLayoutCallbackHelper.getCallCount();
performToolbarSideSwipe(direction); performToolbarSideSwipe(direction);
staticLayoutCallbackHelper.waitForCallback(callLayouChangeCount, 1); staticLayoutCallbackHelper.waitForCallback(callLayoutChangeCount, 1);
if (expectsSelection) selectCallback.waitForCallback(tabSelectedCallCount, 1); if (expectsSelection) selectCallback.waitForCallback(tabSelectedCallCount, 1);
TestThreadUtils.runOnUiThreadBlocking(() -> observer.destroy()); TestThreadUtils.runOnUiThreadBlocking(() -> observer.destroy());
...@@ -1631,7 +1631,7 @@ public class TabsTest { ...@@ -1631,7 +1631,7 @@ public class TabsTest {
private void performToolbarSideSwipe(@ScrollDirection int direction) { private void performToolbarSideSwipe(@ScrollDirection int direction) {
Assert.assertTrue("Unexpected direction for side swipe " + direction, Assert.assertTrue("Unexpected direction for side swipe " + direction,
direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT); direction == ScrollDirection.LEFT || direction == ScrollDirection.RIGHT);
final View toolbar = mActivityTestRule.getActivity().findViewById(R.id.toolbar); final View toolbar = mActivityTestRule.getActivity().getToolbarManager().getToolbarView();
int[] toolbarPos = new int[2]; int[] toolbarPos = new int[2];
toolbar.getLocationOnScreen(toolbarPos); toolbar.getLocationOnScreen(toolbarPos);
final int width = toolbar.getWidth(); final int width = toolbar.getWidth();
...@@ -1640,12 +1640,16 @@ public class TabsTest { ...@@ -1640,12 +1640,16 @@ public class TabsTest {
final int fromX = toolbarPos[0] + width / 2; final int fromX = toolbarPos[0] + width / 2;
final int toX = toolbarPos[0] + (direction == ScrollDirection.LEFT ? 0 : width); final int toX = toolbarPos[0] + (direction == ScrollDirection.LEFT ? 0 : width);
final int y = toolbarPos[1] + height / 2; final int y = toolbarPos[1] + height / 2;
final int stepCount = 10; final int stepCount = 25;
View toolbarRoot = mActivityTestRule.getActivity()
.getFullscreenManager()
.getControlContainer()
.getView();
long downTime = SystemClock.uptimeMillis(); long downTime = SystemClock.uptimeMillis();
TouchCommon.dragStart(mActivityTestRule.getActivity(), fromX, y, downTime); TouchCommon.dragStart(toolbarRoot, fromX, y, downTime);
TouchCommon.dragTo(mActivityTestRule.getActivity(), fromX, toX, y, y, stepCount, downTime); TouchCommon.dragTo(toolbarRoot, fromX, toX, y, y, stepCount, downTime);
TouchCommon.dragEnd(mActivityTestRule.getActivity(), toX, y, downTime); TouchCommon.dragEnd(toolbarRoot, toX, y, downTime);
} }
/** /**
......
...@@ -27,36 +27,46 @@ public class TouchCommon { ...@@ -27,36 +27,46 @@ public class TouchCommon {
/** /**
* Starts (synchronously) a drag motion. Normally followed by dragTo() and dragEnd(). * Starts (synchronously) a drag motion. Normally followed by dragTo() and dragEnd().
* *
* @activity activity The activity where the touch action is being performed. * @param view The view to dispatch the events to.
* @param x X coordinate, in screen coordinates. * @param x X coordinate, in screen coordinates.
* @param y Y coordinate, in screen coordinates. * @param y Y coordinate, in screen coordinates.
* @param downTime When the drag was started, in millis since the epoch. * @param downTime When the drag was started, in millis since the epoch.
*/ */
public static void dragStart(Activity activity, float x, float y, long downTime) { public static void dragStart(View view, float x, float y, long downTime) {
View root = getRootViewForActivity(activity); float[] windowXY = screenToWindowCoordinates(view, x, y);
float[] windowXY = screenToWindowCoordinates(root, x, y);
float windowX = windowXY[0]; float windowX = windowXY[0];
float windowY = windowXY[1]; float windowY = windowXY[1];
MotionEvent event = MotionEvent.obtain( MotionEvent event = MotionEvent.obtain(
downTime, downTime, MotionEvent.ACTION_DOWN, windowX, windowY, 0); downTime, downTime, MotionEvent.ACTION_DOWN, windowX, windowY, 0);
dispatchTouchEvent(root, event); dispatchTouchEvent(view, event);
}
/**
* Starts (synchronously) a drag motion. Normally followed by dragTo() and dragEnd().
*
* @activity activity The activity where the touch action is being performed.
* @param x X coordinate, in screen coordinates.
* @param y Y coordinate, in screen coordinates.
* @param downTime When the drag was started, in millis since the epoch.
*/
public static void dragStart(Activity activity, float x, float y, long downTime) {
dragStart(getRootViewForActivity(activity), x, y, downTime);
} }
/** /**
* Drags / moves (synchronously) to the specified coordinates. Normally preceeded by * Drags / moves (synchronously) to the specified coordinates. Normally preceeded by
* dragStart() and followed by dragEnd() * dragStart() and followed by dragEnd()
* *
* @activity activity The activity where the touch action is being performed. * @param view The view to dispatch events to.
* @param fromX X coordinate of the initial touch, in screen coordinates. * @param fromX X coordinate of the initial touch, in screen coordinates.
* @param toX Xcoordinate of the drag destination, in screen coordinates. * @param toX X coordinate of the drag destination, in screen coordinates.
* @param fromY X coordinate of the initial touch, in screen coordinates. * @param fromY X coordinate of the initial touch, in screen coordinates.
* @param toY Y coordinate of the drag destination, in screen coordinates. * @param toY Y coordinate of the drag destination, in screen coordinates.
* @param stepCount How many move steps to include in the drag. * @param stepCount How many move steps to include in the drag.
* @param downTime When the drag was started, in millis since the epoch. * @param downTime When the drag was started, in millis since the epoch.
*/ */
public static void dragTo(Activity activity, float fromX, float toX, float fromY, float toY, public static void dragTo(View view, float fromX, float toX, float fromY, float toY,
int stepCount, long downTime) { int stepCount, long downTime) {
View rootView = getRootViewForActivity(activity);
float x = fromX; float x = fromX;
float y = fromY; float y = fromY;
float yStep = (toY - fromY) / stepCount; float yStep = (toY - fromY) / stepCount;
...@@ -65,33 +75,62 @@ public class TouchCommon { ...@@ -65,33 +75,62 @@ public class TouchCommon {
y += yStep; y += yStep;
x += xStep; x += xStep;
long eventTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis();
float[] windowXY = screenToWindowCoordinates(rootView, x, y); float[] windowXY = screenToWindowCoordinates(view, x, y);
float windowX = windowXY[0]; float windowX = windowXY[0];
float windowY = windowXY[1]; float windowY = windowXY[1];
MotionEvent event = MotionEvent.obtain( MotionEvent event = MotionEvent.obtain(
downTime, eventTime, MotionEvent.ACTION_MOVE, windowX, windowY, 0); downTime, eventTime, MotionEvent.ACTION_MOVE, windowX, windowY, 0);
dispatchTouchEvent(rootView, event); dispatchTouchEvent(view, event);
} }
} }
/** /**
* Finishes (synchronously) a drag / move at the specified coordinate. * Drags / moves (synchronously) to the specified coordinates. Normally preceded by
* Normally preceeded by dragStart() and dragTo(). * dragStart() and followed by dragEnd()
* *
* @activity activity The activity where the touch action is being performed. * @activity activity The activity where the touch action is being performed.
* @param fromX X coordinate of the initial touch, in screen coordinates.
* @param toX X coordinate of the drag destination, in screen coordinates.
* @param fromY X coordinate of the initial touch, in screen coordinates.
* @param toY Y coordinate of the drag destination, in screen coordinates.
* @param stepCount How many move steps to include in the drag.
* @param downTime When the drag was started, in millis since the epoch.
*/
public static void dragTo(Activity activity, float fromX, float toX, float fromY, float toY,
int stepCount, long downTime) {
dragTo(getRootViewForActivity(activity), fromX, toX, fromY, toY, stepCount, downTime);
}
/**
* Finishes (synchronously) a drag / move at the specified coordinate.
* Normally preceded by dragStart() and dragTo().
*
* @param view The view to dispatch events to.
* @param x X coordinate, in screen coordinates. * @param x X coordinate, in screen coordinates.
* @param y Y coordinate, in screen coordinates. * @param y Y coordinate, in screen coordinates.
* @param downTime When the drag was started, in millis since the epoch. * @param downTime When the drag was started, in millis since the epoch.
*/ */
public static void dragEnd(Activity activity, float x, float y, long downTime) { public static void dragEnd(View view, float x, float y, long downTime) {
View root = getRootViewForActivity(activity); float[] windowXY = screenToWindowCoordinates(view, x, y);
float[] windowXY = screenToWindowCoordinates(root, x, y);
float windowX = windowXY[0]; float windowX = windowXY[0];
float windowY = windowXY[1]; float windowY = windowXY[1];
long eventTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent event =
MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, windowX, windowY, 0); MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, windowX, windowY, 0);
dispatchTouchEvent(root, event); dispatchTouchEvent(view, event);
}
/**
* Finishes (synchronously) a drag / move at the specified coordinate.
* Normally preceded by dragStart() and dragTo().
*
* @activity activity The activity where the touch action is being performed.
* @param x X coordinate, in screen coordinates.
* @param y Y coordinate, in screen coordinates.
* @param downTime When the drag was started, in millis since the epoch.
*/
public static void dragEnd(Activity activity, float x, float y, long downTime) {
dragEnd(getRootViewForActivity(activity), x, y, downTime);
} }
/** /**
......
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