From e05275405689442f05ea6f3fc5da5ca1bf4636dd Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Thu, 3 Nov 2011 10:53:52 +0000 Subject: [PATCH] fix tests, group them in a gwt-suite to run in a jvm instance and speed up maven test --- gwtquery-core/pom.xml | 40 +-- .../google/gwt/query/client/LazyGQuery.java | 276 ++++++++++-------- .../client/impl/SelectorEngineCssToXPath.java | 27 ++ .../google/gwt/query/client/js/JsUtils.java | 5 + .../gwt/query/client/plugins/Events.java | 29 +- .../gwt/query/client/plugins/LazyEvents.java | 4 +- .../rebind/SelectorGeneratorCssToXPath.java | 31 +- ...ryAjaxTest.java => GQueryAjaxTestGwt.java} | 9 +- ...ryCoreTest.java => GQueryCoreTestGwt.java} | 7 +- ...ueryCssTest.java => GQueryCssTestGwt.java} | 7 +- ...ctsTest.java => GQueryEffectsTestGwt.java} | 7 +- ...entsTest.java => GQueryEventsTestGwt.java} | 56 +++- .../gwt/query/client/GQueryGwtSuiteTest.java | 31 ++ ...GQueryJsTest.java => GQueryJsTestGwt.java} | 7 +- ...sTest.java => GQuerySelectorsTestGwt.java} | 7 +- ...etsTest.java => GQueryWidgetsTestGwt.java} | 2 +- .../gwt/query/client/JreQueryCoreTest.java | 13 +- .../client/impl/SelectorEnginesTest.java | 8 +- .../client/impl/SelectorEnginesTestGwt.java | 29 ++ .../query/rebind/SelectorGeneratorsTest.java | 6 +- 20 files changed, 378 insertions(+), 223 deletions(-) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryAjaxTest.java => GQueryAjaxTestGwt.java} (94%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryCoreTest.java => GQueryCoreTestGwt.java} (99%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryCssTest.java => GQueryCssTestGwt.java} (99%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryEffectsTest.java => GQueryEffectsTestGwt.java} (99%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryEventsTest.java => GQueryEventsTestGwt.java} (93%) create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryGwtSuiteTest.java rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryJsTest.java => GQueryJsTestGwt.java} (97%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQuerySelectorsTest.java => GQuerySelectorsTestGwt.java} (99%) rename gwtquery-core/src/test/java/com/google/gwt/query/client/{GQueryWidgetsTest.java => GQueryWidgetsTestGwt.java} (98%) create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTestGwt.java diff --git a/gwtquery-core/pom.xml b/gwtquery-core/pom.xml index afd465ce..520531a4 100644 --- a/gwtquery-core/pom.xml +++ b/gwtquery-core/pom.xml @@ -70,35 +70,17 @@ - org.apache.maven.plugins - maven-surefire-plugin - - false - - - ${project.build.sourceDirectory} - - - ${project.build.testSourceDirectory} - - - - false - - always - - - both - 6 - - - gwt.args - -out target/www-junit - gwt.noserver - true - - - + org.apache.maven.plugins + maven-surefire-plugin + + + ${basedir}/src/main/java + ${basedir}/src/test/java + + + + false + org.riedelcastro diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index 5e68a6fc..1ae86eec 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -20,6 +20,7 @@ import java.util.List; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; +import com.google.gwt.core.client.JsArrayMixed; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.BodyElement; import com.google.gwt.dom.client.ButtonElement; @@ -43,12 +44,15 @@ import com.google.gwt.query.client.js.JsCache; import com.google.gwt.query.client.js.JsMap; import com.google.gwt.query.client.js.JsNamedArray; import com.google.gwt.query.client.js.JsNodeArray; +import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.query.client.js.JsRegexp; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.Effects; import com.google.gwt.query.client.plugins.Events; import com.google.gwt.query.client.plugins.Plugin; import com.google.gwt.query.client.plugins.Widgets; +import com.google.gwt.query.client.plugins.ajax.Ajax; +import com.google.gwt.query.client.plugins.ajax.Ajax.Settings; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; import com.google.gwt.query.client.plugins.events.EventsListener; import com.google.gwt.user.client.DOM; @@ -110,6 +114,7 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery andSelf(); /** + * * The animate() method allows you to create animation effects on any numeric * Attribute, CSS property, or color CSS property. * @@ -123,11 +128,10 @@ public interface LazyGQuery extends LazyBase{ * Example: * *
-   *  //move the element from its original position to the position top:500px and left:500px for 400ms.
-   *  //use a swing easing function for the transition
-   *  $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, Easing.SWING);
-   *  // Change the width and border attributes of a table
-   *  $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);
+   *  //move the element from its original position to left:500px for 500ms
+   *  $("#foo").animate("left:'500'");
+   *  // Change the width attribute of a table
+   *  $("table").animate("$width:'500'"), 400, Easing.LINEAR);
    * 
* * In addition to numeric values, each property can take the strings 'show', @@ -140,30 +144,35 @@ public interface LazyGQuery extends LazyBase{ * Example: * *
-   *  //move the element from its original position to 500px to the left and 5OOpx down for 400ms.
-   *  //use a swing easing function for the transition
-   *  $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);
+   *  //move the element from its original position to 500px to the left for 500ms and
+   *  // change the background color of the element at the end of the animation
+   *  $("#foo").animate("left:'+=500'", new Function(){
+   *                  
+   *                 public void f(Element e){
+   *                   $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED);
+   *                 }
+   *                 
+   *              });
    * 
* + * The duration of the animation is 500ms. + * * For color css properties, values can be specified via hexadecimal or rgb or * literal values. * * Example: * *
-   *  $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);
+   *  $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'");
    * 
* - * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate. + * @param prop the property to animate : "cssName:'value'" * @param funcs an array of {@link Function} called once the animation is * complete - * @param duration the duration in milliseconds of the animation - * @param easing the easing function to use for the transition */ - LazyGQuery animate(Object stringOrProperties, int duration, Easing easing, Function... funcs); + LazyGQuery animate(Object stringOrProperties, Function... funcs); /** - * * The animate() method allows you to create animation effects on any numeric * Attribute, CSS property, or color CSS property. * @@ -177,10 +186,11 @@ public interface LazyGQuery extends LazyBase{ * Example: * *
-   *  //move the element from its original position to left:500px for 500ms
-   *  $("#foo").animate("left:'500'");
-   *  // Change the width attribute of a table
-   *  $("table").animate("$width:'500'"), 400, Easing.LINEAR);
+   *  //move the element from its original position to the position top:500px and left:500px for 400ms.
+   *  //use a swing easing function for the transition
+   *  $("#foo").animate(Properties.create("{top:'500px',left:'500px'}"), 400, Easing.SWING);
+   *  // Change the width and border attributes of a table
+   *  $("table").animate(Properties.create("{$width: '500', $border: '10'}"), 400, Easing.LINEAR);
    * 
* * In addition to numeric values, each property can take the strings 'show', @@ -193,33 +203,27 @@ public interface LazyGQuery extends LazyBase{ * Example: * *
-   *  //move the element from its original position to 500px to the left for 500ms and
-   *  // change the background color of the element at the end of the animation
-   *  $("#foo").animate("left:'+=500'", new Function(){
-   *                  
-   *                 public void f(Element e){
-   *                   $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED);
-   *                 }
-   *                 
-   *              });
+   *  //move the element from its original position to 500px to the left and 5OOpx down for 400ms.
+   *  //use a swing easing function for the transition
+   *  $("#foo").animate(Properties.create("{top:'+=500px',left:'+=500px'}"), 400, Easing.SWING);
    * 
* - * The duration of the animation is 500ms. - * * For color css properties, values can be specified via hexadecimal or rgb or * literal values. * * Example: * *
-   *  $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'");
+   *  $("#foo").animate("backgroundColor:'red', color:'#ffffff', borderColor:'rgb(129, 0, 70)'"), 400, Easing.SWING);
    * 
* - * @param prop the property to animate : "cssName:'value'" + * @param stringOrProperties a String or a {@link Properties} object containing css properties to animate. * @param funcs an array of {@link Function} called once the animation is * complete + * @param duration the duration in milliseconds of the animation + * @param easing the easing function to use for the transition */ - LazyGQuery animate(Object stringOrProperties, Function... funcs); + LazyGQuery animate(Object stringOrProperties, int duration, Easing easing, Function... funcs); /** * The animate() method allows you to create animation effects on any numeric @@ -466,6 +470,17 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery closest(String selector); + /** + * Get the first ancestor element that matches the selector (for each matched + * element), beginning at the current element and progressing up through the + * DOM tree until reach the context node. + * + * If no context is passed in then the context of the gQuery object will be + * used instead. + * + */ + LazyGQuery closest(String selector, Node context); + /** * Returns a {@link Map} object as key a selector and as value the list of * ancestor elements matching this selectors, beginning at the first matched @@ -490,17 +505,6 @@ public interface LazyGQuery extends LazyBase{ */ JsNamedArray> closest(String[] selectors, Node context); - /** - * Get the first ancestor element that matches the selector (for each matched - * element), beginning at the current element and progressing up through the - * DOM tree until reach the context node. - * - * If no context is passed in then the context of the gQuery object will be - * used instead. - * - */ - LazyGQuery closest(String selector, Node context); - /** * Filter the set of elements to those that contain the specified text. */ @@ -714,12 +718,12 @@ public interface LazyGQuery extends LazyBase{ /** * Attach handlers to one or more events for all elements that * match the selector, now or in the future, based on a specific - * set of root elements. + * set of root elements. * * Example: * *
-   * $("table").delegate("td", "click", new Function(){
+   * $("table").delegate("td", Event.ONCLICK, new Function(){
    *  public void f(Element e){
    *  $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));
    *  }
@@ -732,7 +736,7 @@ public interface LazyGQuery extends LazyBase{
    * 
    * $("table").each(new Function(){
    *  public void f(Element table){
-   *   $("td", table).live("click", new Function(){
+   *   $("td", table).live(Event.ONCLICK, new Function(){
    *      public void f(Element e){
    *      $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));
    *    }
@@ -741,22 +745,21 @@ public interface LazyGQuery extends LazyBase{
    *
    * 
* - * You can pass attach the handlers to many events by specifying a String with espaced event type. + * You can attach the handlers to many events by using the '|' operator * ex: *
-   *  $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
-   * 
+ * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...}); *
*/ - LazyGQuery delegate(String selector, String eventType, Function... handlers); + LazyGQuery delegate(String selector, int eventbits, Function... handlers); /** - * Attach handlers to one or more events for all elements that - * match the selector, now or in the future, based on a specific - * set of root elements. - * + * Attach handlers to one or more events for all elements that match the selector, + * now or in the future, based on a specific set of root elements. + * The data parameter allows us + * to pass data to the handler. + * * Example: - * *
    * $("table").delegate("td", "click", new Function(){
    *  public void f(Element e){
@@ -764,10 +767,8 @@ public interface LazyGQuery extends LazyBase{
    *  }
    * });
    * 
- * - * This code above add an handler on click event on all cell (the existing - * oneand the future cell) of all table. This code is equivalent to : - * + * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table. + * This code is equivalent to : *
    * $("table").each(new Function(){
    *  public void f(Element table){
@@ -778,24 +779,25 @@ public interface LazyGQuery extends LazyBase{
    *  }
    * });
    *
-   * You can pass attach the handlers to many events by specifying a String with espaced event type.
+   * 
+ * + * You can pass attach the handlers to many events by using the '|' operator * ex: *
-   *  $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
-   * 
+ * $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...}); * */ - LazyGQuery delegate(String selector, String eventType, Object data, Function... handlers); + LazyGQuery delegate(String selector, int eventbits, Object data, Function... handlers); /** * Attach handlers to one or more events for all elements that * match the selector, now or in the future, based on a specific - * set of root elements. + * set of root elements. * * Example: * *
-   * $("table").delegate("td", Event.ONCLICK, new Function(){
+   * $("table").delegate("td", "click", new Function(){
    *  public void f(Element e){
    *  $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));
    *  }
@@ -808,7 +810,7 @@ public interface LazyGQuery extends LazyBase{
    * 
    * $("table").each(new Function(){
    *  public void f(Element table){
-   *   $("td", table).live(Event.ONCLICK, new Function(){
+   *   $("td", table).live("click", new Function(){
    *      public void f(Element e){
    *      $(e).css(CSS.BACKGROUND_COLOR.with(RGBColor.RED));
    *    }
@@ -817,21 +819,22 @@ public interface LazyGQuery extends LazyBase{
    *
    * 
* - * You can attach the handlers to many events by using the '|' operator + * You can pass attach the handlers to many events by specifying a String with espaced event type. * ex: *
-   *  $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});
+   *  $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
+   * 
*
*/ - LazyGQuery delegate(String selector, int eventbits, Function... handlers); + LazyGQuery delegate(String selector, String eventType, Function... handlers); /** - * Attach handlers to one or more events for all elements that match the selector, - * now or in the future, based on a specific set of root elements. - * The data parameter allows us - * to pass data to the handler. - * + * Attach handlers to one or more events for all elements that + * match the selector, now or in the future, based on a specific + * set of root elements. + * * Example: + * *
    * $("table").delegate("td", "click", new Function(){
    *  public void f(Element e){
@@ -839,8 +842,10 @@ public interface LazyGQuery extends LazyBase{
    *  }
    * });
    * 
- * This code above add an handler on click event on all cell (the existing oneand the future cell) of all table. - * This code is equivalent to : + * + * This code above add an handler on click event on all cell (the existing + * oneand the future cell) of all table. This code is equivalent to : + * *
    * $("table").each(new Function(){
    *  public void f(Element table){
@@ -851,15 +856,14 @@ public interface LazyGQuery extends LazyBase{
    *  }
    * });
    *
-   * 
- * - * You can pass attach the handlers to many events by using the '|' operator + * You can pass attach the handlers to many events by specifying a String with espaced event type. * ex: *
-   *  $("div.main").delegate(".subMain", Event.ONCLICK | Event.ONDBLCLICK, new Function(){...});
+   *  $("div.main").delegate(".subMain", "click dblclick", new Function(){...});
+   * 
* */ - LazyGQuery delegate(String selector, int eventbits, Object data, Function... handlers); + LazyGQuery delegate(String selector, String eventType, Object data, Function... handlers); /** * Execute the next function on the Effects queue for the matched elements. @@ -905,19 +909,19 @@ public interface LazyGQuery extends LazyBase{ /** * Remove an event handlers previously attached using - * {@link #live(String, Function)} In order for this method to function + * {@link #live(int, Function)} In order for this method to function * correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(String, Function)} + * initially used with {@link #live(int, Function)} */ - LazyGQuery die(String eventName); + LazyGQuery die(int eventbits); /** * Remove an event handlers previously attached using - * {@link #live(int, Function)} In order for this method to function + * {@link #live(String, Function)} In order for this method to function * correctly, the selector used with it must match exactly the selector - * initially used with {@link #live(int, Function)} + * initially used with {@link #live(String, Function)} */ - LazyGQuery die(int eventbits); + LazyGQuery die(String eventName); /** * Run one or more Functions over each element of the GQuery. You have to @@ -1083,15 +1087,15 @@ public interface LazyGQuery extends LazyBase{ /** * Reduce the set of matched elements to those that have a descendant - * that matches the selector. + * that matches the Element. */ - LazyGQuery has(String selector); + LazyGQuery has(Element elem); /** * Reduce the set of matched elements to those that have a descendant - * that matches the Element. + * that matches the selector. */ - LazyGQuery has(Element elem); + LazyGQuery has(String selector); /** * Returns true any of the specified classes are present on any of the matched @@ -1225,6 +1229,11 @@ public interface LazyGQuery extends LazyBase{ */ boolean isEmpty(); + /** + * Return true if the first element is visible.isVisible + */ + boolean isVisible(); + /** * Bind a set of functions to the keydown event of each matched element. Or * trigger the event if no functions are provided. @@ -1274,6 +1283,18 @@ public interface LazyGQuery extends LazyBase{ */ int length(); + /** + * Attach a handler for this event to all elements which match the current + * selector, now and in the future. + */ + LazyGQuery live(int eventbits, Function... funcs); + + /** + * Attach a handler for this event to all elements which match the current + * selector, now and in the future. + */ + LazyGQuery live(int eventbits, Object data, Function... funcs); + /** *

* Attach a handler for this event to all elements which match the current @@ -1327,18 +1348,6 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery live(String eventName, Function... funcs); - /** - * Attach a handler for this event to all elements which match the current - * selector, now and in the future. - */ - LazyGQuery live(int eventbits, Function... funcs); - - /** - * Attach a handler for this event to all elements which match the current - * selector, now and in the future. - */ - LazyGQuery live(int eventbits, Object data, Function... funcs); - /** *

* Attach a handler for this event to all elements which match the current @@ -1394,9 +1403,28 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery live(String eventName, Object data, Function... funcs); /** - * Bind a function to the load event of each matched element. + * Load data from the server and place the returned HTML into the matched element. + * + * The url allows us to specify a portion of the remote document to be inserted. + * This is achieved with a special syntax for the url parameter. + * If one or more space characters are included in the string, the portion of + * the string following the first space is assumed to be a GQuery selector that + * determines the content to be loaded. + * */ - LazyGQuery load(Function f); + LazyGQuery load(String url); + + /** + * Load data from the server and place the returned HTML into the matched element. + * + * The url allows us to specify a portion of the remote document to be inserted. + * This is achieved with a special syntax for the url parameter. + * If one or more space characters are included in the string, the portion of + * the string following the first space is assumed to be a GQuery selector that + * determines the content to be loaded. + * + */ + LazyGQuery load(String url, Properties data, Function onSuccess); /** * Reduce the set of matched elements to all elements before a given position. @@ -1703,12 +1731,6 @@ public interface LazyGQuery extends LazyBase{ */ int queue(); - /** - * Show the number of functions in the queued named as queueName to be - * executed on the first matched element. - */ - int queue(String queueName); - /** * Put a set of {@link Function} at the end of the Effects queue. * @@ -1738,6 +1760,12 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery queue(Function... f); + /** + * Show the number of functions in the queued named as queueName to be + * executed on the first matched element. + */ + int queue(String queueName); + /** * Put a set of {@link Function} at the end of a queue. * @@ -1856,14 +1884,14 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery resize(Function... f); /** - * Save a set of Css properties of every matched element. + * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. */ - void restoreCssAttrs(String... cssProps); + LazyGQuery resize(Function f); /** - * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. + * Save a set of Css properties of every matched element. */ - LazyGQuery resize(Function f); + void restoreCssAttrs(String... cssProps); /** * Restore a set of previously saved Css properties in every matched element. @@ -2042,7 +2070,7 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery submit(Function... funcs); /** - * Return the text contained in the first matched element. + * Return the concatened text contained in the matched elements. */ String text(); @@ -2077,7 +2105,7 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery toggleClass(String clz, boolean addOrRemove); /** - * Returns the computed left position of the first element matched. + * Returns the computed top position of the first element matched. */ int top(); @@ -2107,6 +2135,11 @@ public interface LazyGQuery extends LazyBase{ */ LazyGQuery unbind(int eventbits); + /** + * Removes all events that match the eventList. + */ + LazyGQuery unbind(String eventList); + /** * Remove all event delegation that have been bound using * {@link #delegate(String, int, Function...)} {@link #live(int, Function...)} methods @@ -2123,13 +2156,13 @@ public interface LazyGQuery extends LazyBase{ * Undelegate is a way of removing event handlers that have been bound using * {@link #delegate(String, int, Function...)} method */ - LazyGQuery undelegate(String selector, String eventName); + LazyGQuery undelegate(String selector, int eventBit); /** * Undelegate is a way of removing event handlers that have been bound using * {@link #delegate(String, int, Function...)} method */ - LazyGQuery undelegate(String selector, int eventBit); + LazyGQuery undelegate(String selector, String eventName); /** * Remove all duplicate elements from an array of elements. Note that this @@ -2210,11 +2243,6 @@ public interface LazyGQuery extends LazyBase{ */ String[] vals(); - /** - * Return true if the first element is visible.isVisible - */ - boolean isVisible(); - /** * Return the first non null attached widget from the matched elements or null * if there isn't any. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index 9f385dfb..beb89003 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -27,6 +27,7 @@ import com.google.gwt.query.client.js.JsNodeArray; import com.google.gwt.query.client.js.JsObjectArray; import com.google.gwt.query.client.js.JsRegexp; import com.google.gwt.query.client.js.JsUtils; +import com.google.gwt.regexp.shared.RegExp; /** * Runtime selector engine implementation which translates selectors to XPath @@ -192,6 +193,32 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { } } }; + + /** + * A replacer which works in both sides. Right now gquery JsRegexp is faster + * than gwt shared RegExp and does not uses HashSet + */ + public static final Replacer replacerGwt = new Replacer() { + public String replaceAll(String s, String r, Object o) { + RegExp p = RegExp.compile(r, "g"); + if (o instanceof ReplaceCallback) { + ReplaceCallback callback = (ReplaceCallback) o; + com.google.gwt.regexp.shared.MatchResult a = null; + while ((a = p.exec(s)) != null) { + ArrayList args = new ArrayList(); + for (int i = 0; i < a.getGroupCount(); i++) { + args.add(a.getGroup(i)); + } + String f = callback.foundMatch(args); + s = s.replace(a.getGroup(0), f); + p = RegExp.compile(r, "g"); + } + return s; + } else { + return p.replace(s, o.toString()); + } + } + }; public SelectorEngineCssToXPath() { instance = this; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index e1103033..5dac2578 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -314,4 +314,9 @@ public class JsUtils { return Properties.create(); } } + + public static native boolean isDefaultPrevented(JavaScriptObject e)/*-{ + return e.defaultPrevented || e.returnValue === false || e.getPreventDefault && e.getPreventDefault() ? true : false; + }-*/; + } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index 95a92a19..e9bfaeaf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -228,20 +228,27 @@ public class Events extends GQuery { if ((eventbits | Event.ONMOUSEWHEEL) == Event.ONMOUSEWHEEL) dispatchEvent(document.createMouseEvent("mousewheel", true, true, 0, 0, 0, 0, 0, false, false, false, false, NativeEvent.BUTTON_LEFT, null)); - if (eventbits == EventsListener.ONSUBMIT) - triggerHtmlEvent("submit"); + if (eventbits == EventsListener.ONSUBMIT) { + Event evt = document.createHtmlEvent("submit", true, true).cast(); + dispatchEvent(evt, new Function() { + public native void f(Element e) /*-{ + e.submit(); + }-*/; + }); + } if (eventbits == EventsListener.ONRESIZE) triggerHtmlEvent("resize"); return this; } - + /** * Trigger a html event in all matched elements. * * @param htmlEvent An string representing the html event desired + * @functions a set of function to run if the event is not canceled. */ - public Events triggerHtmlEvent(String htmlEvent) { - dispatchEvent(document.createHtmlEvent(htmlEvent, true, true)); + public Events triggerHtmlEvent(String htmlEvent, Function...functions) { + dispatchEvent(document.createHtmlEvent(htmlEvent, true, true), functions); return this; } @@ -289,11 +296,17 @@ public class Events extends GQuery { } return this; } - - private void dispatchEvent(NativeEvent evt) { + + private void dispatchEvent(NativeEvent evt, Function...funcs) { for (Element e : elements()) { if (isEventCapable(e)){ e.dispatchEvent(evt); + if (!JsUtils.isDefaultPrevented(evt)){ + for (Function f: funcs) { + f.setEvent(Event.as(evt)); + f.f(e); + } + } } } } @@ -306,7 +319,5 @@ public class Events extends GQuery { } return this; } - - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java index 0dc01b72..2e8bac07 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java @@ -19,6 +19,7 @@ import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; +import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.events.EventsListener; import com.google.gwt.user.client.Event; import com.google.gwt.query.client.LazyBase; @@ -114,8 +115,9 @@ public interface LazyEvents extends LazyBase{ * Trigger a html event in all matched elements. * * @param htmlEvent An string representing the html event desired + * @functions a set of function to run if the event is not canceled. */ - LazyEvents triggerHtmlEvent(String htmlEvent); + LazyEvents triggerHtmlEvent(String htmlEvent, Function...functions); /** * Removes all handlers, that matches the events bits passed, from each diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java index a90b6fe2..a726b6bd 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/rebind/SelectorGeneratorCssToXPath.java @@ -31,7 +31,6 @@ import com.google.gwt.query.client.Selector; import com.google.gwt.query.client.impl.SelectorEngineCssToXPath; import com.google.gwt.query.client.impl.SelectorEngineCssToXPath.ReplaceCallback; import com.google.gwt.query.client.impl.SelectorEngineCssToXPath.Replacer; -import com.google.gwt.regexp.shared.RegExp; import com.google.gwt.user.rebind.SourceWriter; /** @@ -44,7 +43,7 @@ public class SelectorGeneratorCssToXPath extends SelectorGeneratorBase { /** * The replacer implementation for the JVM. */ - public static final Replacer replacerJvm = new Replacer() { + public static final Replacer replacer = new Replacer() { public String replaceAll(String s, String r, Object o) { Pattern p = Pattern.compile(r); if (o instanceof ReplaceCallback) { @@ -68,34 +67,6 @@ public class SelectorGeneratorCssToXPath extends SelectorGeneratorBase { } }; - /** - * A replacer which works in both sides. Right now gquery JsRegexp is faster - * than gwt shared RegExp and does not uses HashSet - */ - public static final Replacer replacerGwt = new Replacer() { - public String replaceAll(String s, String r, Object o) { - RegExp p = RegExp.compile(r, "g"); - if (o instanceof ReplaceCallback) { - ReplaceCallback callback = (ReplaceCallback) o; - com.google.gwt.regexp.shared.MatchResult a = null; - while ((a = p.exec(s)) != null) { - ArrayList args = new ArrayList(); - for (int i = 0; i < a.getGroupCount(); i++) { - args.add(a.getGroup(i)); - } - String f = callback.foundMatch(args); - s = s.replace(a.getGroup(0), f); - p = RegExp.compile(r, "g"); - } - return s; - } else { - return p.replace(s, o.toString()); - } - } - }; - - public static final Replacer replacer = replacerGwt; - private SelectorEngineCssToXPath engine = new SelectorEngineCssToXPath( replacer); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java similarity index 94% rename from gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java rename to gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java index 7056a9a3..231db889 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java @@ -16,6 +16,8 @@ package com.google.gwt.query.client; +import static com.google.gwt.query.client.GQuery.$; + import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.junit.client.GWTTestCase; @@ -28,7 +30,7 @@ import com.google.gwt.user.client.ui.RootPanel; /** * Test class for testing ajax stuff. */ -public class GQueryAjaxTest extends GWTTestCase { +public class GQueryAjaxTestGwt extends GWTTestCase { static Element e = null; @@ -38,6 +40,11 @@ public class GQueryAjaxTest extends GWTTestCase { return "com.google.gwt.query.Query"; } + public void gwtTearDown() { + $(e).remove(); + e = null; + } + public void gwtSetUp() { if (e == null) { testPanel = new HTML(); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java similarity index 99% rename from gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java rename to gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java index 0149df5a..347adb1a 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java @@ -55,7 +55,7 @@ import java.util.List; /** * Test class for testing gwtquery-core api. */ -public class GQueryCoreTest extends GWTTestCase { +public class GQueryCoreTestGwt extends GWTTestCase { static Element e = null; @@ -82,6 +82,11 @@ public class GQueryCoreTest extends GWTTestCase { return "com.google.gwt.query.Query"; } + public void gwtTearDown() { + $(e).remove(); + e = null; + } + public void gwtSetUp() { if (e == null || DOM.getElementById("core-tst") == null) { testPanel = new HTML(); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTestGwt.java similarity index 99% rename from gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java rename to gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTestGwt.java index 9ad7d71e..561a029e 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTestGwt.java @@ -59,7 +59,7 @@ import com.google.gwt.user.client.ui.RootPanel; /** * Test class for testing css part. */ -public class GQueryCssTest extends GWTTestCase { +public class GQueryCssTestGwt extends GWTTestCase { static Element e = null; @@ -68,6 +68,11 @@ public class GQueryCssTest extends GWTTestCase { public String getModuleName() { return "com.google.gwt.query.Query"; } + + public void gwtTearDown() { + $(e).remove(); + e = null; + } public void gwtSetUp() { if (e == null) { diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java similarity index 99% rename from gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java rename to gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java index bc4f1b7f..f286d6f9 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java @@ -32,7 +32,7 @@ import com.google.gwt.user.client.ui.RootPanel; /** * Test class for testing gwtquery effects plugin api. */ -public class GQueryEffectsTest extends GWTTestCase { +public class GQueryEffectsTestGwt extends GWTTestCase { static Element e = null; @@ -42,6 +42,11 @@ public class GQueryEffectsTest extends GWTTestCase { return "com.google.gwt.query.Query"; } + public void gwtTearDown() { + $(e).remove(); + e = null; + } + public void gwtSetUp() { if (e == null) { testPanel = new HTML(); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java similarity index 93% rename from gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java rename to gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index 601d9e99..5a8ba73e 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java @@ -40,7 +40,7 @@ import com.google.gwt.user.client.ui.RootPanel; /** * Test class for testing gwt events plugin api. */ -public class GQueryEventsTest extends GWTTestCase { +public class GQueryEventsTestGwt extends GWTTestCase { static Element e = null; @@ -51,6 +51,11 @@ public class GQueryEventsTest extends GWTTestCase { public String getModuleName() { return "com.google.gwt.query.Query"; } + + public void gwtTearDown() { + $(e).remove(); + e = null; + } public void gwtSetUp() { if (e == null) { @@ -731,7 +736,39 @@ public void testUnDelegateAll2(){ g.width(400); g.resize(); } - + + public void testBindUnbindSubmitEvent() { + // Add a form and an iframe to the dom. The form target is the iframe + $(e).html("