Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Unified Diff: third_party/WebKit/Source/devtools/front_end/test_runner/TestRunner.js

Issue 2742623002: DevTools: improve test infrastructure w/ devtools driving the test (Closed)
Patch Set: fixup Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d270d6cde0bfb90428ee4d9dfce27312c5c172fd..639135d8a1557588f687ab42b9e7cd348f64bc80 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,10 +4,10 @@
/* eslint-disable no-console */
-/** @type {!{notifyDone: function()}|undefined} */
+/** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */
self.testRunner;
-TestRunner.executeTestScript = function() {
+TestRunner.start = function() {
fetch(`${Runtime.queryParam('test')}`)
.then(data => data.text())
.then(testScript => eval(`(function(){${testScript}})()`))
@@ -57,6 +57,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) {
@@ -79,9 +89,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) {
dgozman 2017/03/10 00:17:17 General question: should we use this opportunity t
+ 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) {
};
/**
+ * @param {!Array<string>} panels
+ * @return {!Promise<!Array<!UI.Panel>>}
+ */
+TestRunner.loadPanels = function(panels) {
+ return Promise.all(panels.map(panel => UI.inspectorView.panel(panel)));
+};
+
+/**
* @param {string} key
* @param {boolean=} ctrlKey
* @param {boolean=} altKey
@@ -136,6 +185,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

Powered by Google App Engine
This is Rietveld 408576698