Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** @type {!{notifyDone: function()}|undefined} */ | 5 /** @type {!{notifyDone: function()}|undefined} */ |
| 6 self.testRunner; | 6 self.testRunner; |
| 7 | 7 |
| 8 TestRunner.executeTestScript = function() { | 8 TestRunner.executeTestScript = function() { |
| 9 fetch(`${Runtime.queryParam('test')}`) | 9 fetch(`${Runtime.queryParam('test')}`) |
| 10 .then((data) => data.text()) | 10 .then((data) => data.text()) |
| 11 .then((testScript) => eval(`(function(){${testScript}})()`)) | 11 .then((testScript) => eval(`(function(){${testScript}})()`)) |
| 12 .catch((error) => { | 12 .catch((error) => { |
| 13 TestRunner.addResult(`Unable to execute test script because of error: ${ error}`); | 13 TestRunner.addResult(`Unable to execute test script because of error: ${ error}`); |
| 14 TestRunner.completeTest(); | 14 TestRunner.completeTest(); |
| 15 }); | 15 }); |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 /** @type {!Array<string>} */ | 18 /** @type {!Array<string>} */ |
| 19 TestRunner._results = []; | 19 TestRunner._results = []; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * @suppressGlobalPropertiesCheck | 22 * @suppressGlobalPropertiesCheck |
| 23 */ | 23 */ |
| 24 TestRunner.completeTest = function() { | 24 TestRunner.completeTest = function() { |
| 25 if (!self.testRunner) { | 25 if (!self.testRunner) { |
| 26 console.log('Test Done'); | 26 console.log('Test Done'); // eslint-disable-line no-console |
|
chenwilliam
2016/12/08 20:00:23
Since it's a test harness, I think it's OK if we d
einbinder
2016/12/09 01:16:05
Done.
| |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 | 29 |
| 30 Array.prototype.forEach.call(document.documentElement.childNodes, x => x.remov e()); | 30 Array.prototype.forEach.call(document.documentElement.childNodes, x => x.remov e()); |
| 31 var outputElement = document.createElement('div'); | 31 var outputElement = document.createElement('div'); |
| 32 // Support for svg - add to document, not body, check for style. | 32 // Support for svg - add to document, not body, check for style. |
| 33 if (outputElement.style) { | 33 if (outputElement.style) { |
| 34 outputElement.style.whiteSpace = 'pre'; | 34 outputElement.style.whiteSpace = 'pre'; |
| 35 outputElement.style.height = '10px'; | 35 outputElement.style.height = '10px'; |
| 36 outputElement.style.overflow = 'hidden'; | 36 outputElement.style.overflow = 'hidden'; |
| 37 } | 37 } |
| 38 document.documentElement.appendChild(outputElement); | 38 document.documentElement.appendChild(outputElement); |
| 39 for (var i = 0; i < TestRunner._results.length; i++) { | 39 for (var i = 0; i < TestRunner._results.length; i++) { |
| 40 outputElement.appendChild(document.createTextNode(TestRunner._results[i])); | 40 outputElement.appendChild(document.createTextNode(TestRunner._results[i])); |
| 41 outputElement.appendChild(document.createElement('br')); | 41 outputElement.appendChild(document.createElement('br')); |
| 42 } | 42 } |
| 43 TestRunner._results = []; | 43 TestRunner._results = []; |
| 44 self.testRunner.notifyDone(); | 44 self.testRunner.notifyDone(); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @param {*} text | 48 * @param {*} text |
| 49 */ | 49 */ |
| 50 TestRunner.addResult = function(text) { | 50 TestRunner.addResult = function(text) { |
| 51 if (self.testRunner) | 51 if (self.testRunner) |
| 52 TestRunner._results.push(String(text)); | 52 TestRunner._results.push(String(text)); |
| 53 else | 53 else |
| 54 console.log(text); | 54 console.log(text); // eslint-disable-line no-console |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * @param {!Array<function()>} tests | 58 * @param {!Array<function()>} tests |
| 59 */ | 59 */ |
| 60 TestRunner.runTests = function(tests) { | 60 TestRunner.runTests = function(tests) { |
| 61 nextTest(); | 61 nextTest(); |
| 62 | 62 |
| 63 function nextTest() { | 63 function nextTest() { |
| 64 var test = tests.shift(); | 64 var test = tests.shift(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 * @param {number} colno | 142 * @param {number} colno |
| 143 * @param {!Error} error | 143 * @param {!Error} error |
| 144 */ | 144 */ |
| 145 function completeTestOnError(message, source, lineno, colno, error) { | 145 function completeTestOnError(message, source, lineno, colno, error) { |
| 146 TestRunner.addResult('TEST ENDED IN ERROR: ' + error.stack); | 146 TestRunner.addResult('TEST ENDED IN ERROR: ' + error.stack); |
| 147 TestRunner.completeTest(); | 147 TestRunner.completeTest(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 self['onerror'] = completeTestOnError; | 150 self['onerror'] = completeTestOnError; |
| 151 })(); | 151 })(); |
| OLD | NEW |