From e05275405689442f05ea6f3fc5da5ca1bf4636dd Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Thu, 3 Nov 2011 10:53:52 +0000 Subject: fix tests, group them in a gwt-suite to run in a jvm instance and speed up maven test --- gwtquery-core/pom.xml | 40 +- .../com/google/gwt/query/client/LazyGQuery.java | 276 +-- .../client/impl/SelectorEngineCssToXPath.java | 27 + .../com/google/gwt/query/client/js/JsUtils.java | 5 + .../google/gwt/query/client/plugins/Events.java | 29 +- .../gwt/query/client/plugins/LazyEvents.java | 4 +- .../query/rebind/SelectorGeneratorCssToXPath.java | 31 +- .../google/gwt/query/client/GQueryAjaxTest.java | 115 - .../google/gwt/query/client/GQueryAjaxTestGwt.java | 122 + .../google/gwt/query/client/GQueryCoreTest.java | 1820 --------------- .../google/gwt/query/client/GQueryCoreTestGwt.java | 1825 +++++++++++++++ .../com/google/gwt/query/client/GQueryCssTest.java | 1144 ---------- .../google/gwt/query/client/GQueryCssTestGwt.java | 1149 ++++++++++ .../google/gwt/query/client/GQueryEffectsTest.java | 422 ---- .../gwt/query/client/GQueryEffectsTestGwt.java | 427 ++++ .../google/gwt/query/client/GQueryEventsTest.java | 834 ------- .../gwt/query/client/GQueryEventsTestGwt.java | 874 ++++++++ .../gwt/query/client/GQueryGwtSuiteTest.java | 31 + .../com/google/gwt/query/client/GQueryJsTest.java | 135 -- .../google/gwt/query/client/GQueryJsTestGwt.java | 140 ++ .../gwt/query/client/GQuerySelectorsTest.java | 2342 ------------------- .../gwt/query/client/GQuerySelectorsTestGwt.java | 2347 ++++++++++++++++++++ .../google/gwt/query/client/GQueryWidgetsTest.java | 137 -- .../gwt/query/client/GQueryWidgetsTestGwt.java | 137 ++ .../google/gwt/query/client/JreQueryCoreTest.java | 13 +- .../gwt/query/client/impl/SelectorEnginesTest.java | 8 +- .../query/client/impl/SelectorEnginesTestGwt.java | 29 + .../gwt/query/rebind/SelectorGeneratorsTest.java | 6 +- 28 files changed, 7312 insertions(+), 7157 deletions(-) delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCssTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryGwtSuiteTest.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryJsTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTestGwt.java delete mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryWidgetsTest.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryWidgetsTestGwt.java create mode 100644 gwtquery-core/src/test/java/com/google/gwt/query/client/impl/SelectorEnginesTestGwt.java (limited to 'gwtquery-core') 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/GQueryAjaxTest.java deleted file mode 100644 index 7056a9a3..00000000 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client; - - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Element; -import com.google.gwt.junit.client.GWTTestCase; -import com.google.gwt.query.client.builders.JsonBuilder; -import com.google.gwt.query.client.builders.Name; -import com.google.gwt.query.client.builders.XmlBuilder; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.RootPanel; - -/** - * Test class for testing ajax stuff. - */ -public class GQueryAjaxTest extends GWTTestCase { - - static Element e = null; - - static HTML testPanel = null; - - public String getModuleName() { - return "com.google.gwt.query.Query"; - } - - public void gwtSetUp() { - if (e == null) { - testPanel = new HTML(); - RootPanel.get().add(testPanel); - e = testPanel.getElement(); - e.setId("core-tst"); - } else { - e.setInnerHTML(""); - } - } - - interface JsonExample extends JsonBuilder { - int getA(); - JsonExample getB(); - @Name("u") - String getUrl(); - long getD(); - Boolean getZ(); - String[] getT(); - JsonExample setT(String[] strings); - JsonExample setZ(Boolean b); - JsonExample setD(long l); - } - - public void testJsonBuilder() { - String json = "[{a:1, b:{a:2,b:{a:3}},u:url, d:'2','t':['hola','adios'], 'z': true}]"; - JsonExample c = GWT.create(JsonExample.class); - assertEquals(0, c.getA()); - c.parse(json, true); - assertEquals(1, c.getA()); - assertNotNull(c.getB()); - assertEquals(2, c.getB().getA()); - assertEquals(3, c.getB().getB().getA()); - assertTrue(c.getZ()); - assertEquals("hola", c.getT()[0]); - assertEquals("adios", c.getT()[1]); - assertEquals("url", c.getUrl()); - c.setT(new String[]{"foo", "bar"}) - .setZ(false).setD(1234); - assertFalse(c.getZ()); - assertEquals("foo", c.getT()[0]); - assertEquals("bar", c.getT()[1]); - assertEquals(1234l, c.getD()); - - } - - interface XmlExample extends XmlBuilder { - String getA(); - Boolean getB(); - @Name("c") - int getNumber(); - - XmlExample[] getX(); - @Name("x") - XmlExample getFirstX(); - - XmlExample setA(String s); - @Name("c") - XmlExample setNumber(int i); - } - - public void testXmlBuilder() { - String xml = " text"; - XmlExample x = GWT.create(XmlExample.class); - x.parse(xml); - assertTrue(x.getB()); - assertEquals("ra", x.getA()); - assertEquals(-1, x.getNumber()); - assertEquals("xa2", x.getX()[1].getA()); - assertEquals("xa1", x.getFirstX().getA()); - x.setA("X").setNumber(1234); - assertEquals("X", x.getA()); - assertEquals(1234, x.getNumber()); - } -} diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java new file mode 100644 index 00000000..231db889 --- /dev/null +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryAjaxTestGwt.java @@ -0,0 +1,122 @@ +/* + * Copyright 2011, The gwtquery team. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +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; +import com.google.gwt.query.client.builders.JsonBuilder; +import com.google.gwt.query.client.builders.Name; +import com.google.gwt.query.client.builders.XmlBuilder; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.RootPanel; + +/** + * Test class for testing ajax stuff. + */ +public class GQueryAjaxTestGwt extends GWTTestCase { + + static Element e = null; + + static HTML testPanel = null; + + public String getModuleName() { + return "com.google.gwt.query.Query"; + } + + public void gwtTearDown() { + $(e).remove(); + e = null; + } + + public void gwtSetUp() { + if (e == null) { + testPanel = new HTML(); + RootPanel.get().add(testPanel); + e = testPanel.getElement(); + e.setId("core-tst"); + } else { + e.setInnerHTML(""); + } + } + + interface JsonExample extends JsonBuilder { + int getA(); + JsonExample getB(); + @Name("u") + String getUrl(); + long getD(); + Boolean getZ(); + String[] getT(); + JsonExample setT(String[] strings); + JsonExample setZ(Boolean b); + JsonExample setD(long l); + } + + public void testJsonBuilder() { + String json = "[{a:1, b:{a:2,b:{a:3}},u:url, d:'2','t':['hola','adios'], 'z': true}]"; + JsonExample c = GWT.create(JsonExample.class); + assertEquals(0, c.getA()); + c.parse(json, true); + assertEquals(1, c.getA()); + assertNotNull(c.getB()); + assertEquals(2, c.getB().getA()); + assertEquals(3, c.getB().getB().getA()); + assertTrue(c.getZ()); + assertEquals("hola", c.getT()[0]); + assertEquals("adios", c.getT()[1]); + assertEquals("url", c.getUrl()); + c.setT(new String[]{"foo", "bar"}) + .setZ(false).setD(1234); + assertFalse(c.getZ()); + assertEquals("foo", c.getT()[0]); + assertEquals("bar", c.getT()[1]); + assertEquals(1234l, c.getD()); + + } + + interface XmlExample extends XmlBuilder { + String getA(); + Boolean getB(); + @Name("c") + int getNumber(); + + XmlExample[] getX(); + @Name("x") + XmlExample getFirstX(); + + XmlExample setA(String s); + @Name("c") + XmlExample setNumber(int i); + } + + public void testXmlBuilder() { + String xml = " text"; + XmlExample x = GWT.create(XmlExample.class); + x.parse(xml); + assertTrue(x.getB()); + assertEquals("ra", x.getA()); + assertEquals(-1, x.getNumber()); + assertEquals("xa2", x.getX()[1].getA()); + assertEquals("xa1", x.getFirstX().getA()); + x.setA("X").setNumber(1234); + assertEquals("X", x.getA()); + assertEquals(1234, x.getNumber()); + } +} 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/GQueryCoreTest.java deleted file mode 100644 index 0149df5a..00000000 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ /dev/null @@ -1,1820 +0,0 @@ -/* - * Copyright 2011, The gwtquery team. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.query.client; - -import static com.google.gwt.query.client.GQuery.$; -import static com.google.gwt.query.client.GQuery.$$; -import static com.google.gwt.query.client.GQuery.document; - -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.InputElement; -import com.google.gwt.dom.client.Node; -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.junit.client.GWTTestCase; -import com.google.gwt.query.client.css.CSS; -import com.google.gwt.query.client.css.RGBColor; -import com.google.gwt.query.client.impl.SelectorEngineCssToXPath; -import com.google.gwt.query.client.impl.SelectorEngineImpl; -import com.google.gwt.query.client.impl.SelectorEngineSizzle; -import com.google.gwt.query.client.js.JsNamedArray; -import com.google.gwt.query.client.js.JsNodeArray; -import com.google.gwt.query.client.js.JsUtils; -import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.TextArea; -import com.google.gwt.user.client.ui.Widget; - -import junit.framework.Assert; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Test class for testing gwtquery-core api. - */ -public class GQueryCoreTest extends GWTTestCase { - - static Element e = null; - - static HTML testPanel = null; - - protected static void assertHtmlEquals(Object expected, Object actual) { - assertEquals(iExplorerFixHtml(expected), iExplorerFixHtml(actual)); - } - - protected static String iExplorerFixHtml(Object s) { - // IE shows all tags upper-case - // IE adds \r \n - // IE does not put quotes to some attributes - // Investigate: IE in method find puts the attribute $h="4" - // Investigate: IE in method filter adds the attrib added="null" - return s.toString().trim().toLowerCase().replaceAll("[\r\n]", "").replaceAll( - " ([\\w]+)=[\"']([^\"']+)[\"']", " $1=$2").replaceAll( - "\\s+\\$h=\"[^\"]+\"", "").replaceAll(" added=[^ >]+", ""); - } - - int done = 0; - - public String getModuleName() { - return "com.google.gwt.query.Query"; - } - - public void gwtSetUp() { - if (e == null || DOM.getElementById("core-tst") == null) { - testPanel = new HTML(); - RootPanel.get().add(testPanel); - e = testPanel.getElement(); - e.setId("core-tst"); - } else { - e.setInnerHTML(""); - } - } - - public void testAttributeMethods() { - - $(e).html("

Content

"); - GQuery gq = $("p", e); - - // attr() - gq.attr($$("attr1: 'a', attr2: 'b'")); - assertEquals("a", gq.attr("attr1")); - assertEquals("b", gq.attr("attr2")); - - gq.attr("attr3", new Function() { - public String f(Element e, int i) { - return e.getInnerText(); - } - }); - assertEquals("Content", gq.attr("attr3")); - - assertEquals("a1", gq.attr("class")); - gq.attr("class", "b1 b2"); - - // hasClass() - assertTrue(gq.hasClass("b1")); - assertTrue(gq.hasClass("b2")); - - // addClass() - gq.addClass("c1", "c2"); - assertTrue(gq.hasClass("b1")); - assertTrue(gq.hasClass("b2")); - assertTrue(gq.hasClass("c1")); - assertTrue(gq.hasClass("c2")); - - // removeClass() - gq.removeClass("c2", "c1"); - assertTrue(gq.hasClass("b1")); - assertTrue(gq.hasClass("b2")); - assertFalse(gq.hasClass("c1")); - assertFalse(gq.hasClass("c2")); - - // toggleClass() - gq.toggleClass("b2"); - assertTrue(gq.hasClass("b1")); - assertFalse(gq.hasClass("b2")); - gq.toggleClass("b2"); - assertTrue(gq.hasClass("b1")); - assertTrue(gq.hasClass("b2")); - gq.toggleClass("b2", true); - assertTrue(gq.hasClass("b2")); - gq.toggleClass("b2", false); - assertFalse(gq.hasClass("b2")); - - // css() - String content = "

Test Paragraph.

"; - $(e).html(content); - assertEquals("red", $("p", e).css("color")); - $("p", e).css("font-weight", "bold"); - assertEquals("bold", $("p", e).css("font-weight")); - - // css() properties - $(e).html("

Test Paragraph.

"); - $("p", e).css( - Properties.create("color: 'red', 'font-weight': 'bold', background: 'blue'")); - assertEquals("red", $("p", e).css("color")); - assertEquals("bold", $("p", e).css("font-weight")); - assertEquals("blue", $("p", e).css("background-color", false)); - - // css() camelize and uppercase - $(e).html("

Test Paragraph.

"); - $("p", e).css(Properties.create("COLOR: 'red', 'FONT-WEIGHT': 'bold'")); - assertEquals("red", $("p", e).css("color", false)); - assertEquals("", $("p", e).css("background")); - } - - public void testCapitalLetters() { - $(e).html("
Content
"); - assertEquals(1, $("#testImageDisplay").size()); - // Commented because IE is case insensitive - // assertEquals(0, $("#testimagedisplay").size()); - assertEquals(1, $(".whatEver").size()); - assertEquals(0, $(".whatever").size()); - } - - public void testCleanMethod() { - $(e).html("").append($("")); - assertHtmlEquals("", $(e).html()); - - $(e).html("").append($("")); - assertHtmlEquals("", $(e).html()); - - $(e).html("").append($("")); - assertHtmlEquals("", $(e).html()); - } - - public void testDomManip() { - String content = "branchA target" - + "branchB target"; - - $(e).html(""); - $(e).append(content); - assertEquals(4, $("span", e).size()); - assertEquals(2, $("span.target", e).size()); - assertHtmlEquals(content, $(e).html()); - - $(e).html("ab"); - $("span").append("
c
"); - assertHtmlEquals("a
c
b
c
", $( - e).html()); - } - - public void testEach() { - $(e).html("

Content 1

Content 2

Content 3

"); - $("p", e).each(new Function() { - public void f(Element e) { - $(e).text("."); - } - }); - assertHtmlEquals("

.

.

.

", $("p", e)); - $("p", e).each(new Function() { - public String f(Element e, int i) { - $(e).text("" + i); - return ""; - } - }); - assertHtmlEquals("

0

1

2

", $("p", e)); - } - - public void testIFrameManipulation() { - $(e).html("