| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Common testing utilities. | 5 // Common testing utilities. |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Shortcut for document.getElementById. | 8 * Shortcut for document.getElementById. |
| 9 * @param {string} id of the element. | 9 * @param {string} id of the element. |
| 10 * @return {HTMLElement} with the id. | 10 * @return {HTMLElement} with the id. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TestUtils.extractHtmlFromCommentEncodedString = | 35 TestUtils.extractHtmlFromCommentEncodedString = |
| 36 function(commentEncodedHtml, opt_args) { | 36 function(commentEncodedHtml, opt_args) { |
| 37 var stringified = commentEncodedHtml.toString(); | 37 var stringified = commentEncodedHtml.toString(); |
| 38 if (opt_args) { | 38 if (opt_args) { |
| 39 for (var i = 0; i < opt_args.length; i++) | 39 for (var i = 0; i < opt_args.length; i++) |
| 40 stringified = stringified.replace('$' + i, opt_args[i]); | 40 stringified = stringified.replace('$' + i, opt_args[i]); |
| 41 } | 41 } |
| 42 return stringified.replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, ''); | 42 return stringified.replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, ''); |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 |
| 46 /** |
| 47 * Creates a data url for a document. |
| 48 * @param {function() : void} doc Snippet wrapped inside of a function. |
| 49 * @return {string} |
| 50 */ |
| 51 TestUtils.createUrlForDoc = function(doc) { |
| 52 var docString = TestUtils.extractHtmlFromCommentEncodedString(doc); |
| 53 return TestUtils.collapseWhitespace('data:text/html,<!doctype html>' + |
| 54 docString.replace(/[\n\r]/g, '') |
| 55 .trim()); |
| 56 }; |
| 57 |
| 58 /** |
| 59 * Collapses inner whitespace. |
| 60 * @param {string} str |
| 61 * @return {string} |
| 62 */ |
| 63 TestUtils.collapseWhitespace = function(str) { |
| 64 return str.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, ''); |
| 65 }; |
| 66 |
| 45 /** | 67 /** |
| 46 * Similar to |TEST_F|. Generates a test for the given |testFixture|, | 68 * Similar to |TEST_F|. Generates a test for the given |testFixture|, |
| 47 * |testName|, and |testFunction|. | 69 * |testName|, and |testFunction|. |
| 48 * Used this variant when an |isAsync| fixture wants to temporarily mix in an | 70 * Used this variant when an |isAsync| fixture wants to temporarily mix in an |
| 49 * sync test. | 71 * sync test. |
| 50 * @param {string} testFixture Fixture name. | 72 * @param {string} testFixture Fixture name. |
| 51 * @param {string} testName Test name. | 73 * @param {string} testName Test name. |
| 52 * @param {function} testFunction The test impl. | 74 * @param {function} testFunction The test impl. |
| 53 */ | 75 */ |
| 54 function SYNC_TEST_F(testFixture, testName, testFunction) { | 76 function SYNC_TEST_F(testFixture, testName, testFunction) { |
| 55 TEST_F(testFixture, testName, function() { | 77 TEST_F(testFixture, testName, function() { |
| 56 this.newCallback(testFunction)(); | 78 this.newCallback(testFunction)(); |
| 57 }); | 79 }); |
| 58 } | 80 } |
| OLD | NEW |