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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Creates wrappers for callbacks and calls testDone() when all callbacks
7 * have been invoked.
8 * @param {testing.Test} fixture
9 */
10 function CallbackHelper(fixture) {
11 /** @type {Object} fixture */
12 this.fixture_ = fixture;
13 /** @type {number} */
14 this.pendingCallbacks_ = 0;
15 }
16
17 CallbackHelper.prototype = {
18 /**
19 * @param {Function=} opt_callback
20 * @return {Function}
21 */
22 wrap: function(opt_callback) {
23 var callback = opt_callback || function() {};
24 var savedArgs = new SaveMockArguments();
25 var lastCall = null;
26 var completionAction = callFunctionWithSavedArgs(savedArgs, function() {
27 if (lastCall) {
28 throw new Error('Called more than once, first call here: ' + lastCall);
29 } else {
30 lastCall = new Error().stack;
31 }
32 callback.apply(this.fixture_, arguments);
33 if (--this.pendingCallbacks_ <= 0)
34 testDone();
35 }.bind(this));
36 // runAllActionsAsync catches exceptions and puts them in the test
37 // framework's list of errors and fails the test.
38 var runAll = runAllActionsAsync(WhenTestDone.ASSERT, completionAction);
39 ++this.pendingCallbacks_;
40 return function() {
41 savedArgs.arguments = Array.prototype.slice.call(arguments);
42 runAll.invoke();
43 }
44 }
45 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698