Bug 851861 - Intermittent testFlingCorrectness, etc al. dragSync() consumers. r=mfinkle, a=sledru
authorMark Capella <markcapella@twcny.rr.com>
Wed, 21 Jan 2015 19:23:49 -0500
changeset 243043 3aca4622bfd5
parent 243042 508190797a80
child 243044 9ac8ce8d36ef
push id4371
push userryanvm@gmail.com
push date2015-01-26 16:42 +0000
treeherdermozilla-beta@3aca4622bfd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, sledru
bugs851861
milestone36.0
Bug 851861 - Intermittent testFlingCorrectness, etc al. dragSync() consumers. r=mfinkle, a=sledru
mobile/android/base/gfx/JavaPanZoomController.java
mobile/android/base/gfx/LayerView.java
mobile/android/base/tests/MotionEventHelper.java
--- a/mobile/android/base/gfx/JavaPanZoomController.java
+++ b/mobile/android/base/gfx/JavaPanZoomController.java
@@ -124,26 +124,29 @@ class JavaPanZoomController
     /* The user selected panning mode */
     private AxisLockMode mMode;
     /* Whether or not to wait for a double-tap before dispatching a single-tap */
     private boolean mWaitForDoubleTap;
     /* Used to change the scrollY direction */
     private boolean mNegateWheelScrollY;
     /* Whether the current event has been default-prevented. */
     private boolean mDefaultPrevented;
+    /* Whether longpress events are enabled, or suppressed by robocop tests. */
+    private boolean isLongpressEnabled;
 
     // Handler to be notified when overscroll occurs
     private Overscroll mOverscroll;
 
     public JavaPanZoomController(PanZoomTarget target, View view, EventDispatcher eventDispatcher) {
         mTarget = target;
         mSubscroller = new SubdocumentScrollHelper(eventDispatcher);
         mX = new AxisX(mSubscroller);
         mY = new AxisY(mSubscroller);
         mTouchEventHandler = new TouchEventHandler(view.getContext(), view, this);
+        isLongpressEnabled = true;
 
         checkMainThread();
 
         setState(PanZoomState.NOTHING);
 
         mEventDispatcher = eventDispatcher;
         mEventDispatcher.registerGeckoThreadListener(this,
             MESSAGE_ZOOM_RECT,
@@ -1343,18 +1346,30 @@ class JavaPanZoomController
         // onSingleTapUp (if the user lifts their finger before the
         // long-press timeout) or a call to onLongPress (if the user
         // does not). In the former case, we want to make sure it is
         // treated as a click. (Note that if this is called, we will
         // not get a call to onDoubleTap).
         mWaitForDoubleTap = false;
     }
 
+    /**
+     * MotionEventHelper dragAsync() robocop tests can have us suppress
+     * longpress events that are spuriously created on slower test devices.
+     */
+    public void setIsLongpressEnabled(boolean isLongpressEnabled) {
+        this.isLongpressEnabled = isLongpressEnabled;
+    }
+
     @Override
     public void onLongPress(MotionEvent motionEvent) {
+        if (!isLongpressEnabled) {
+            return;
+        }
+
         GeckoEvent e = GeckoEvent.createLongPressEvent(motionEvent);
         GeckoAppShell.sendEventToGecko(e);
     }
 
     @Override
     public boolean onSingleTapUp(MotionEvent motionEvent) {
         // When double-tapping is allowed, we have to wait to see if this is
         // going to be a double-tap.
--- a/mobile/android/base/gfx/LayerView.java
+++ b/mobile/android/base/gfx/LayerView.java
@@ -136,16 +136,24 @@ public class LayerView extends FrameLayo
 
         setFocusable(true);
         setFocusableInTouchMode(true);
 
         GeckoAccessibility.setDelegate(this);
         GeckoAccessibility.setAccessibilityStateChangeListener(getContext());
     }
 
+    /**
+     * MotionEventHelper dragAsync() robocop tests can instruct
+     * PanZoomController not to generate longpress events.
+     */
+    public void setIsLongpressEnabled(boolean isLongpressEnabled) {
+        ((JavaPanZoomController) mPanZoomController).setIsLongpressEnabled(isLongpressEnabled);
+    }
+
     private static Point getEventRadius(MotionEvent event) {
         return new Point((int)event.getToolMajor() / 2,
                          (int)event.getToolMinor() / 2);
     }
 
     public void geckoConnected() {
         // See if we want to force 16-bit colour before doing anything
         PrefsHelper.getPref("gfx.android.rgb16.force", new PrefsHelper.PrefHandlerBase() {
--- a/mobile/android/base/tests/MotionEventHelper.java
+++ b/mobile/android/base/tests/MotionEventHelper.java
@@ -1,29 +1,34 @@
 package org.mozilla.gecko.tests;
 
+import org.mozilla.gecko.GeckoAppShell;
+import org.mozilla.gecko.gfx.LayerView;
+
 import android.app.Instrumentation;
 import android.os.SystemClock;
 import android.util.FloatMath;
 import android.util.Log;
 import android.view.MotionEvent;
 
 class MotionEventHelper {
     private static final String LOGTAG = "RobocopMotionEventHelper";
 
     private static final long DRAG_EVENTS_PER_SECOND = 20; // 20 move events per second when doing a drag
 
     private final Instrumentation mInstrumentation;
     private final int mSurfaceOffsetX;
     private final int mSurfaceOffsetY;
+    private final LayerView layerView;
 
     public MotionEventHelper(Instrumentation inst, int surfaceOffsetX, int surfaceOffsetY) {
         mInstrumentation = inst;
         mSurfaceOffsetX = surfaceOffsetX;
         mSurfaceOffsetY = surfaceOffsetY;
+        layerView = GeckoAppShell.getLayerView();
         Log.i(LOGTAG, "Initialized using offset (" + mSurfaceOffsetX + "," + mSurfaceOffsetY + ")");
     }
 
     public long down(float x, float y) {
         Log.d(LOGTAG, "Triggering down at (" + x + "," + y + ")");
         long downTime = SystemClock.uptimeMillis();
         MotionEvent event = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, mSurfaceOffsetX + x, mSurfaceOffsetY + y, 0);
         try {
@@ -66,16 +71,18 @@ class MotionEventHelper {
         }
         return -1L;
     }
 
     public Thread dragAsync(final float startX, final float startY, final float endX, final float endY, final long durationMillis) {
         Thread t = new Thread() {
             @Override
             public void run() {
+                layerView.setIsLongpressEnabled(false);
+
                 int numEvents = (int)(durationMillis * DRAG_EVENTS_PER_SECOND / 1000);
                 float eventDx = (endX - startX) / numEvents;
                 float eventDy = (endY - startY) / numEvents;
                 long downTime = down(startX, startY);
                 for (int i = 0; i < numEvents - 1; i++) {
                     downTime = move(downTime, startX + (eventDx * i), startY + (eventDy * i));
                     try {
                         Thread.sleep(1000L / DRAG_EVENTS_PER_SECOND);
@@ -88,16 +95,18 @@ class MotionEventHelper {
                 try {
                     Thread.sleep(1000L);
                 } catch (InterruptedException ie) {
                     ie.printStackTrace();
                 }
                 // do the last one using endX/endY directly to avoid rounding errors
                 downTime = move(downTime, endX, endY);
                 downTime = up(downTime, endX, endY);
+
+                layerView.setIsLongpressEnabled(true);
             }
         };
         t.start();
         return t;
     }
 
     public void dragSync(float startX, float startY, float endX, float endY, long durationMillis) {
         try {