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

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

Issue 158003003: Convert Google Now's State Change Gathering Mechanism to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed a spot 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
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 28c4b930a67f8a69480d53e58a520342d65cd8a2..1078a6b701e8ad6aec3ce7a666df3ffdd2fc9083 100644
--- a/chrome/browser/resources/google_now/common_test_util.js
+++ b/chrome/browser/resources/google_now/common_test_util.js
@@ -71,3 +71,45 @@ function getMockHandlerContainer(eventIdentifier) {
return mockEventContainer;
}
+
+/**
+ * MockPromise
+ * The JS test harness expects all calls to complete synchronously.
+ * As a result, we can't use built-in JS promises since they run asynchronously.
+ * Instead of mocking all possible calls to promises, a skeleton
+ * implementation is provided to get the tests to pass.
+ */
+var Promise = function() {
+ function PromisePrototypeObject(asyncTask) {
+ var result;
+ asyncTask(
+ function(asyncResult) {
+ result = [asyncResult];
+ },
+ function() {}); // Errors are unsupported.
+
+ function then(callback) {
+ callback.apply(null, result);
skare_ 2014/02/12 22:39:03 this works, just curious - could use result=asyncR
robliao 2014/02/12 23:57:24 Done. On 2014/02/12 22:39:03, Travis Skare wrote:
+ }
+ return {then: then, isPromise: true};
+ }
+
+ function all(arrayOfPromises) {
+ var results = [];
+ for (i = 0; i < arrayOfPromises.length; i++) {
+ if (arrayOfPromises[i].isPromise) {
+ arrayOfPromises[i].then(function(result) {
+ results[i] = result;
+ });
+ } else {
+ results[i] = arrayOfPromises[i];
+ }
+ }
+ var promise = new PromisePrototypeObject(function(resolve) {
+ resolve(results);
+ });
+ return promise;
+ }
+ PromisePrototypeObject.all = all;
+ return PromisePrototypeObject;
+}();
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698