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..94ad963285a64ecd74f87f44d86b6fb3ccbc2ae5 100644 |
--- a/chrome/test/data/webui/polymer_browser_test_base.js |
+++ b/chrome/test/data/webui/polymer_browser_test_base.js |
@@ -95,3 +95,25 @@ 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. |
+ */ |
+PolymerTest.async = function(fn) { |
+ PolymerTest.lastPromise_ = PolymerTest.lastPromise_.then(function() { |
+ return new Promise(function(resolve) { |
+ setTimeout(fn); |
+ setTimeout(resolve); |
+ }); |
+ }); |
+ return PolymerTest.lastPromise_; |
+}; |
+ |
+/** @type {Promise} */ |
Dan Beam
2015/09/14 23:31:48
nit: @type -> @private
michaelpg
2015/09/15 01:17:57
Done.
|
+PolymerTest.lastPromise_ = Promise.resolve(); |