diff options
author | Manolo Carrasco <manolo@apache.org> | 2010-05-30 07:38:05 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2010-05-30 07:38:05 +0000 |
commit | 47cb10658ebdb1d65059dd82408210c05aa2a281 (patch) | |
tree | ff62f6a09601a1d06fdf83f2878e769db7727806 /gwtquery-core | |
parent | b89f4d3fa117bac99aa074d0fdb83b1fa06a72ef (diff) | |
download | gwtquery-47cb10658ebdb1d65059dd82408210c05aa2a281.tar.gz gwtquery-47cb10658ebdb1d65059dd82408210c05aa2a281.zip |
added new test to check the effects queue
Diffstat (limited to 'gwtquery-core')
3 files changed, 83 insertions, 12 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 8b01fa20..91dd9a84 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -62,6 +62,14 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { this.left = left;
this.top = top;
}
+
+ public Offset add(int left, int top) {
+ return new Offset(this.left + left, this.top + top);
+ }
+
+ public String toString() {
+ return top + "+" + left;
+ }
}
protected static final class DataCache extends JavaScriptObject {
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java index f1d8dcd0..13d75c7d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java @@ -86,9 +86,9 @@ public abstract class GQueryQueue extends GQuery { * Adds a new function, to be executed, onto the end of the queue of all * matched elements. */ - public GQueryQueue queue(String type, Function data) { + public GQueryQueue queue(String type, Function func) { for (Element e : elements()) { - queue(e, type, data); + queue(e, type, func); } return this; } @@ -96,9 +96,9 @@ public abstract class GQueryQueue extends GQuery { /** * Replaces the current queue with the given queue on all matched elements. */ - public GQueryQueue queue(String type, Queue<?> data) { + public GQueryQueue queue(String type, Queue<?> queue) { for (Element e : elements()) { - replacequeue(e, type, data); + replacequeue(e, type, queue); } return this; } @@ -119,19 +119,19 @@ public abstract class GQueryQueue extends GQuery { } @SuppressWarnings("unchecked") - private Queue<Function> queue(Element elem, String type, Function data) { + private Queue<Function> queue(Element elem, String type, Function func) { if (elem != null) { type = type + "queue"; Queue<Function> q = (Queue<Function>) data(elem, type, null); if (q == null) { q = (Queue<Function>) data(elem, type, Queue.newInstance()); } - if (data != null) { - q.enqueue(data); + if (func != null) { + q.enqueue(func); } if (SelectorEngine.eq(type, "__FXqueue") && q.length() == 1) { - if (data != null) { - data.f(elem); + if (func != null) { + func.f(elem); } } return q; @@ -139,10 +139,10 @@ public abstract class GQueryQueue extends GQuery { return null; } - private void replacequeue(Element elem, String type, Queue<?> data) { + private void replacequeue(Element elem, String type, Queue<?> queue) { if (elem != null) { type = type + "queue"; - data(elem, type, data); + data(elem, type, queue); } } } 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/GQueryEffectsTest.java index 8e0a581f..05e1cca8 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/GQueryEffectsTest.java @@ -15,10 +15,14 @@ */ package com.google.gwt.query.client; +import static com.google.gwt.query.client.Effects.Effects; +import static com.google.gwt.query.client.Effects.Easing.LINEAR; import static com.google.gwt.query.client.GQuery.$; +import static com.google.gwt.query.client.GQuery.$$; import com.google.gwt.dom.client.Element; import com.google.gwt.junit.client.GWTTestCase; +import com.google.gwt.query.client.GQuery.Offset; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; @@ -47,7 +51,7 @@ public class GQueryEffectsTest extends GWTTestCase { } } - public void testEffectsPlugin() { + public void testEffects() { $(e).html( "<p id='id1'>Content 1</p><p id='id2'>Content 2</p><p id='id3'>Content 3</p>"); @@ -110,5 +114,64 @@ public class GQueryEffectsTest extends GWTTestCase { timerMidTime.schedule(1200); timerLongTime.schedule(2200); } + + + void assertPosition(GQuery g, Offset min, Offset max) { + int a = Math.min(min.top, max.top); + int b = Math.max(min.top, max.top); + boolean c = a <= g.position().top && g.position().top <= b; + String msg = "Top has the value " + g.position().top + ", but should be in the range: " + a + " - " + b; + assertTrue(msg, c); + + a = Math.min(min.left, max.left); + b = Math.max(min.left, max.left); + c = a <= g.position().left && g.position().left <= b; + msg = "Left has the value " + g.position().left + ", but should be in the range: " + a + " - " + b; + assertTrue(msg, c); + } + + + public void testEffectsShouldBeQueued() { + $(e).html( + "<p id='id1'>Content 1</p><p id='id2'>Content 2</p><p id='id3'>Content 3</p>"); + + final GQuery g = $("#id1").css("position", "relative"); + final Offset o = g.position(); + g.as(Effects). + animate($$("left: '+=100'"), 400, LINEAR, null). + animate($$("top: '+=100'"), 400, LINEAR, null). + animate($$("left: '-=100'"), 400, LINEAR, null). + animate($$("top: '-=100'"), 400, LINEAR, null); + + delayTestFinish(2500); + + final Timer timer1 = new Timer() { + public void run() { + assertPosition(g, o.add(99, 0), o.add(1,0)); + finishTest(); + } + }; + final Timer timer2 = new Timer() { + public void run() { + assertPosition(g, o.add(100, 99), o.add(100, 1)); + timer1.schedule(400); + } + }; + final Timer timer3 = new Timer() { + public void run() { + assertPosition(g, o.add(1, 100), o.add(99, 100)); + timer2.schedule(400); + } + }; + final Timer timer4 = new Timer() { + public void run() { + assertPosition(g, o.add(0, 1), o.add(0, 99)); + timer3.schedule(400); + } + }; + + timer4.schedule(200); + } + } |