Chromium Code Reviews| 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..022c94012e31122db59e9f440b4095da6314f793 100644 |
| --- a/chrome/test/data/webui/polymer_browser_test_base.js |
| +++ b/chrome/test/data/webui/polymer_browser_test_base.js |
| @@ -95,3 +95,27 @@ 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) { |
| + // Wrap the asynchronous call to |fn| in a Promise. |
| + var p = new Promise(function(resolve, reject) { |
| + setTimeout(function() { |
| + fn.call(); |
| + resolve(); |
| + }); |
| + }); |
| + // Return a helper function of the same name which adds this function to the |
| + // Promise chain. |
| + return { |
| + async: function(fn) { |
| + p.then(function() { |
| + return PolymerTest.async(fn); |
|
michaelpg
2015/09/08 06:26:59
this doesn't quite work. what I actually want is s
michaelpg
2015/09/11 20:14:38
Ignore this comment, see new patch.
|
| + }); |
| + }, |
| + }; |
| +}; |