]> source.dussan.org Git - gwtquery.git/commitdiff
Test nested promises
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Sun, 17 Mar 2013 14:35:12 +0000 (15:35 +0100)
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>
Sun, 17 Mar 2013 14:35:12 +0000 (15:35 +0100)
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryDeferredTestGwt.java

index d685c1ca940b7528629032ac940393e258fc4484..dcd6e20b2c196364d46ac7f6b78a78e69d567e2b 100644 (file)
@@ -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();
+          }
+        });
+      }
 
 }