Search in sources :

Example 1 with Timer

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);
}
Also used : Timer(org.gwtproject.timer.client.Timer) AnimationHandle(org.gwtproject.animation.client.AnimationScheduler.AnimationHandle)

Example 2 with Timer

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);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) AnimationHandle(org.gwtproject.animation.client.AnimationScheduler.AnimationHandle) Test(org.junit.Test)

Example 3 with Timer

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);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 4 with Timer

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");
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 5 with Timer

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);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Aggregations

Timer (org.gwtproject.timer.client.Timer)65 Promise (elemental2.promise.Promise)16 Test (org.junit.Test)15 ScheduledCommand (org.gwtproject.core.client.Scheduler.ScheduledCommand)7 LoadEvent (org.gwtproject.event.dom.client.LoadEvent)7 Button (org.dominokit.domino.ui.button.Button)3 Card (org.dominokit.domino.ui.cards.Card)3 NativeEvent (org.gwtproject.dom.client.NativeEvent)3 HTMLDivElement (elemental2.dom.HTMLDivElement)2 ArrayList (java.util.ArrayList)2 SampleMethod (org.dominokit.domino.SampleMethod)2 UiView (org.dominokit.domino.api.client.annotations.UiView)2 BaseDemoView (org.dominokit.domino.componentcase.client.ui.views.BaseDemoView)2 CodeCard (org.dominokit.domino.componentcase.client.ui.views.CodeCard)2 Column (org.dominokit.domino.ui.grid.Column)2 Row (org.dominokit.domino.ui.grid.Row)2 BlockHeader (org.dominokit.domino.ui.header.BlockHeader)2 Loader (org.dominokit.domino.ui.loaders.Loader)2 Color (org.dominokit.domino.ui.style.Color)2 AnimationHandle (org.gwtproject.animation.client.AnimationScheduler.AnimationHandle)2