Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9376)

Unified Diff: chrome/test/data/webui/polymer_browser_test_base.js

Issue 1310843010: Add Polymer tests for cr-settings-prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new changes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();

Powered by Google App Engine
This is Rietveld 408576698