From: Manuel Carrasco MoƱino Date: Sun, 17 Mar 2013 14:35:12 +0000 (+0100) Subject: Test nested promises X-Git-Tag: release-1.4.0~59^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=464f849ed1a41645ea8db6084ffdb8948ccba1c1;p=gwtquery.git Test nested promises --- diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java index d685c1ca..dcd6e20b 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java @@ -210,5 +210,52 @@ public class GQueryDeferredTestGwt extends GWTTestCase { } }); } + + public void testNestedPromiseFunction() { + progress = 0; + delayTestFinish(3000); + + Promise doingFoo = new PromiseFunction() { + public void f(final Deferred dfd) { + new Timer() { + int count = 0; + public void run() { + dfd.notify(count ++); + if (count > 3) { + cancel(); + dfd.resolve("done"); + } + } + }.scheduleRepeating(50); + } + }; + + Promise doingBar = new PromiseFunction() { + public void f(final Deferred dfd) { + new Timer() { + int count = 0; + public void run() { + dfd.notify(count ++); + if (count > 3) { + cancel(); + dfd.resolve("done"); + } + } + }.scheduleRepeating(50); + } + }; + + GQuery.when(doingFoo, doingBar).progress(new Function() { + public void f() { + int c = getArgument(0); + progress += c; + } + }).done(new Function() { + public void f() { + assertEquals(12, progress); + finishTest(); + } + }); + } }