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

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: preempt stevenjb comments :) 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..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.
+};

Powered by Google App Engine
This is Rietveld 408576698