From 464f849ed1a41645ea8db6084ffdb8948ccba1c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Carrasco=20Mo=C3=B1ino?= Date: Sun, 17 Mar 2013 15:35:12 +0100 Subject: [PATCH] Test nested promises --- .../query/client/GQueryDeferredTestGwt.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) 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(); + } + }); + } } -- 2.39.5