Search in sources :

Example 61 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class TokenEscapingTest method testTokenEscaping.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
@Test(timeout = 5000)
public Promise<Void> testTokenEscaping() {
    return new Promise<>((resolve, reject) -> {
        final String shouldBeEncoded = "% ^[]|\"<>{}\\";
        final String shouldBeEncodedAs = "%25%20%5E%5B%5D%7C%22%3C%3E%7B%7D%5C";
        addHistoryListenerImpl(event -> {
            assertEquals(shouldBeEncodedAs, getCurrentLocationHash());
            assertEquals(shouldBeEncoded, event.getValue());
            resolve.onInvoke((Void) null);
        });
        timer = new Timer() {

            @Override
            public void run() {
                History.newItem(shouldBeEncoded);
            }
        };
        timer.schedule(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 62 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class TokenNonescapingTest method testTokenNonescaping.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
@Test(timeout = 5000)
public Promise<Void> testTokenNonescaping() {
    return new Promise<>((resolve, reject) -> {
        final String shouldNotChange = "abc;,/?:@&=+$-_.!~*()ABC123foo";
        addHistoryListenerImpl(event -> {
            assertEquals(shouldNotChange, event.getValue());
            resolve.onInvoke((Void) null);
        });
        timer = new Timer() {

            @Override
            public void run() {
                History.newItem(shouldNotChange);
            }
        };
        timer.schedule(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 63 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class NoEventsTest method testNoEvents.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
@Test(timeout = 5000)
public Promise<Void> testNoEvents() {
    return new Promise<>((resolve, reject) -> {
        timer = new Timer() {

            @Override
            public void run() {
                resolve.onInvoke((Void) null);
            }
        };
        addHistoryListenerImpl(event -> fail("onHistoryChanged should not have been called"));
        History.newItem("testNoEvents", false);
        timer.scheduleRepeating(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 64 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class ReplaceItemTest method testReplaceItem.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
@Test(timeout = 5000)
public Promise<Void> testReplaceItem() {
    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";
        final String historyToken3 = "token3";
        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.replaceItem(historyToken3, true);
                            break;
                        }
                    case 2:
                        {
                            if (!historyToken.equals(historyToken3)) {
                                fail("Expecting token '" + historyToken3 + "', but got: " + historyToken);
                            }
                            state = 3;
                            History.back();
                            break;
                        }
                    case 3:
                        {
                            if (!historyToken.equals(historyToken1)) {
                                fail("Expecting token '" + historyToken1 + "', but got: " + historyToken);
                            }
                            resolve.onInvoke((Void) null);
                        }
                }
            }
        });
        History.newItem(historyToken1);
        timer = new Timer() {

            @Override
            public void run() {
                History.newItem(historyToken1);
            }
        };
        timer.schedule(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 65 with Timer

use of org.gwtproject.timer.client.Timer in project gwtproject by treblereel.

the class ImageResourceTest method testAttachDetach.

/**
 * Test that attaching and immediately detaching an element does not cause an error.
 */
public void testAttachDetach() {
    final Image image = (Image) document.createElement("img");
    document.body.appendChild(image);
    document.body.removeChild(image);
    // Wait for the synthetic event to attempt to fire.
    delayTestFinish(DEFAULT_TEST_TIMEOUT);
    new Timer() {

        @Override
        public void run() {
            // The synthetic event did not cause an error.
            finishTest();
        }
    }.schedule(SYNTHETIC_LOAD_EVENT_TIMEOUT);
}
Also used : Timer(org.gwtproject.timer.client.Timer) Image(elemental2.dom.Image)

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