Search in sources :

Example 1 with JavaScriptObject

use of org.gwtproject.core.client.JavaScriptObject in project gwtproject by treblereel.

the class ElementTest method testProperties.

/**
 * setProperty*, getProperty*.
 */
@Test
public void testProperties() {
    DivElement div = Document.get().createDivElement();
    div.setPropertyString("foo", "bar");
    assertEquals("bar", div.getPropertyString("foo"));
    div.setPropertyInt("foo", 42);
    assertEquals(42, div.getPropertyInt("foo"));
    div.setPropertyBoolean("foo", true);
    div.setPropertyBoolean("bar", false);
    assertTrue(div.getPropertyBoolean("foo"));
    assertFalse(div.getPropertyBoolean("bar"));
    Object obj = new Object();
    div.setPropertyObject("baz", obj);
    assertEquals(obj, div.getPropertyObject("baz"));
    JavaScriptObject jso = JavaScriptObject.createObject();
    div.setPropertyJSO("tintin", jso);
    assertEquals(jso, div.getPropertyJSO("tintin"));
    assertNull(div.getPropertyObject("inexistant_property_at_least_we_hope_so"));
    div.setPropertyObject("baz", Boolean.TRUE);
    assertEquals(Boolean.TRUE, div.getPropertyObject("baz"));
    div.setPropertyObject("baz", Boolean.FALSE);
    assertEquals(Boolean.FALSE, div.getPropertyObject("baz"));
    div.setPropertyObject("baz", 42.0);
    assertEquals(42.0, div.getPropertyObject("baz"));
    div.setPropertyObject("baz", 0.0);
    assertEquals(0.0, div.getPropertyObject("baz"));
    div.setPropertyObject("baz", Double.NaN);
    assertTrue(Double.isNaN((Double) div.getPropertyObject("baz")));
    div.setPropertyObject("baz", "tintin");
    assertEquals("tintin", div.getPropertyObject("baz"));
    div.setPropertyObject("baz", "");
    assertEquals("", div.getPropertyObject("baz"));
}
Also used : JavaScriptObject(org.gwtproject.core.client.JavaScriptObject) JavaScriptObject(org.gwtproject.core.client.JavaScriptObject) Test(org.junit.Test)

Example 2 with JavaScriptObject

use of org.gwtproject.core.client.JavaScriptObject in project gwtproject by treblereel.

the class NodeTest method testIsAndAs.

/**
 * Tests Element.is() and Element.as().
 */
@Test
public void testIsAndAs() {
    assertTrue(Node.is(Document.get()));
    JavaScriptObject text = Document.get().createTextNode("foo");
    assertTrue(Node.is(text));
    // Node.is(null) is allowed and should return false.
    assertFalse(Node.is(null));
}
Also used : JavaScriptObject(org.gwtproject.core.client.JavaScriptObject) Test(org.junit.Test)

Example 3 with JavaScriptObject

use of org.gwtproject.core.client.JavaScriptObject in project gwtproject by treblereel.

the class CustomEventsTest method getBitlessCustomDisptachers.

private static JavaScriptObject getBitlessCustomDisptachers() {
    JsPropertyMap result = JsPropertyMap.of();
    Fn fn = event -> {
        DOMImplStandard.dispatchEvent(event);
        String title = Js.uncheckedCast(Js.asPropertyMap(Js.asPropertyMap(event).get("target")).get("title"));
        Js.asPropertyMap(Js.asPropertyMap(event).get("target")).set("title", title + "-custom_method");
    };
    result.set("c2", fn);
    return Js.uncheckedCast(result);
}
Also used : Event(elemental2.dom.Event) Element(org.gwtproject.dom.client.Element) EventHandler(org.gwtproject.event.legacy.shared.EventHandler) JsPropertyMap(jsinterop.base.JsPropertyMap) Button(org.gwtproject.user.client.ui.Button) JavaScriptObject(org.gwtproject.core.client.JavaScriptObject) J2clTestInput(com.google.j2cl.junit.apt.J2clTestInput) DOMImplStandard(org.gwtproject.user.client.impl.DOMImplStandard) DOMImplStandardBase(org.gwtproject.user.client.impl.DOMImplStandardBase) DomEvent(org.gwtproject.event.dom.client.DomEvent) GWTTestCase(com.google.gwt.junit.client.GWTTestCase) Js(jsinterop.base.Js) NativeEvent(org.gwtproject.dom.client.NativeEvent) JsFunction(jsinterop.annotations.JsFunction) RootPanel(org.gwtproject.user.client.ui.RootPanel) JsPropertyMap(jsinterop.base.JsPropertyMap)

Aggregations

JavaScriptObject (org.gwtproject.core.client.JavaScriptObject)3 Test (org.junit.Test)2 GWTTestCase (com.google.gwt.junit.client.GWTTestCase)1 J2clTestInput (com.google.j2cl.junit.apt.J2clTestInput)1 Event (elemental2.dom.Event)1 JsFunction (jsinterop.annotations.JsFunction)1 Js (jsinterop.base.Js)1 JsPropertyMap (jsinterop.base.JsPropertyMap)1 Element (org.gwtproject.dom.client.Element)1 NativeEvent (org.gwtproject.dom.client.NativeEvent)1 DomEvent (org.gwtproject.event.dom.client.DomEvent)1 EventHandler (org.gwtproject.event.legacy.shared.EventHandler)1 DOMImplStandard (org.gwtproject.user.client.impl.DOMImplStandard)1 DOMImplStandardBase (org.gwtproject.user.client.impl.DOMImplStandardBase)1 Button (org.gwtproject.user.client.ui.Button)1 RootPanel (org.gwtproject.user.client.ui.RootPanel)1