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

Unified Diff: chrome/browser/resources/chromeos/chromevox/testing/callback_helper.js

Issue 938623003: Fix ChromeVox next tests to fail instead of timing out where applicable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify async callback handling in the tests. Created 5 years, 9 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/chromeos/chromevox/testing/callback_helper.js
diff --git a/chrome/browser/resources/chromeos/chromevox/testing/callback_helper.js b/chrome/browser/resources/chromeos/chromevox/testing/callback_helper.js
new file mode 100644
index 0000000000000000000000000000000000000000..fba23c3b4203409aa41b8f2d0938abcd6b0d04ce
--- /dev/null
+++ b/chrome/browser/resources/chromeos/chromevox/testing/callback_helper.js
@@ -0,0 +1,45 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Creates wrappers for callbacks and calls testDone() when all callbacks
+ * have been invoked.
+ * @param {testing.Test} fixture
+ */
+function CallbackHelper(fixture) {
+ /** @type {Object} fixture */
+ this.fixture_ = fixture;
+ /** @type {number} */
+ this.pendingCallbacks_ = 0;
+}
+
+CallbackHelper.prototype = {
+ /**
+ * @param {Function=} opt_callback
+ * @return {Function}
+ */
+ wrap: function(opt_callback) {
+ var callback = opt_callback || function() {};
+ var savedArgs = new SaveMockArguments();
+ var lastCall = null;
+ var completionAction = callFunctionWithSavedArgs(savedArgs, function() {
+ if (lastCall) {
+ throw new Error('Called more than once, first call here: ' + lastCall);
+ } else {
+ lastCall = new Error().stack;
+ }
+ callback.apply(this.fixture_, arguments);
+ if (--this.pendingCallbacks_ <= 0)
+ testDone();
+ }.bind(this));
+ // runAllActionsAsync catches exceptions and puts them in the test
+ // framework's list of errors and fails the test.
+ var runAll = runAllActionsAsync(WhenTestDone.ASSERT, completionAction);
+ ++this.pendingCallbacks_;
+ return function() {
+ savedArgs.arguments = Array.prototype.slice.call(arguments);
+ runAll.invoke();
+ }
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698