Search in sources :

Example 6 with Timer

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

the class NoDoubleTokenUnEscapingTest method testNoDoubleTokenUnEscaping.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
// @Test(timeout = 5000)
public Promise<Void> testNoDoubleTokenUnEscaping() {
    return new Promise<>((resolve, reject) -> {
        final String shouldBeEncoded = "abc%20abc";
        History.newItem(shouldBeEncoded);
        History.newItem("someOtherToken");
        History.back();
        // allow browser to update the url
        timer = new Timer() {

            @Override
            public void run() {
                // make sure that value in url actually matches the original token
                assertEquals(shouldBeEncoded, History.getToken());
                resolve.onInvoke((Void) null);
            }
        };
        timer.schedule(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer)

Example 7 with Timer

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

the class ReplaceItemNoEventTest method testReplaceItemNoEvent.

/**
 * Verify that no events are issued via newItem if there were not reqeuested.
 */
@Test(timeout = 5000)
public Promise<Void> testReplaceItemNoEvent() {
    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 historyToken2_encoded = "token%202";
        History.newItem(historyToken1);
        addHistoryListenerImpl(event -> fail("No event expected"));
        History.replaceItem(historyToken2, false);
        assertEquals(historyToken2, History.getToken());
        timer = new Timer() {

            @Override
            public void run() {
                // Make sure that we have updated the URL properly.
                assertEquals(historyToken2_encoded, getCurrentLocationHash());
                resolve.onInvoke((Void) null);
            }
        };
        timer.schedule(500);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 8 with Timer

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

the class TokenWithQuestionmarkTest method testTokenWithQuestionmark.

/**
 * Test that using an empty history token works properly. There have been problems (see issue
 * 2905) with this in the past on Safari.
 *
 * <p>Seems like a HtmlUnit bug. Need more investigation.
 */
@Test(timeout = 5000)
public Promise<Void> testTokenWithQuestionmark() {
    return new Promise<>((resolve, reject) -> {
        final String token = "foo?bar";
        timer = new Timer() {

            @Override
            public void run() {
                History.newItem(token);
            }
        };
        addHistoryListenerImpl(event -> {
            String historyToken = event.getValue();
            if (historyToken == null) {
                fail("historyToken should not be null");
            }
            assertEquals(token, historyToken);
            timer.cancel();
            resolve.onInvoke((Void) null);
        });
        History.newItem(token);
    });
}
Also used : Promise(elemental2.promise.Promise) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 9 with Timer

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

the class ResizeLayoutPanelTest method testResizeContainer.

/**
 * Test that resizing the outer container triggers a resize event.
 *
 * @param container the container that will hold the panel
 * @param resizeCommand the command that resizes the container
 */
private void testResizeContainer(final SimplePanel container, final Command resizeCommand) {
    // Create a panel and add a handler.
    ResizeLayoutPanel panel = createPanel();
    panel.setWidget(new Label("hello world"));
    panel.setWidth("100%");
    panel.setHeight("100%");
    final CustomResizeHandler handler = new CustomResizeHandler();
    panel.addResizeHandler(handler);
    handler.assertResizeFired(false);
    // Create an outer container and attach it.
    container.setWidget(panel);
    RootPanel.get().add(container);
    // Wait for the resize event from attaching.
    delayTestFinish(10000);
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        @Override
        public void execute() {
            // Triggered by attach.
            handler.assertResizeFired(true);
            // Change the size of the container.
            resizeCommand.execute();
            new Timer() {

                @Override
                public void run() {
                    handler.assertResizeFired(true);
                    container.removeFromParent();
                    finishTest();
                }
            }.schedule(250);
        }
    });
}
Also used : ScheduledCommand(org.gwtproject.core.client.Scheduler.ScheduledCommand) Timer(org.gwtproject.timer.client.Timer)

Example 10 with Timer

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

the class ImageTest method testAttachDetach.

/**
 * Test that attaching and immediately detaching an element does not cause an
 * error.
 */
public void testAttachDetach() {
    final Image image = new Image("counting-forwards.png");
    RootPanel.get().add(image);
    RootPanel.get().remove(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)

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