cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / testing / callback_helper.js
blob6f14d2f9c43418cb7a8f069557b56ace9b8683a0
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.
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;
17 CallbackHelper.prototype = {
18 /**
19 * @param {Function=} opt_callback
20 * @return {Function}
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;
32 callback.apply(this.fixture_, arguments);
33 if (--this.pendingCallbacks_ <= 0)
34 CallbackHelper.testDone_();
35 }.bind(this));
36 // runAllActionsAsync catches exceptions and puts them in the test
37 // framework's list of errors and fails the test if appropriate.
38 var runAll = runAllActionsAsync(WhenTestDone.ASSERT, completionAction);
39 ++this.pendingCallbacks_;
40 return function() {
41 savedArgs.arguments = Array.prototype.slice.call(arguments);
42 runAll.invoke();
47 /**
48 * @private
50 CallbackHelper.testDone_ = this.testDone;
51 // Remove testDone for public use since direclty using it conflicts with
52 // this callback helper.
53 delete this.testDone;