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

Unified Diff: chrome/browser/resources/google_now/common_test_util.js

Issue 162273002: Convert Google Now's Authentication Manager to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR Feedback Created 6 years, 10 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/browser/resources/google_now/common_test_util.js
diff --git a/chrome/browser/resources/google_now/common_test_util.js b/chrome/browser/resources/google_now/common_test_util.js
index 754e2578fa2f6bf059a5b2b70fbb7ea8c6ed0bed..425b906331304223a5c788b8dcfd0bd83372a1ac 100644
--- a/chrome/browser/resources/google_now/common_test_util.js
+++ b/chrome/browser/resources/google_now/common_test_util.js
@@ -82,16 +82,38 @@ function getMockHandlerContainer(eventIdentifier) {
var Promise = function() {
function PromisePrototypeObject(asyncTask) {
var result;
+ var resolved = false;
asyncTask(
function(asyncResult) {
result = asyncResult;
+ resolved = true;
},
- function() {}); // Errors are unsupported.
+ function(asyncFailureResult) {
+ result = asyncResult;
+ resolved = false;
+ });
function then(callback) {
- callback.call(null, result);
+ if (resolved) {
+ callback.call(null, result);
+ }
+ return this;
}
- return {then: then, isPromise: true};
+
+ // Promises use the function name "catch" to call back error handlers.
+ // We can't use "catch" since function or variable names cannot use the word
+ // "catch".
+ function catchFunc(callback) {
+ if (!resolved) {
+ callback.call(null, result);
+ }
+ return this;
+ }
+
+ var promiseObj = {then: then, isPromise: true};
+ // Using the name "catch" above during initialization will trigger an error.
+ promiseObj.catch = catchFunc;
+ return promiseObj;
}
function all(arrayOfPromises) {

Powered by Google App Engine
This is Rietveld 408576698