Bug 901445 - Add the longClickOnScreen from robotium 4.0 to Robocop (r=gbrown)
authorAdrian Tamas <adrian.tamas@softvision.ro>
Fri, 09 Aug 2013 18:32:35 +0100
changeset 143516 fb365c5ad68dff263e75e7a7396e934738ae0efe
parent 143515 828ab0810ea55f6d87192630f883b5253187481c
child 143517 d07b65be9f7a8d19552ea6443fc8dc3656da117a
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs901445
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 901445 - Add the longClickOnScreen from robotium 4.0 to Robocop (r=gbrown)
build/mobile/robocop/Actions.java.in
build/mobile/robocop/FennecNativeActions.java.in
--- a/build/mobile/robocop/Actions.java.in
+++ b/build/mobile/robocop/Actions.java.in
@@ -78,12 +78,19 @@ public interface Actions {
      * @param key The special key to send
      */
     void sendSpecialKey(SpecialKey key);
     void sendKeyCode(int keyCode);
 
     void drag(int startingX, int endingX, int startingY, int endingY);
 
     /**
+     * This is the implementation of clickLongOnScreen from Robotium 4.0 since this sometimes fails for Robotium 3.6
+     * TODO : Remove this when Robotium is updated
+     */
+
+    void clickLongOnScreen(float x, float y);
+
+    /**
      * Run a sql query on the specified database
      */
     public Cursor querySql(String dbPath, String sql);
 }
--- a/build/mobile/robocop/FennecNativeActions.java.in
+++ b/build/mobile/robocop/FennecNativeActions.java.in
@@ -17,17 +17,19 @@ import java.util.ArrayList;
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.content.Context;
 import android.database.Cursor;
 import android.os.SystemClock;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.KeyEvent;
+import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewConfiguration;
 
 import com.jayway.android.robotium.solo.Solo;
 
 import static @ANDROID_PACKAGE_NAME@.FennecNativeDriver.LogLevel;
 
 public class FennecNativeActions implements Actions {
     private Solo mSolo;
     private Instrumentation mInstr;
@@ -453,16 +455,51 @@ public class FennecNativeActions impleme
     public void sendKeys(String input) {
         mInstr.sendStringSync(input);
     }
 
     public void drag(int startingX, int endingX, int startingY, int endingY) {
         mSolo.drag(startingX, endingX, startingY, endingY, 10);
     }
 
+     /**
+     * This is the implementation of clickLongOnScreen from Robotium 4.0 since this sometimes fails for Robotium 3.6
+     * TODO : Remove this when Robotium is updated
+     */
+
+    public void clickLongOnScreen(float x, float y) {
+    	boolean successfull = false;
+        int retry = 0;
+        long downTime = SystemClock.uptimeMillis();
+        long eventTime = SystemClock.uptimeMillis();
+        MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
+
+        while(!successfull && retry < 10) {
+            try{
+                mInstr.sendPointerSync(event);
+                successfull = true;
+            }catch(SecurityException e){
+                FennecNativeDriver.log(LogLevel.ERROR, e);
+                retry++;
+            }
+        }
+
+        mAsserter.ok(successfull, "Trying to click on long on screen at (" + x + "," + y + ")", "Was able to click long on screen");
+
+        eventTime = SystemClock.uptimeMillis();
+        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, x + 1.0f, y + 1.0f, 0);
+        mInstr.sendPointerSync(event);
+        mSolo.sleep(((int)(ViewConfiguration.getLongPressTimeout() * 2.5f)));
+
+        eventTime = SystemClock.uptimeMillis();
+        event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, x, y, 0);
+        mInstr.sendPointerSync(event);
+        mSolo.sleep(500);
+    }
+
     public Cursor querySql(String dbPath, String sql) {
         try {
             return (Cursor)mQuerySql.invoke(mRobocopApi, dbPath, sql);
         } catch(InvocationTargetException ex) {
             Log.e(LOGTAG, "Error invoking method", ex);
         } catch(IllegalAccessException ex) {
             Log.e(LOGTAG, "Error using field", ex);
         }