Search in sources :

Example 26 with Message

use of com.codename1.messaging.Message in project CodenameOne by codenameone.

the class TestComponent method testBrowserComponent2267.

// Test for https://github.com/codenameone/CodenameOne/issues/2267
private void testBrowserComponent2267() {
    Form hi = new Form();
    String formName = "testBrowserComponent2267";
    hi.setName(formName);
    hi.setLayout(new BorderLayout());
    BrowserComponent browserComponent = new BrowserComponent();
    hi.add(BorderLayout.CENTER, browserComponent);
    final Throwable[] ex = new Throwable[1];
    final boolean[] complete = new boolean[1];
    Button loadButton = new Button("setUrl");
    String buttonName = "setUrl";
    loadButton.setName(buttonName);
    loadButton.addActionListener((ev) -> {
        ActionListener errorHandler = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                e.consume();
                ex[0] = (Throwable) e.getSource();
                complete[0] = true;
                Display.getInstance().removeEdtErrorHandler(this);
            }
        };
        try {
            Display.getInstance().addEdtErrorHandler(errorHandler);
            browserComponent.addWebEventListener("onLoad", e -> {
                Display.getInstance().removeEdtErrorHandler(errorHandler);
                complete[0] = true;
            });
            browserComponent.setURL("https://www.google.es");
        } catch (Throwable t) {
            ex[0] = t;
            complete[0] = true;
            Display.getInstance().removeEdtErrorHandler(errorHandler);
        } finally {
        // complete[0] = true;
        }
    });
    hi.add(BorderLayout.SOUTH, loadButton);
    hi.show();
    TestUtils.waitForFormName(formName, 2000);
    TestUtils.clickButtonByName(buttonName);
    while (!complete[0]) {
        Display.getInstance().invokeAndBlock(() -> {
            Util.sleep(50);
        });
    }
    String message = null;
    if (ex[0] != null) {
        message = ex[0].getMessage();
    }
    TestUtils.assertBool(ex[0] == null, "We received an exception setting the browserComponent URL: " + message);
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

ConnectionRequest (com.codename1.io.ConnectionRequest)8 ActionListener (com.codename1.ui.events.ActionListener)6 IOException (java.io.IOException)5 Message (au.com.dius.pact.model.v3.messaging.Message)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 MessagePact (au.com.dius.pact.model.v3.messaging.MessagePact)2 BufferedInputStream (com.codename1.io.BufferedInputStream)2 NetworkEvent (com.codename1.io.NetworkEvent)2 Message (com.codename1.messaging.Message)2 Dialog (com.codename1.ui.Dialog)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 DataInputStream (java.io.DataInputStream)2 Method (java.lang.reflect.Method)2 Hashtable (java.util.Hashtable)2 Vector (java.util.Vector)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1