From 165102a8b462de613e1d6a928149ee1c9af19bcb Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 24 Nov 2010 11:30:52 +0000 Subject: updating to gwt 2.1.0 and fixing compilation (patch by julien.dramaix) and tests for it. fixes issue59 and issue58 --- .../com/google/gwt/query/client/DevTestRunner.java | 221 ++++++++++++++++++++- 1 file changed, 220 insertions(+), 1 deletion(-) (limited to 'devtest') diff --git a/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java index 193635fc..eaf890ec 100644 --- a/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java +++ b/devtest/src/main/java/com/google/gwt/query/client/DevTestRunner.java @@ -16,19 +16,29 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.GQuery.$; +import static com.google.gwt.query.client.GQuery.document; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NodeList; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.FocusHandler; import com.google.gwt.event.shared.GwtEvent; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.query.client.impl.SelectorEngineImpl; import com.google.gwt.query.client.plugins.Events; +import com.google.gwt.query.client.plugins.Widgets; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.FlowPanel; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.Widget; /** * This module is thought to emulate a test environment similar to @@ -50,13 +60,222 @@ public class DevTestRunner extends MyTestCase implements EntryPoint { public void onModuleLoad() { try { gwtSetUp(); - testSiblings(); + testEventsPlugin(); } catch (Exception ex) { ex.printStackTrace(); $(e).html("").after("
ERROR: " + ex.getMessage() + "
"); } } + public void testEventsPlugin() { + $(e).html("

Content

"); + + // click + $("p", e).click(new Function() { + public void f(Element elem) { + $(elem).css("color", "red"); + } + }, new Function() { + public void f(Element elem) { + $(elem).css("background", "green"); + } + }); + $("p", e, Events.Events).trigger(Event.ONCLICK); + assertEquals("red", $("p", e).css("color")); + assertEquals("green", $("p", e).css("background-color")); + + // unbind + $("p", e).css("color", "white"); + $("p", e).unbind(Event.ONCLICK); + $("p", e).click(); + assertEquals("white", $("p", e).css("color")); + + // toggle + $("p", e).unbind(Event.ONCLICK); + $("p", e).toggle(new Function() { + public void f(Element elem) { + $(elem).css("color", "red"); + } + }, new Function() { + public void f(Element elem) { + $(elem).css("color", "blue"); + } + }); + $("p", e).click(); + assertEquals("red", $("p", e).css("color")); + $("p", e).click(); + assertEquals("blue", $("p", e).css("color")); + + // one + $("p", e).unbind(Event.ONCLICK); + $("p", e).one(Event.ONCLICK, null, new Function() { + public void f(Element elem) { + $(elem).css("color", "red"); + } + }); + $("p", e).click(); + assertEquals("red", $("p", e).css("color")); + $("p", e).css("color", "white"); + $("p", e).click(); + assertEquals("white", $("p", e).css("color")); + + // hover (mouseover, mouseout) + $("p", e).hover(new Function() { + public void f(Element elem) { + $(elem).css("background-color", "yellow"); + } + }, new Function() { + public void f(Element elem) { + $(elem).css("background-color", "white"); + } + }); + $("p", e).trigger(Event.ONMOUSEOVER); + assertEquals("yellow", $("p", e).css("background-color")); + $("p", e).trigger(Event.ONMOUSEOUT); + assertEquals("white", $("p", e).css("background-color")); + + // focus + $("p", e).focus(new Function() { + public void f(Element elem) { + $(elem).css("border", "1px dotted black"); + } + }); + $("p", e).focus(); + assertEquals("black", $("p", e).css("border-top-color")); + assertEquals("dotted", $("p", e).css("border-top-style")); + assertEquals("1px", $("p", e).css("border-top-width")); + + // blur + $("p", e).blur(new Function() { + public void f(Element elem) { + $(elem).css("border", ""); + } + }); + $("p", e).blur(); + assertEquals("", $("p", e).css("border")); + + // key events + $(e).html(""); + Function keyEventAction = new Function() { + public boolean f(Event evnt) { + GQuery gq = $(evnt); + gq.val(gq.val() + Character.toString((char) evnt.getKeyCode())); + return false; + } + }; + $("input", e).keypress(keyEventAction); + $("input", e).keydown(keyEventAction); + $("input", e).keyup(keyEventAction); + $("input", e).focus(); + $("input", e).keydown('a'); + $("input", e).keypress('b'); + $("input", e).keyup('c'); + assertEquals("abc", $("input", e).val()); + } + + public void testUnbindMultipleEvents() { + String content = "

content

"; + $(e).html(content); + $(document).bind(Event.ONMOUSEMOVE, null, new Function() { + public void f(Element e){ + $("p").css("color", "red"); + } + }); + $(document).bind(Event.ONMOUSEUP, null, new Function(){ + public void f(Element e){ + $("p").css("color", "yellow"); + } + }); + $(document).trigger(Event.ONMOUSEMOVE); + assertEquals("red", $("p").css("color")); + $(document).trigger(Event.ONMOUSEUP); + assertEquals("yellow", $("p").css("color")); + $("p").css("color", "black"); + $(document).unbind(Event.ONMOUSEUP|Event.ONMOUSEMOVE); + $(document).trigger(Event.ONMOUSEMOVE); + assertEquals("black", $("p").css("color")); + $(document).trigger(Event.ONMOUSEUP); + assertEquals("black", $("p").css("color")); + } + + public void testGWTQueryCoreWidgets() { + final FlowPanel p = new FlowPanel(); + Button b = new Button("test"); + RootPanel.get().add(b); + RootPanel.get().add(p); + + int nitems = 4; + final String label1 = "I'm the label "; + final String label2 = "Finally I'm just a simple label"; + + for (int i = 0; i < nitems; i++) { + Label l = new Label(label1 + i); + p.add(l); + } + $("
whateverClick-me").appendTo(document).asWidget(); + b2.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + $(b1).css("color", "red"); + } + }); + + b2.click(); + assertEquals("red", $(b1).css("color")); + } + public void testSiblings() { String content = "
12
12
"; $(e).html(content); -- cgit v1.2.3