Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / data / webrtc / test_functions.js
blob8ed2a75b8baf631812d54c80cb7466ba71a6f038
1 /**
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
7 /**
8 * The callback to send test messages to. By default we will assume that we
9 * are being run by an automated test case such as a browser test, but this can
10 * be overridden.
11 * @private
13 var gReturnCallback = sendToTest;
15 /**
16 * The callback to send debug messages to. By default we assume console.log.
17 * @private
19 var gDebugCallback = consoleLog_;
21 /**
22 * Replaces the test message callback. Test messages are messages sent by the
23 * returnToTest function.
25 * @param callback A function that takes a single string (the message).
27 function replaceReturnCallback(callback) {
28 gReturnCallback = callback;
31 /**
32 * Replaces the debug message callback. Debug messages are messages sent by the
33 * debug function.
35 * @param callback A function that takes a single string (the message).
37 function replaceDebugCallback(callback) {
38 gDebugCallback = callback;
41 // Helper / error handling functions.
43 /**
44 * Prints a debug message on the webpage itself.
46 function debug(txt) {
47 if (gOurClientName == null)
48 prefix = '';
49 else
50 prefix = gOurClientName + ' says: ';
52 gDebugCallback(prefix + txt);
55 /**
56 * Sends a value back to the test.
58 * @param {string} message The message to return.
60 function returnToTest(message) {
61 gReturnCallback(message);
64 /**
65 * Sends a message to the test case. Requires that this javascript was
66 * loaded by the test. This will make the test proceed if it is blocked in a
67 * ExecuteJavascript call.
69 * @param {string} message The message to send.
71 function sendToTest(message) {
72 debug('Returning ' + message + ' to test.');
73 window.domAutomationController.send(message);
76 /**
77 * Fails the test by generating an exception. If the test automation is calling
78 * into us, make sure to fail the test as fast as possible. You must use this
79 * function like this:
81 * throw failTest('my reason');
83 * @return {!Error}
85 function failTest(reason) {
86 console.error(reason);
87 returnToTest('Test failed: ' + reason);
88 return new Error(reason);
91 /** @private */
92 function consoleLog_(message) {
93 // It is not legal to treat console.log as a first-class object, so wrap it.
94 console.log(message);