use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.
the class AnimationGwt2SchedulerTest method testCancel.
public void testCancel() {
delayTestFinish(TEST_TIMEOUT);
AnimationHandle handle = scheduler.requestAnimationFrame(timestamp -> fail("The animation frame was cancelled and should not execute."), null);
// Cancel the animation frame.
handle.cancel();
// Wait to make sure it doesn't execute.
new Timer() {
@Override
public void run() {
finishTest();
}
}.schedule(TIMER_DELAY);
}
use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.
the class AnimationSchedulerJ2clTest method testCancel.
@Test(timeout = TEST_TIMEOUT)
public Promise<Void> testCancel() {
AnimationHandle handle = scheduler.requestAnimationFrame(timestamp -> fail("The animation frame was cancelled and should not execute."), null);
// Cancel the animation frame.
handle.cancel();
// Wait to make sure it doesn't execute.
return new Promise<>((resolve, reject) -> {
new Timer() {
@Override
public void run() {
resolve.onInvoke((Void) null);
}
}.schedule(TIMER_DELAY);
});
}
use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.
the class EmptyHistoryTokensTest method testEmptyHistoryTokens.
/*
* Tests against issue #879: Ensure that empty history tokens do not add
* additional characters after the '#' symbol in the URL.
*/
@Test(timeout = 5000)
public Promise<Void> testEmptyHistoryTokens() {
// event to fire.
return new Promise<>((resolve, reject) -> {
timer = new Timer() {
@Override
public void run() {
History.newItem("foobar");
}
};
addHistoryListenerImpl(event -> {
String historyToken = event.getValue();
if (historyToken == null) {
fail("historyToken should not be null");
}
if (historyToken.equals("foobar")) {
History.newItem("");
} else {
assertEquals("", historyToken);
resolve.onInvoke((Void) null);
}
});
timer.scheduleRepeating(500);
});
}
use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.
the class HistoryChangeCountTest method testHistoryChangedCount.
/**
* Verify that {@link ValueChangeHandler#onValueChange(ValueChangeEvent)} is only called onceper
* {@link History#newItem(String)}.
*
* @return
*/
@Test(timeout = 5000)
public Promise<Object> testHistoryChangedCount() {
return new Promise<>((resolve, reject) -> {
timer = new Timer() {
private int count = 0;
@Override
public void run() {
if (count++ == 0) {
// verify that duplicates don't issue another event
History.newItem("testHistoryChangedCount");
timer.schedule(500);
} else {
resolve.onInvoke((Void) null);
}
}
};
addHistoryListenerImpl(new ValueChangeHandler<String>() {
private int count = 0;
@Override
public void onValueChange(ValueChangeEvent<String> event) {
if (count++ != 0) {
fail("onHistoryChanged called multiple times");
}
// wait 500ms to see if we get called multiple times
timer.schedule(500);
}
});
History.newItem("testHistoryChangedCount");
});
}
use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.
the class HistoryTest method testHistory.
/*
* Ensure that non-url-safe strings (such as those containing spaces) are
* encoded/decoded correctly, and that programmatic 'back' works.
*/
@Test(timeout = 10000)
public Promise<Void> testHistory() {
return new Promise<>((resolve, reject) -> {
/*
* Sentinel token which should only be seen if tokens are lost during the
* rest of the test. Without this, History.back() might send the browser too
* far back, i.e. back to before the web app containing our test module.
*/
History.newItem("if-you-see-this-then-history-went-back-too-far");
final String historyToken1 = "token1";
final String historyToken2 = "token 2";
Timer timer = new Timer() {
@Override
public void run() {
History.newItem(historyToken1);
}
};
addHistoryListenerImpl(new ValueChangeHandler<String>() {
private int state = 0;
@Override
public void onValueChange(ValueChangeEvent<String> event) {
String historyToken = event.getValue();
switch(state) {
case 0:
{
if (!historyToken.equals(historyToken1)) {
fail("Expecting token '" + historyToken1 + "', but got: " + historyToken);
}
state = 1;
History.newItem(historyToken2);
break;
}
case 1:
{
if (!historyToken.equals(historyToken2)) {
fail("Expecting token '" + historyToken2 + "', but got: " + historyToken);
}
state = 2;
History.back();
break;
}
case 2:
{
if (!historyToken.equals(historyToken1)) {
fail("Expecting token '" + historyToken1 + "', but got: " + historyToken);
}
resolve.onInvoke((Void) null);
break;
}
}
}
});
timer.schedule(500);
});
}
Aggregations