| 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..e1529cd3f1b43146cfeb80b9105968540ee3042f 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,14 +4,14 @@
|
|
|
| /* eslint-disable no-console */
|
|
|
| -/** @type {!{notifyDone: function()}|undefined} */
|
| +/** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */
|
| self.testRunner;
|
|
|
| TestRunner.executeTestScript = function() {
|
| const testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
|
| fetch(testScriptURL)
|
| .then(data => data.text())
|
| - .then(testScript => eval(`(function test(){${testScript}})()\n//# sourceURL=${testScriptURL}`))
|
| + .then(testScript => eval(`(async function test(){${testScript}})()\n//# sourceURL=${testScriptURL}`))
|
| .catch(error => {
|
| TestRunner.addResult(`Unable to execute test script because of error: ${error}`);
|
| TestRunner.completeTest();
|
| @@ -57,6 +57,16 @@ TestRunner.addResult = function(text) {
|
| console.log(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
|
| */
|
| @@ -77,12 +87,43 @@ 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') {
|
| @@ -117,6 +158,14 @@ TestRunner.loadLazyModules = function(lazyModules) {
|
| return Promise.all(lazyModules.map(lazyModule => self.runtime.loadModulePromise(lazyModule)));
|
| };
|
|
|
| +/**
|
| + * @param {string} panel
|
| + * @return {!Promise<!UI.Panel>}
|
| + */
|
| +TestRunner.loadPanel = function(panel) {
|
| + return UI.inspectorView.panel(panel);
|
| +};
|
| +
|
| /**
|
| * @param {string} key
|
| * @param {boolean=} ctrlKey
|
| @@ -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
|
|
|