Add the longClickOnScreen from robotium 4.0 to Robocop to make sure long click does not fail (r=gbrown)

This commit is contained in:
Adrian Tamas 2013-08-05 11:45:37 +03:00
Родитель b79be6f355
Коммит 17e0d21cff
2 изменённых файлов: 44 добавлений и 0 удалений

Просмотреть файл

@ -82,6 +82,13 @@ public interface Actions {
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
*/

Просмотреть файл

@ -22,7 +22,9 @@ 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;
@ -458,6 +460,41 @@ public class FennecNativeActions implements Actions {
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);