Search in sources :

Example 66 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_button.

private void getComponentAt_int_int_button() {
    log("Testing getComponentAt(x, y) with button");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Button("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form");
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 67 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_label.

private void getComponentAt_int_int_label() {
    log("Testing getComponentAt(x, y) with label");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Label("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form", 2000);
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 68 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_container.

private void getComponentAt_int_int_container() {
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Container l = new Container();
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form", 2000);
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 69 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_browsercomponent.

private void getComponentAt_int_int_browsercomponent() {
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form mapDemo = new Form("Maps", new LayeredLayout());
    Toolbar.setOnTopSideMenu(true);
    Toolbar tb = new Toolbar();
    mapDemo.setToolbar(tb);
    mapDemo.setTitle("Maps");
    tb.addCommandToSideMenu(new Command("Test") {

        @Override
        public void actionPerformed(ActionEvent e) {
        // testNestedScrollingLabels();
        }
    });
    BrowserComponent mc = new BrowserComponent();
    mapDemo.add(mc);
    mapDemo.show();
    TestUtils.waitForFormTitle("Maps", 2000);
    Component middleComponent = mapDemo.getComponentAt(w / 2, h / 2);
    assertTrue(mc == middleComponent || mc.contains(middleComponent), "Wrong component found in middle. Expected " + mc + " but found " + middleComponent);
    tb.openSideMenu();
    // wait for side menu to open
    TestUtils.waitFor(500);
    Component res = null;
    res = tb.getComponentAt(10, h / 2);
    // System.out.println("tb size = "+tb.getAbsoluteX()+", "+tb.getAbsoluteY()+", "+tb.getWidth()+", "+tb.getHeight());
    // System.out.println("mb size = "+tb.getMenuBar().getAbsoluteX()+", "+tb.getMenuBar().getAbsoluteY()+", "+tb.getMenuBar().getWidth()+", "+tb.getMenuBar().getHeight());
    // System.out.println("res is "+res);
    res = mapDemo.getComponentAt(10, h / 2);
    // Let's find the interaction dialog on the form
    Component interactionDialog = $("*", mapDemo).filter(c -> {
        return c instanceof InteractionDialog;
    }).asComponent();
    assertTrue(((InteractionDialog) interactionDialog).contains(res), "Toolbar is open so getComponentAt() should return something on the toolbar.  But received " + res + ".  Toolbar is " + tb);
}
Also used : Util(com.codename1.io.Util) BoxLayout(com.codename1.ui.layouts.BoxLayout) ActionEvent(com.codename1.ui.events.ActionEvent) NetworkManager(com.codename1.io.NetworkManager) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) NetworkEvent(com.codename1.io.NetworkEvent) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) ConnectionRequest(com.codename1.io.ConnectionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) AbstractTest(com.codename1.testing.AbstractTest) TestUtils(com.codename1.testing.TestUtils) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat) Cookie(com.codename1.io.Cookie) FileSystemStorage(com.codename1.io.FileSystemStorage) IOException(java.io.IOException) ActionListener(com.codename1.ui.events.ActionListener) JSONParser(com.codename1.io.JSONParser) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) InputStreamReader(java.io.InputStreamReader) Style(com.codename1.ui.plaf.Style) Coord(com.codename1.maps.Coord) ToastBar(com.codename1.components.ToastBar) InteractionDialog(com.codename1.components.InteractionDialog) InteractionDialog(com.codename1.components.InteractionDialog) ActionEvent(com.codename1.ui.events.ActionEvent) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 70 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestComponent method testCookiesInBrowserComponent.

private void testCookiesInBrowserComponent() throws IOException {
    Cookie.clearCookiesFromStorage();
    Form f = new Form("CookiesInBrowser");
    String formName = "CookiesInBrowser";
    f.setName(formName);
    f.setLayout(new BorderLayout());
    BrowserComponent bc = new BrowserComponent();
    f.add(BorderLayout.CENTER, bc);
    f.show();
    TestUtils.waitForFormName(formName, 2000);
    String baseUrl = "http://solutions.weblite.ca/cn1tests/cookie";
    String clearCookiesUrl = baseUrl + "/reset.php";
    String setCookiesUrl = baseUrl + "/set.php";
    String checkCookiesUrl = baseUrl + "/check.php";
    String setCookiesUrlSession = baseUrl + "/set_session.php";
    final BrowserStatus status = new BrowserStatus(bc);
    bc.setURL(clearCookiesUrl);
    status.waitReady();
    status.reset();
    bc.setURL(checkCookiesUrl);
    status.waitReady();
    Map<String, Object> res = status.getJSONContent();
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    status.reset();
    bc.setURL(setCookiesUrl);
    status.waitReady();
    status.reset();
    bc.setURL(checkCookiesUrl);
    status.waitReady();
    res = status.getJSONContent();
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
    status.reset();
    bc.setURL(clearCookiesUrl);
    status.waitReady();
    status.reset();
    bc.setURL(checkCookiesUrl);
    status.waitReady();
    res = status.getJSONContent();
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    status.reset();
    bc.setURL(setCookiesUrlSession);
    status.waitReady();
    status.reset();
    bc.setURL(checkCookiesUrl);
    status.waitReady();
    res = status.getJSONContent();
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
    // Now let's try to share cookies between the browser component and
    // a connection request.
    ConnectionRequest.setUseNativeCookieStore(true);
    Cookie.clearCookiesFromStorage();
    BrowserComponent bc2 = new BrowserComponent();
    bc.getParent().replace(bc, bc2, null);
    bc = bc2;
    f.revalidate();
    final BrowserStatus status2 = new BrowserStatus(bc);
    bc.setURL(clearCookiesUrl);
    status2.waitReady();
    status2.reset();
    // First verify that the cookie is not set in either browser or connection request
    bc.setURL(checkCookiesUrl);
    status2.waitReady();
    res = status2.getJSONContent();
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    res = ConnectionRequest.fetchJSON(checkCookiesUrl);
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    // Next let's set the cookie in the browser, and verify that it is set in both
    // browser and connection request.
    status2.reset();
    bc.setURL(setCookiesUrl);
    status2.waitReady();
    status2.reset();
    bc.setURL(checkCookiesUrl);
    status2.waitReady();
    res = status2.getJSONContent();
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
    res = ConnectionRequest.fetchJSON(checkCookiesUrl);
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
    // Now let's delete the cookie in the browser and verify that it is deleted in
    // both the browser and connection request.
    status2.reset();
    bc.setURL(clearCookiesUrl);
    status2.waitReady();
    status2.reset();
    bc.setURL(checkCookiesUrl);
    status2.waitReady();
    res = status2.getJSONContent();
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    res = ConnectionRequest.fetchJSON(checkCookiesUrl);
    TestUtils.assertBool(null == res.get("cookieval"), "Cookie should be null after clearing cookies but was " + res.get("cookieval"));
    // Now let's set the cookie in the ConnectionRequest and verify that it is set in both
    // connection request and browser.
    ConnectionRequest.fetchJSON(setCookiesUrl);
    res = ConnectionRequest.fetchJSON(checkCookiesUrl);
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
    status2.reset();
    bc.setURL(checkCookiesUrl);
    status2.waitReady();
    res = status2.getJSONContent();
    TestUtils.assertEqual("hello", res.get("cookieval"), "Cookie set to incorrect value.");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8