1 // Copyright 2014 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 // Common testing utilities.
8 * Shortcut for document.getElementById.
9 * @param {string} id of the element.
10 * @return {HTMLElement} with the id.
13 return document
.getElementById(id
);
19 var TestUtils = function() {};
22 * Extracts some inlined html encoded as a comment inside a function,
23 * so you can use it like this:
25 * this.appendDoc(function() {/*!
26 * <p>Html goes here</p>
29 * @param {Function} commentEncodedHtml The html , embedded as a
30 * comment inside an anonymous function - see example, above.
31 * @param {!Array=} opt_args Optional arguments to be substituted in the form
32 * $0, ... within the code block.
33 * @return {string} The html text.
35 TestUtils
.extractHtmlFromCommentEncodedString
=
36 function(commentEncodedHtml
, opt_args
) {
37 var stringified
= commentEncodedHtml
.toString();
39 for (var i
= 0; i
< opt_args
.length
; i
++)
40 stringified
= stringified
.replace('$' + i
, opt_args
[i
]);
42 return stringified
.replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');