From fd879510528580969e3645ee3f83a545c7ccb4e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Fri, 1 Nov 2013 13:26:54 +0100 Subject: [PATCH] Fix an effects test which was randomly failing --- .../query/client/GQueryEffectsTestGwt.java | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java index b71b2300..2dcefa3a 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTestGwt.java @@ -15,13 +15,13 @@ */ 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.*; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.RepeatingCommand; 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.query.client.plugins.Effects; +import com.google.gwt.query.client.plugins.effects.Bezier.EasingCurve; import com.google.gwt.query.client.plugins.effects.Fx.ColorFx; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; @@ -71,38 +71,43 @@ public class GQueryEffectsTestGwt extends GWTTestCase { GQuery back = $("div", e); assertEquals(0, back.size()); - g.as(Effects.Effects).clipDisappear(duration); - - // Check that the back div has been created - back = $("div", e); - assertEquals(1, back.size()); - // Configure the max duration for this test - delayTestFinish(duration * 2); + delayTestFinish(duration * 3); // each timer calls the next one - //final Timer timer1 = new Timer() { - //public void run() { + final Timer endTimer = new Timer() { + public void run() { // Check that the back div has been removed - //GQuery back = $("div", e); - //assertEquals(0, back.size()); + GQuery back = $("div", e); + assertEquals(0, back.size()); // Check that the attribute clip has been removed - //assertEquals("", g.css("clip")); - //finishTest(); - //} - //}; - final Timer timer2 = new Timer() { - public void run() { - // Check that the attribute clip has been set - String re = "rect\\(\\d+px[, ]+\\d+px[, ]+\\d+px[, ]+\\d+px\\)"; - assertTrue(g.css("clip") + " does not match " + re, g.css("clip").matches(re)); + assertTrue(g.css("clip").matches("(|auto)")); finishTest(); - //timer1.schedule(duration/2 + 1); } }; + + Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() { + int c = 0; + // Run until we detect the rect has been changed or timeout + public boolean execute() { + String re = "rect\\(\\d+px[, ]+\\d+px[, ]+\\d+px[, ]+\\d+px\\)"; + if (g.css("clip").matches(re)) { + endTimer.schedule(duration); + return false; + } + if (duration < (c += 10)) { + fail(g.css("clip") + " does not matched " + re); + return false; + } + return true; + } + }, 100); + + g.as(Effects).clipDisappear(duration); - // Start the first timer - timer2.schedule(duration/2); + // Check that the back div has been created + back = $("div", e); + assertEquals(1, back.size()); } public void testEffectsShouldBeQueued() { @@ -112,7 +117,7 @@ public class GQueryEffectsTestGwt extends GWTTestCase { final Offset o = g.offset(); final int duration = 1000; - g.as(Effects.Effects). + g.as(Effects). animate($$("left: '+=100'"), duration, Easing.LINEAR). animate($$("top: '+=100'"), duration, Easing.LINEAR). animate($$("left: '-=100'"), duration, Easing.LINEAR). @@ -241,7 +246,7 @@ public class GQueryEffectsTestGwt extends GWTTestCase { .toString()); prop1 = GQuery.$$("marginTop: '-110px', marginLeft: '-110px', top: '50%', left: '50%', width: '174px', height: '174px', padding: '20px'"); - PropertiesAnimation an = new PropertiesAnimation(Easing.SWING, g.get(0), prop1); + PropertiesAnimation an = new PropertiesAnimation(EasingCurve.SWING, g.get(0), prop1); an.onStart(); an.onComplete(); @@ -352,7 +357,7 @@ public class GQueryEffectsTestGwt extends GWTTestCase { delayTestFinish(duration * 3); - g.as(Effects.Effects). + g.as(Effects). animate($$("$width: +=100; $border: +=4"), duration, Easing.LINEAR); final Timer timer = new Timer() { -- 2.39.5