Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js b/third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js |
| index 66e955615cee2c999558b822529e5239994f1a9d..e23e6b3a909367826f1e7d7c9035277d998c6cbb 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js |
| @@ -4,7 +4,7 @@ |
| /* eslint-disable no-console */ |
| -/** @type {!{notifyDone: function()}|undefined} */ |
| +/** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */ |
| self.testRunner; |
| TestRunner.executeTestScript = function() { |
| @@ -58,6 +58,16 @@ TestRunner.addResult = function(text) { |
| }; |
| /** |
| + * @param {!Array<string>} textArray |
| + */ |
| +TestRunner.addResults = function(textArray) { |
| + if (!textArray) |
| + return; |
| + for (var i = 0, size = textArray.length; i < size; ++i) |
| + TestRunner.addResult(textArray[i]); |
| +}; |
| + |
| +/** |
| * @param {!Array<function()>} tests |
| */ |
| TestRunner.runTests = function(tests) { |
| @@ -80,9 +90,40 @@ TestRunner.runTests = function(tests) { |
| /** |
| * @param {!Object} receiver |
| * @param {string} methodName |
| + * @param {!Function} override |
| + * @param {boolean} opt_sticky |
| + */ |
| +TestRunner.addSniffer = function(receiver, methodName, override, opt_sticky) { |
| + override = TestRunner.safeWrap(override); |
| + |
| + var original = receiver[methodName]; |
| + if (typeof original !== 'function') |
| + throw new Error('Cannot find method to override: ' + methodName); |
| + |
| + receiver[methodName] = function(var_args) { |
| + try { |
| + var result = original.apply(this, arguments); |
| + } finally { |
| + if (!opt_sticky) |
| + receiver[methodName] = original; |
| + } |
| + // In case of exception the override won't be called. |
| + try { |
| + Array.prototype.push.call(arguments, result); |
| + override.apply(this, arguments); |
| + } catch (e) { |
| + throw new Error('Exception in overriden method \'' + methodName + '\': ' + e); |
| + } |
| + return result; |
| + }; |
| +}; |
| + |
| +/** |
| + * @param {!Object} receiver |
| + * @param {string} methodName |
| * @return {!Promise<*>} |
| */ |
| -TestRunner.addSniffer = function(receiver, methodName) { |
| +TestRunner.addSnifferPromise = function(receiver, methodName) { |
| return new Promise(function(resolve, reject) { |
| var original = receiver[methodName]; |
| if (typeof original !== 'function') { |
| @@ -118,6 +159,14 @@ TestRunner.loadLazyModules = function(lazyModules) { |
| }; |
| /** |
| + * @param {!Array<string>} panels |
| + * @return {!Promise<!Array<!UI.Panel>>} |
| + */ |
| +TestRunner.loadPanels = function(panels) { |
|
dgozman
2017/04/25 21:08:28
Do we ever use multiple? Let's have loadPanel.
chenwilliam
2017/06/15 01:01:05
In a couple spots (e.g. https://cs.chromium.org/ch
|
| + return Promise.all(panels.map(panel => UI.inspectorView.panel(panel))); |
| +}; |
| + |
| +/** |
| * @param {string} key |
| * @param {boolean=} ctrlKey |
| * @param {boolean=} altKey |
| @@ -137,6 +186,32 @@ TestRunner.createKeyEvent = function(key, ctrlKey, altKey, shiftKey, metaKey) { |
| }); |
| }; |
| +/** |
| + * @param {!Function} func |
| + * @param {!Function=} onexception |
| + * @return {function()} |
| + */ |
| +TestRunner.safeWrap = function(func, onexception) { |
| + /** |
| + * @this {*} |
| + */ |
| + function result() { |
| + if (!func) |
| + return; |
| + var wrapThis = this; |
| + try { |
| + return func.apply(wrapThis, arguments); |
| + } catch (e) { |
| + TestRunner.addResult('Exception while running: ' + func + '\n' + (e.stack || e)); |
| + if (onexception) |
| + TestRunner.safeWrap(onexception)(); |
| + else |
| + TestRunner.completeTest(); |
| + } |
| + } |
| + return result; |
| +}; |
| + |
| (function() { |
| /** |
| * @param {string|!Event} message |