Bug 840825 - Add blockForEventData method to EventExpecter. r=gbrown

This commit is contained in:
Margaret Leibovic 2013-02-19 10:15:44 -08:00
parent 4aa6da6a4f
commit 9c28dc5476
2 changed files with 19 additions and 4 deletions

View File

@ -20,6 +20,9 @@ public interface Actions {
/** Blocks until the event has been received. Subsequent calls will return immediately. */
public void blockForEvent();
/** Blocks until the event has been received and returns data associated with the event. */
public String blockForEventData();
/** Polls to see if the event has been received. Once this returns true, subsequent calls will also return true. */
public boolean eventReceived();
}

View File

@ -96,7 +96,7 @@ public class FennecNativeActions implements Actions {
}
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
"Waking up on "+methodName);
mEventExpecter.notifyOfEvent();
mEventExpecter.notifyOfEvent(args);
return null;
}
}
@ -105,6 +105,7 @@ public class FennecNativeActions implements Actions {
private final String mGeckoEvent;
private final Object[] mRegistrationParams;
private boolean mEventReceived;
private String mEventData;
private static final int MAX_WAIT_MS = 90000;
GeckoEventExpecter(String geckoEvent, Object[] registrationParams) {
@ -190,15 +191,21 @@ public class FennecNativeActions implements Actions {
"unblocked on expecter for " + mGeckoEvent);
}
public synchronized String blockForEventData() {
blockForEvent();
return mEventData;
}
public synchronized boolean eventReceived() {
return mEventReceived;
}
void notifyOfEvent() {
void notifyOfEvent(Object[] args) {
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
"received event " + mGeckoEvent);
synchronized (this) {
mEventReceived = true;
mEventData = args[1].toString();
this.notifyAll();
}
}
@ -247,7 +254,7 @@ public class FennecNativeActions implements Actions {
if ("drawFinished".equals(methodName)) {
FennecNativeDriver.log(FennecNativeDriver.LogLevel.DEBUG,
"Received drawFinished notification");
mPaintExpecter.notifyOfEvent();
mPaintExpecter.notifyOfEvent(args);
} else if ("toString".equals(methodName)) {
return "DrawListenerProxy";
} else if ("equals".equals(methodName)) {
@ -269,7 +276,7 @@ public class FennecNativeActions implements Actions {
mSetDrawListener.invoke(mRobocopApi, proxy);
}
void notifyOfEvent() {
void notifyOfEvent(Object[] args) {
synchronized (this) {
mPaintDone = true;
this.notifyAll();
@ -300,6 +307,11 @@ public class FennecNativeActions implements Actions {
}
}
public synchronized String blockForEventData() {
blockForEvent();
return null;
}
public synchronized boolean eventReceived() {
return mPaintDone;
}