| 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 /* eslint-disable no-console */ | 5 /* eslint-disable no-console */ |
| 6 | 6 |
| 7 /** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */ | 7 /** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */ |
| 8 self.testRunner; | 8 self.testRunner; |
| 9 | 9 |
| 10 TestRunner.executeTestScript = function() { | 10 TestRunner.executeTestScript = function() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (!(testPromise instanceof Promise)) | 84 if (!(testPromise instanceof Promise)) |
| 85 testPromise = Promise.resolve(); | 85 testPromise = Promise.resolve(); |
| 86 testPromise.then(nextTest); | 86 testPromise.then(nextTest); |
| 87 } | 87 } |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * @param {!Object} receiver | 91 * @param {!Object} receiver |
| 92 * @param {string} methodName | 92 * @param {string} methodName |
| 93 * @param {!Function} override | 93 * @param {!Function} override |
| 94 * @param {boolean} opt_sticky | 94 * @param {boolean=} opt_sticky |
| 95 */ | 95 */ |
| 96 TestRunner.addSniffer = function(receiver, methodName, override, opt_sticky) { | 96 TestRunner.addSniffer = function(receiver, methodName, override, opt_sticky) { |
| 97 override = TestRunner.safeWrap(override); | 97 override = TestRunner.safeWrap(override); |
| 98 | 98 |
| 99 var original = receiver[methodName]; | 99 var original = receiver[methodName]; |
| 100 if (typeof original !== 'function') | 100 if (typeof original !== 'function') |
| 101 throw new Error('Cannot find method to override: ' + methodName); | 101 throw new Error('Cannot find method to override: ' + methodName); |
| 102 | 102 |
| 103 receiver[methodName] = function(var_args) { | 103 receiver[methodName] = function(var_args) { |
| 104 try { | 104 try { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 bubbles: true, | 180 bubbles: true, |
| 181 cancelable: true, | 181 cancelable: true, |
| 182 ctrlKey: !!ctrlKey, | 182 ctrlKey: !!ctrlKey, |
| 183 altKey: !!altKey, | 183 altKey: !!altKey, |
| 184 shiftKey: !!shiftKey, | 184 shiftKey: !!shiftKey, |
| 185 metaKey: !!metaKey | 185 metaKey: !!metaKey |
| 186 }); | 186 }); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 /** | 189 /** |
| 190 * @param {!Function} func | 190 * @param {!Function=} func |
| 191 * @param {!Function=} onexception | 191 * @param {!Function=} onexception |
| 192 * @return {!Function} | 192 * @return {!Function} |
| 193 */ | 193 */ |
| 194 TestRunner.safeWrap = function(func, onexception) { | 194 TestRunner.safeWrap = function(func, onexception) { |
| 195 /** | 195 /** |
| 196 * @this {*} | 196 * @this {*} |
| 197 */ | 197 */ |
| 198 function result() { | 198 function result() { |
| 199 if (!func) | 199 if (!func) |
| 200 return; | 200 return; |
| 201 var wrapThis = this; | 201 var wrapThis = this; |
| 202 try { | 202 try { |
| 203 return func.apply(wrapThis, arguments); | 203 return func.apply(wrapThis, arguments); |
| 204 } catch (e) { | 204 } catch (e) { |
| 205 TestRunner.addResult('Exception while running: ' + func + '\n' + (e.stack
|| e)); | 205 TestRunner.addResult('Exception while running: ' + func + '\n' + (e.stack
|| e)); |
| 206 if (onexception) | 206 if (onexception) |
| 207 TestRunner.safeWrap(onexception)(); | 207 TestRunner.safeWrap(onexception)(); |
| 208 else | 208 else |
| 209 TestRunner.completeTest(); | 209 TestRunner.completeTest(); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 return result; | 212 return result; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 /** | 215 /** |
| 216 * @param {!Element} node |
| 217 * @return {string} |
| 218 */ |
| 219 TestRunner.textContentWithLineBreaks = function(node) { |
| 220 function padding(currentNode) { |
| 221 var result = 0; |
| 222 while (currentNode && currentNode !== node) { |
| 223 if (currentNode.nodeName === 'OL' && |
| 224 !(currentNode.classList && currentNode.classList.contains('object-prop
erties-section'))) |
| 225 ++result; |
| 226 currentNode = currentNode.parentNode; |
| 227 } |
| 228 return Array(result * 4 + 1).join(' '); |
| 229 } |
| 230 |
| 231 var buffer = ''; |
| 232 var currentNode = node; |
| 233 var ignoreFirst = false; |
| 234 while (currentNode.traverseNextNode(node)) { |
| 235 currentNode = currentNode.traverseNextNode(node); |
| 236 if (currentNode.nodeType === Node.TEXT_NODE) { |
| 237 buffer += currentNode.nodeValue; |
| 238 } else if (currentNode.nodeName === 'LI' || currentNode.nodeName === 'TR') { |
| 239 if (!ignoreFirst) |
| 240 buffer += '\n' + padding(currentNode); |
| 241 else |
| 242 ignoreFirst = false; |
| 243 } else if (currentNode.nodeName === 'STYLE') { |
| 244 currentNode = currentNode.traverseNextNode(node); |
| 245 continue; |
| 246 } else if (currentNode.classList && currentNode.classList.contains('object-p
roperties-section')) { |
| 247 ignoreFirst = true; |
| 248 } |
| 249 } |
| 250 return buffer; |
| 251 }; |
| 252 |
| 253 /** |
| 216 * @param {!Function} testFunction | 254 * @param {!Function} testFunction |
| 217 * @return {!Function} | 255 * @return {!Function} |
| 218 */ | 256 */ |
| 219 function debugTest(testFunction) { | 257 function debugTest(testFunction) { |
| 220 self.test = testFunction; | 258 self.test = testFunction; |
| 221 TestRunner.addResult = console.log; | 259 TestRunner.addResult = console.log; |
| 222 TestRunner.completeTest = () => console.log('Test completed'); | 260 TestRunner.completeTest = () => console.log('Test completed'); |
| 223 return () => {}; | 261 return () => {}; |
| 224 } | 262 } |
| 225 | 263 |
| 226 (function() { | 264 (function() { |
| 227 /** | 265 /** |
| 228 * @param {string|!Event} message | 266 * @param {string|!Event} message |
| 229 * @param {string} source | 267 * @param {string} source |
| 230 * @param {number} lineno | 268 * @param {number} lineno |
| 231 * @param {number} colno | 269 * @param {number} colno |
| 232 * @param {!Error} error | 270 * @param {!Error} error |
| 233 */ | 271 */ |
| 234 function completeTestOnError(message, source, lineno, colno, error) { | 272 function completeTestOnError(message, source, lineno, colno, error) { |
| 235 TestRunner.addResult('TEST ENDED IN ERROR: ' + error.stack); | 273 TestRunner.addResult('TEST ENDED IN ERROR: ' + error.stack); |
| 236 TestRunner.completeTest(); | 274 TestRunner.completeTest(); |
| 237 } | 275 } |
| 238 | 276 |
| 239 self['onerror'] = completeTestOnError; | 277 self['onerror'] = completeTestOnError; |
| 240 })(); | 278 })(); |
| OLD | NEW |