Chromium Code Reviews| 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..aa7eb39b533326c25300038f6d8c3b1a91cae304 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 = asyncResult; |
|
rgustafson
2014/02/14 02:12:07
asyncFailureResult?
robliao
2014/02/14 02:28:25
Done.
|
| + 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; |
| + } |
| + |
| + return {then: then, catch: catchFunc, isPromise: true}; |
| } |
| function all(arrayOfPromises) { |