|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mozilla.mcp.TimeoutHandler
public class TimeoutHandler
This class provides a simple facility for placing a time bound on browser interactions (clicks, Ajax transactions, etc).
Usage
A useful pattern is to use this as an inner class within a JUnit testscase:
final Thread testThread = Thread.currentThread();
timeoutHandler = new TimeoutHandler() {
public void timeout() {
super.timeout();
testThread.interrupt();
fail("Action timed out");
}
};
mcp.setTimeoutHandler(timeoutHandler);
TimeoutHandler
has a boolean JavaBeans property
called didTimeout
that can be used after blocking
operations to test if a timeout happened.
if (timeoutHandler.isDidTimeout()) {
fail("timed out waiting for load");
}
Another useful pattern is to combine the previous inner class approach with having the browser perform a non-blocking operation, and then causing the main thread to enter a loop until either a condition is met, or the timeout occurs:
bitSet.clear();
mcp.clickElement(inplaceFields.get(1));
makeAjaxAssertions(bitSet);
//...
private void makeAjaxAssertions(BitSet bitSet) throws Exception {
// Artifically wait for the ajax transaction to complete, or the timeout to be reached.
int i = 0;
while (true) {
if (bitSet.get(TestFeature.STOP_WAITING.ordinal())) {
break;
}
i++;
Thread.currentThread().sleep(mcp.getTimeoutWaitInterval());
}
// assert that the ajax transaction succeeded
assertTrue(bitSet.get(TestFeature.RECEIVED_END_AJAX_EVENT.ordinal()));
}
The above code will either exit normally, by virtuo of the AjaxListener being called and it setting the STOP_WAITING bit in the bitset, or it will terminate due to timeout, in which case the inner class timeout method will be called.
Constructor Summary | |
---|---|
TimeoutHandler()
|
Method Summary | |
---|---|
boolean |
isDidTimeout()
Getter for boolean JavaBeans property didTimeout . |
void |
setDidTimeout(boolean didTimeout)
Setter for boolean JavaBeans property didTimeout . |
void |
timeout()
The default implementation sets the value of the didTimeout JavaBeans property to
true . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TimeoutHandler()
Method Detail |
---|
public void timeout()
The default implementation sets the value of the
didTimeout
JavaBeans property to
true
.
public boolean isDidTimeout()
Getter for boolean JavaBeans property
didTimeout
.
public void setDidTimeout(boolean didTimeout)
Setter for boolean JavaBeans property
didTimeout
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |