| 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..5d75d6d3b3eb1da2042d2dc26c7326eeda2df94a 100644
|
| --- a/chrome/test/data/webui/polymer_browser_test_base.js
|
| +++ b/chrome/test/data/webui/polymer_browser_test_base.js
|
| @@ -95,3 +95,28 @@ PolymerTest.getLibraries = function(basePath) {
|
| return basePath + library;
|
| });
|
| };
|
| +
|
| +/**
|
| + * Returns a promise which asynchronously calls |fn| and is also resolved
|
| + * asynchronously. Repeated calls to this function ensure each call waits for
|
| + * the previous promise to resolve, allowing any setTimeouts called by the prior
|
| + * function to be queued beforehand. For example:
|
| + * PolymerTest.async(fn1); PolymerTest.async(fn2).then(success, failure);
|
| + * If fn1 calls setTimeout(asyncFn), fn2 won't be called until after asyncFn is
|
| + * called.
|
| + * @param {function()=} opt_fn
|
| + * @return {Promise}
|
| + */
|
| +PolymerTest.async = function(opt_fn) {
|
| + PolymerTest.lastPromise_ = PolymerTest.lastPromise_.then(function() {
|
| + return new Promise(function(resolve) {
|
| + if (opt_fn)
|
| + setTimeout(opt_fn);
|
| + setTimeout(resolve);
|
| + });
|
| + });
|
| + return PolymerTest.lastPromise_;
|
| +};
|
| +
|
| +/** @private {Promise} */
|
| +PolymerTest.lastPromise_ = Promise.resolve();
|
|
|