2011-12-22 06:09:41 -08:00
|
|
|
#filter substitution
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-22 06:09:41 -08:00
|
|
|
|
|
|
|
package @ANDROID_PACKAGE_NAME@;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Proxy;
|
|
|
|
import java.lang.reflect.InvocationHandler;
|
2012-03-08 10:25:44 -08:00
|
|
|
import java.util.concurrent.SynchronousQueue;
|
|
|
|
import java.util.ArrayList;
|
2011-12-22 06:09:41 -08:00
|
|
|
|
|
|
|
import android.app.Activity;
|
2012-03-08 10:25:44 -08:00
|
|
|
import android.content.Context;
|
2011-12-22 06:09:41 -08:00
|
|
|
import android.app.Instrumentation;
|
2012-03-08 10:25:44 -08:00
|
|
|
import android.database.Cursor;
|
2012-02-02 13:07:00 -08:00
|
|
|
import android.os.SystemClock;
|
2011-12-22 06:09:41 -08:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.KeyEvent;
|
2012-03-08 10:25:44 -08:00
|
|
|
import android.util.Log;
|
2011-12-22 06:09:41 -08:00
|
|
|
|
|
|
|
import org.json.*;
|
|
|
|
|
|
|
|
import com.jayway.android.robotium.solo.Solo;
|
|
|
|
|
2012-04-10 12:20:55 -07:00
|
|
|
import static @ANDROID_PACKAGE_NAME@.FennecNativeDriver.LogLevel;
|
|
|
|
|
2011-12-22 06:09:41 -08:00
|
|
|
public class FennecNativeActions implements Actions {
|
2012-02-15 06:56:20 -08:00
|
|
|
private Solo mSolo;
|
|
|
|
private Instrumentation mInstr;
|
|
|
|
private Activity mGeckoApp;
|
2012-06-28 11:20:15 -07:00
|
|
|
private Assert mAsserter;
|
2012-02-15 06:56:20 -08:00
|
|
|
|
|
|
|
// Objects for reflexive access of fennec classes.
|
|
|
|
private ClassLoader mClassLoader;
|
2012-08-14 05:55:58 -07:00
|
|
|
private Class mApiClass;
|
|
|
|
private Class mEventListenerClass;
|
|
|
|
private Class mDrawListenerClass;
|
|
|
|
private Method mRegisterEventListener;
|
|
|
|
private Method mUnregisterEventListener;
|
|
|
|
private Method mBroadcastEvent;
|
2012-02-15 06:56:20 -08:00
|
|
|
private Method mSetDrawListener;
|
2012-08-14 05:55:58 -07:00
|
|
|
private Method mQuerySql;
|
|
|
|
private Object mRobocopApi;
|
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
private static final String LOGTAG = "FennecNativeActions";
|
2012-02-15 06:56:20 -08:00
|
|
|
|
2012-06-28 11:20:15 -07:00
|
|
|
public FennecNativeActions(Activity activity, Solo robocop, Instrumentation instrumentation, Assert asserter) {
|
2012-02-15 06:56:20 -08:00
|
|
|
mSolo = robocop;
|
|
|
|
mInstr = instrumentation;
|
|
|
|
mGeckoApp = activity;
|
2012-06-28 11:20:15 -07:00
|
|
|
mAsserter = asserter;
|
2012-02-15 06:56:20 -08:00
|
|
|
// Set up reflexive access of java classes and methods.
|
|
|
|
try {
|
|
|
|
mClassLoader = activity.getClassLoader();
|
2012-08-14 05:55:58 -07:00
|
|
|
|
|
|
|
mApiClass = mClassLoader.loadClass("org.mozilla.gecko.RobocopAPI");
|
|
|
|
mEventListenerClass = mClassLoader.loadClass("org.mozilla.gecko.util.GeckoEventListener");
|
|
|
|
mDrawListenerClass = mClassLoader.loadClass("org.mozilla.gecko.gfx.GeckoLayerClient$DrawListener");
|
|
|
|
|
|
|
|
mRegisterEventListener = mApiClass.getMethod("registerEventListener", String.class, mEventListenerClass);
|
|
|
|
mUnregisterEventListener = mApiClass.getMethod("unregisterEventListener", String.class, mEventListenerClass);
|
|
|
|
mBroadcastEvent = mApiClass.getMethod("broadcastEvent", String.class, String.class);
|
|
|
|
mSetDrawListener = mApiClass.getMethod("setDrawListener", mDrawListenerClass);
|
|
|
|
mQuerySql = mApiClass.getMethod("querySql", String.class, String.class);
|
|
|
|
|
|
|
|
mRobocopApi = mApiClass.getConstructor(Activity.class).newInstance(activity);
|
|
|
|
} catch (Exception e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
2011-12-22 06:09:41 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
class wakeInvocationHandler implements InvocationHandler {
|
|
|
|
private final GeckoEventExpecter mEventExpecter;
|
2011-12-22 06:09:41 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public wakeInvocationHandler(GeckoEventExpecter expecter) {
|
|
|
|
mEventExpecter = expecter;
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
|
|
|
String methodName = method.getName();
|
|
|
|
//Depending on the method, return a completely different type.
|
|
|
|
if(methodName.equals("toString")) {
|
|
|
|
return "wakeInvocationHandler";
|
|
|
|
}
|
|
|
|
if(methodName.equals("equals")) {
|
|
|
|
return this == args[0];
|
|
|
|
}
|
|
|
|
if(methodName.equals("clone")) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
if(methodName.equals("hashCode")) {
|
|
|
|
return 314;
|
|
|
|
}
|
2012-04-10 12:20:46 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
2012-02-15 06:56:20 -08:00
|
|
|
"Waking up on "+methodName);
|
2013-02-19 10:15:44 -08:00
|
|
|
mEventExpecter.notifyOfEvent(args);
|
2012-02-15 06:56:20 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 06:09:41 -08:00
|
|
|
|
2012-08-10 14:59:12 -07:00
|
|
|
class GeckoEventExpecter implements RepeatedEventExpecter {
|
2012-02-15 06:56:20 -08:00
|
|
|
private final String mGeckoEvent;
|
|
|
|
private final Object[] mRegistrationParams;
|
|
|
|
private boolean mEventReceived;
|
2013-03-05 02:27:29 -08:00
|
|
|
private boolean mEventEverReceived;
|
2013-02-19 10:15:44 -08:00
|
|
|
private String mEventData;
|
2012-06-28 11:20:15 -07:00
|
|
|
private static final int MAX_WAIT_MS = 90000;
|
2012-01-05 18:36:17 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
GeckoEventExpecter(String geckoEvent, Object[] registrationParams) {
|
|
|
|
mGeckoEvent = geckoEvent;
|
|
|
|
mRegistrationParams = registrationParams;
|
|
|
|
}
|
2012-01-05 18:36:17 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public synchronized void blockForEvent() {
|
2013-03-12 11:32:25 -07:00
|
|
|
blockForEvent(MAX_WAIT_MS, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private synchronized void blockForEvent(long millis, boolean failOnTimeout) {
|
2012-06-28 11:20:15 -07:00
|
|
|
long startTime = SystemClock.uptimeMillis();
|
|
|
|
long endTime = 0;
|
2012-02-15 06:56:20 -08:00
|
|
|
while (! mEventReceived) {
|
|
|
|
try {
|
2013-03-12 11:32:25 -07:00
|
|
|
this.wait(millis);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (InterruptedException ie) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-28 11:20:15 -07:00
|
|
|
endTime = SystemClock.uptimeMillis();
|
2013-03-12 11:32:25 -07:00
|
|
|
if (!mEventReceived && (endTime - startTime >= millis)) {
|
|
|
|
if (failOnTimeout) {
|
|
|
|
FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
|
|
|
|
mAsserter.ok(false, "GeckoEventExpecter",
|
|
|
|
"blockForEvent timeout: "+mGeckoEvent);
|
|
|
|
}
|
|
|
|
mEventData = null;
|
2012-06-28 11:20:15 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
2012-08-10 14:59:12 -07:00
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
mUnregisterEventListener.invoke(mRobocopApi, mRegistrationParams);
|
2012-08-10 14:59:12 -07:00
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
|
|
|
}
|
2012-04-10 12:20:46 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
2012-02-15 06:56:20 -08:00
|
|
|
"unblocked on expecter for " + mGeckoEvent);
|
2013-03-05 02:27:29 -08:00
|
|
|
mEventReceived = false;
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
2012-01-05 18:36:17 -08:00
|
|
|
|
2012-08-10 14:59:12 -07:00
|
|
|
public synchronized void blockUntilClear(long millis) {
|
|
|
|
if (millis <= 0) {
|
|
|
|
throw new IllegalArgumentException("millis must be > 0");
|
|
|
|
}
|
|
|
|
// wait for at least one event
|
|
|
|
long startTime = SystemClock.uptimeMillis();
|
|
|
|
long endTime = 0;
|
|
|
|
while (!mEventReceived) {
|
|
|
|
try {
|
|
|
|
this.wait(MAX_WAIT_MS);
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
endTime = SystemClock.uptimeMillis();
|
|
|
|
if (!mEventReceived && (endTime - startTime >= MAX_WAIT_MS)) {
|
2012-08-30 07:50:16 -07:00
|
|
|
FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
|
2012-08-10 14:59:12 -07:00
|
|
|
mAsserter.ok(false, "GeckoEventExpecter", "blockUtilClear timeout");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// now wait for a period of millis where we don't get an event
|
|
|
|
startTime = SystemClock.uptimeMillis();
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
this.wait(millis);
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
endTime = SystemClock.uptimeMillis();
|
|
|
|
if (endTime - startTime >= millis) {
|
|
|
|
// success
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// we got a notify() before we could wait long enough, so we need to start over
|
|
|
|
startTime = endTime;
|
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
mUnregisterEventListener.invoke(mRobocopApi, mRegistrationParams);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (IllegalAccessException e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (InvocationTargetException e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
2012-08-10 14:59:12 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
|
|
|
"unblocked on expecter for " + mGeckoEvent);
|
2013-03-05 02:27:29 -08:00
|
|
|
mEventReceived = false;
|
2012-08-10 14:59:12 -07:00
|
|
|
}
|
|
|
|
|
2013-02-19 10:15:44 -08:00
|
|
|
public synchronized String blockForEventData() {
|
|
|
|
blockForEvent();
|
|
|
|
return mEventData;
|
|
|
|
}
|
|
|
|
|
2013-03-12 11:32:25 -07:00
|
|
|
public synchronized String blockForEventDataWithTimeout(long millis) {
|
|
|
|
blockForEvent(millis, false);
|
|
|
|
return mEventData;
|
|
|
|
}
|
|
|
|
|
2012-08-10 14:59:12 -07:00
|
|
|
public synchronized boolean eventReceived() {
|
2013-03-05 02:27:29 -08:00
|
|
|
return mEventEverReceived;
|
2012-08-10 14:59:12 -07:00
|
|
|
}
|
|
|
|
|
2013-02-19 10:15:44 -08:00
|
|
|
void notifyOfEvent(Object[] args) {
|
2012-04-10 12:20:46 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
2012-02-15 06:56:20 -08:00
|
|
|
"received event " + mGeckoEvent);
|
|
|
|
synchronized (this) {
|
|
|
|
mEventReceived = true;
|
2013-03-05 02:27:29 -08:00
|
|
|
mEventEverReceived = true;
|
2013-02-19 10:15:44 -08:00
|
|
|
mEventData = args[1].toString();
|
2012-02-15 06:56:20 -08:00
|
|
|
this.notifyAll();
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
|
2012-08-10 14:59:12 -07:00
|
|
|
public RepeatedEventExpecter expectGeckoEvent(String geckoEvent) {
|
2012-04-10 12:20:46 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
2012-02-15 06:56:20 -08:00
|
|
|
"waiting for "+geckoEvent);
|
2012-01-05 18:36:17 -08:00
|
|
|
try {
|
2012-02-15 06:56:20 -08:00
|
|
|
Object[] finalParams = new Object[2];
|
|
|
|
finalParams[0] = geckoEvent;
|
|
|
|
GeckoEventExpecter expecter = new GeckoEventExpecter(geckoEvent, finalParams);
|
|
|
|
wakeInvocationHandler wIH = new wakeInvocationHandler(expecter);
|
2012-08-14 05:55:58 -07:00
|
|
|
Object proxy = Proxy.newProxyInstance(mClassLoader, new Class[] { mEventListenerClass }, wIH);
|
2012-02-15 06:56:20 -08:00
|
|
|
finalParams[1] = proxy;
|
2012-08-14 05:55:58 -07:00
|
|
|
|
|
|
|
mRegisterEventListener.invoke(mRobocopApi, finalParams);
|
2012-02-15 06:56:20 -08:00
|
|
|
return expecter;
|
|
|
|
} catch (IllegalAccessException e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (InvocationTargetException e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
return null;
|
2012-01-05 18:36:17 -08:00
|
|
|
}
|
|
|
|
|
2012-05-25 10:04:12 -07:00
|
|
|
public void sendGeckoEvent(String geckoEvent, String data) {
|
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
mBroadcastEvent.invoke(mRobocopApi, geckoEvent, data);
|
2012-05-25 10:04:12 -07:00
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
class DrawListenerProxy implements InvocationHandler {
|
|
|
|
private final PaintExpecter mPaintExpecter;
|
2012-01-05 18:36:17 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
DrawListenerProxy(PaintExpecter paintExpecter) {
|
|
|
|
mPaintExpecter = paintExpecter;
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) {
|
|
|
|
String methodName = method.getName();
|
|
|
|
if ("drawFinished".equals(methodName)) {
|
2012-04-10 12:20:46 -07:00
|
|
|
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
|
2012-02-15 06:56:20 -08:00
|
|
|
"Received drawFinished notification");
|
2013-02-19 10:15:44 -08:00
|
|
|
mPaintExpecter.notifyOfEvent(args);
|
2012-02-15 06:56:20 -08:00
|
|
|
} else if ("toString".equals(methodName)) {
|
|
|
|
return "DrawListenerProxy";
|
|
|
|
} else if ("equals".equals(methodName)) {
|
|
|
|
return false;
|
|
|
|
} else if ("hashCode".equals(methodName)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
class PaintExpecter implements RepeatedEventExpecter {
|
|
|
|
private Object mLayerClient;
|
|
|
|
private boolean mPaintDone;
|
2012-06-28 11:20:15 -07:00
|
|
|
private static final int MAX_WAIT_MS = 90000;
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
PaintExpecter() throws IllegalAccessException, InvocationTargetException {
|
2012-08-14 05:55:58 -07:00
|
|
|
Object proxy = Proxy.newProxyInstance(mClassLoader, new Class[] { mDrawListenerClass }, new DrawListenerProxy(this));
|
|
|
|
mSetDrawListener.invoke(mRobocopApi, proxy);
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2013-02-19 10:15:44 -08:00
|
|
|
void notifyOfEvent(Object[] args) {
|
2012-02-15 06:56:20 -08:00
|
|
|
synchronized (this) {
|
|
|
|
mPaintDone = true;
|
|
|
|
this.notifyAll();
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2013-03-12 11:32:25 -07:00
|
|
|
private synchronized void blockForEvent(long millis, boolean failOnTimeout) {
|
2012-06-28 11:20:15 -07:00
|
|
|
long startTime = SystemClock.uptimeMillis();
|
|
|
|
long endTime = 0;
|
2012-02-15 06:56:20 -08:00
|
|
|
while (!mPaintDone) {
|
|
|
|
try {
|
2013-03-12 11:32:25 -07:00
|
|
|
this.wait(millis);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (InterruptedException ie) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-28 11:20:15 -07:00
|
|
|
endTime = SystemClock.uptimeMillis();
|
2013-03-12 11:32:25 -07:00
|
|
|
if (!mPaintDone && (endTime - startTime >= millis)) {
|
|
|
|
if (failOnTimeout) {
|
|
|
|
FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
|
|
|
|
mAsserter.ok(false, "PaintExpecter", "blockForEvent timeout");
|
|
|
|
}
|
2012-06-28 11:20:15 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
mSetDrawListener.invoke(mRobocopApi, (Object)null);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (Exception e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2013-03-12 11:32:25 -07:00
|
|
|
public synchronized void blockForEvent() {
|
|
|
|
blockForEvent(MAX_WAIT_MS, true);
|
|
|
|
}
|
|
|
|
|
2013-02-19 10:15:44 -08:00
|
|
|
public synchronized String blockForEventData() {
|
|
|
|
blockForEvent();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-03-12 11:32:25 -07:00
|
|
|
public synchronized String blockForEventDataWithTimeout(long millis) {
|
|
|
|
blockForEvent(millis, false);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public synchronized boolean eventReceived() {
|
|
|
|
return mPaintDone;
|
2012-01-30 19:46:13 -08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public synchronized void blockUntilClear(long millis) {
|
|
|
|
if (millis <= 0) {
|
|
|
|
throw new IllegalArgumentException("millis must be > 0");
|
|
|
|
}
|
|
|
|
// wait for at least one event
|
2012-06-28 11:20:15 -07:00
|
|
|
long startTime = SystemClock.uptimeMillis();
|
|
|
|
long endTime = 0;
|
2012-02-15 06:56:20 -08:00
|
|
|
while (!mPaintDone) {
|
|
|
|
try {
|
2012-06-28 11:20:15 -07:00
|
|
|
this.wait(MAX_WAIT_MS);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (InterruptedException ie) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-28 11:20:15 -07:00
|
|
|
endTime = SystemClock.uptimeMillis();
|
|
|
|
if (!mPaintDone && (endTime - startTime >= MAX_WAIT_MS)) {
|
2012-08-30 07:50:16 -07:00
|
|
|
FennecNativeDriver.logAllStackTraces(FennecNativeDriver.LogLevel.ERROR);
|
2012-06-28 11:20:15 -07:00
|
|
|
mAsserter.ok(false, "PaintExpecter", "blockUtilClear timeout");
|
|
|
|
return;
|
|
|
|
}
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
|
|
|
// now wait for a period of millis where we don't get an event
|
2012-06-28 11:20:15 -07:00
|
|
|
startTime = SystemClock.uptimeMillis();
|
2012-02-15 06:56:20 -08:00
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
this.wait(millis);
|
|
|
|
} catch (InterruptedException ie) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, ie);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-28 11:20:15 -07:00
|
|
|
endTime = SystemClock.uptimeMillis();
|
2012-02-15 06:56:20 -08:00
|
|
|
if (endTime - startTime >= millis) {
|
|
|
|
// success
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// we got a notify() before we could wait long enough, so we need to start over
|
|
|
|
startTime = endTime;
|
|
|
|
}
|
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
mSetDrawListener.invoke(mRobocopApi, (Object)null);
|
2012-02-15 06:56:20 -08:00
|
|
|
} catch (Exception e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
}
|
2012-02-02 13:07:00 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public RepeatedEventExpecter expectPaint() {
|
2012-02-02 13:07:00 -08:00
|
|
|
try {
|
2012-02-15 06:56:20 -08:00
|
|
|
return new PaintExpecter();
|
|
|
|
} catch (Exception e) {
|
2012-04-10 12:20:55 -07:00
|
|
|
FennecNativeDriver.log(LogLevel.ERROR, e);
|
2012-02-15 06:56:20 -08:00
|
|
|
return null;
|
2012-02-02 13:07:00 -08:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public void sendSpecialKey(SpecialKey button) {
|
|
|
|
switch(button) {
|
|
|
|
case DOWN:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_DPAD_DOWN);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case UP:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_DPAD_UP);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case LEFT:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_DPAD_LEFT);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case RIGHT:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_DPAD_RIGHT);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case ENTER:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_ENTER);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case MENU:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_MENU);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
case BACK:
|
2013-04-03 16:45:43 -07:00
|
|
|
sendKeyCode(KeyEvent.KEYCODE_BACK);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
default:
|
2013-04-03 16:45:43 -07:00
|
|
|
mAsserter.ok(false, "sendSpecialKey", "Unknown SpecialKey " + button);
|
2012-02-15 06:56:20 -08:00
|
|
|
break;
|
|
|
|
}
|
2012-01-30 19:46:13 -08:00
|
|
|
}
|
|
|
|
|
2013-04-03 16:45:43 -07:00
|
|
|
public void sendKeyCode(int keyCode) {
|
|
|
|
if (keyCode <= 0 || keyCode > KeyEvent.getMaxKeyCode()) {
|
|
|
|
mAsserter.ok(false, "sendKeyCode", "Unknown keyCode " + keyCode);
|
|
|
|
}
|
|
|
|
mInstr.sendCharacterSync(keyCode);
|
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
@Override
|
|
|
|
public void sendKeys(String input) {
|
|
|
|
mInstr.sendStringSync(input);
|
2011-12-22 06:09:41 -08:00
|
|
|
}
|
|
|
|
|
2012-02-15 06:56:20 -08:00
|
|
|
public void drag(int startingX, int endingX, int startingY, int endingY) {
|
|
|
|
mSolo.drag(startingX, endingX, startingY, endingY, 10);
|
|
|
|
}
|
2012-03-08 10:25:44 -08:00
|
|
|
|
|
|
|
public Cursor querySql(String dbPath, String sql) {
|
|
|
|
try {
|
2012-08-14 05:55:58 -07:00
|
|
|
return (Cursor)mQuerySql.invoke(mRobocopApi, dbPath, sql);
|
2012-03-08 10:25:44 -08:00
|
|
|
} catch(InvocationTargetException ex) {
|
|
|
|
Log.e(LOGTAG, "Error invoking method", ex);
|
|
|
|
} catch(IllegalAccessException ex) {
|
|
|
|
Log.e(LOGTAG, "Error using field", ex);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2011-12-22 06:09:41 -08:00
|
|
|
}
|