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");
}
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");
}
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");
}
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);
}
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.");
}
Aggregations