Index: chrome/test/data/webui/polymer_browser_test_base.js |
diff --git a/chrome/test/data/webui/polymer_browser_test_base.js b/chrome/test/data/webui/polymer_browser_test_base.js |
index b768ef76f555a034a033641b08b6ae2c3845b7de..284d92a11008a53390d5f0712caa68375d7217bf 100644 |
--- a/chrome/test/data/webui/polymer_browser_test_base.js |
+++ b/chrome/test/data/webui/polymer_browser_test_base.js |
@@ -95,3 +95,29 @@ PolymerTest.getLibraries = function(basePath) { |
return basePath + library; |
}); |
}; |
+ |
+/** |
+ * Allows chaining asynchronous function to avoid having to write nested |
+ * Promises or setTimeouts. |
+ * Example: PolymerTest.async(fn1).async(fn2).async(fn3).async(done); |
+ */ |
+PolymerTest.async = function(fn) { |
Dan Beam
2015/09/11 21:49:12
initialize lastPromise_ to Promise.resolve(), remo
michaelpg
2015/09/13 03:01:05
nice!
|
+ if (!PolymerTest.lastPromise_) { |
+ PolymerTest.lastPromise_ = new Promise(function(resolve) { |
+ setTimeout(fn); |
+ setTimeout(resolve); |
+ }); |
+ } else { |
+ PolymerTest.lastPromise_ = PolymerTest.lastPromise_.then(function() { |
+ return new Promise(function(resolve) { |
+ setTimeout(fn); |
+ setTimeout(resolve); |
+ }); |
+ }); |
+ } |
+ // Return a helper function of the same name which adds this function to the |
+ // Promise chain. |
+ return { |
+ async: PolymerTest.async |
+ }; |
Dan Beam
2015/09/11 21:49:12
wat? why not?
return PolymerTest.lastPromise_;
michaelpg
2015/09/13 03:01:05
Done. this was just sugar.
|
+}; |