summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/webrtc/test_functions.js
blob: 1c102b8b113c16e95debcd313b3b40cb031f015a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * Copyright (c) 2012 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.
 */

// Helper / error handling functions.

/**
 * Prints a debug message.
 */
function debug(txt) {
  console.log(txt);
}

/**
 * Sends a value back to the test without logging it.
 *
 * @param {string} message The message to return.
 */
function silentReturnToTest(message) {
  window.domAutomationController.send(message);
}

/**
 * Sends a value back to the test and logs it.
 *
 * @param {string} message The message to return.
 */
function returnToTest(message) {
  debug('Returning ' + message + ' to test.');
  silentReturnToTest(message);
}


/**
 * Fails the test by generating an exception. If the test automation is calling
 * into us, make sure to fail the test as fast as possible. You must use this
 * function like this:
 *
 * throw failTest('my reason');
 *
 * @return {!Error}
 */
function failTest(reason) {
  var error = new Error(reason);
  returnToTest('Test failed: ' + error.stack);
  return error;
}