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

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: Merging in https://codereview.chromium.org/174053003/ 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..44d21e6d1f640ea07406a7919738959bcbb09706 100644
--- a/chrome/browser/resources/google_now/common_test_util.js
+++ b/chrome/browser/resources/google_now/common_test_util.js
@@ -82,16 +82,35 @@ 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 = asyncFailureResult;
+ resolved = false;
+ });
function then(callback) {
- callback.call(null, result);
+ if (resolved) {
+ callback.call(null, result);
+ }
+ return this;
+ }
+
+ // 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;
}
- return {then: then, isPromise: true};
+
+ return {then: then, catch: catchFunc, isPromise: true};
}
function all(arrayOfPromises) {
« no previous file with comments | « chrome/browser/resources/google_now/background_unittest.gtestjs ('k') | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698