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

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

Issue 2837083003: DevTools: create test infrastructure so devtools drives the test (Closed)
Patch Set: rebaseline Created 3 years, 6 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 66e955615cee2c999558b822529e5239994f1a9d..900ed24c5399f46d750f048696de106317b12007 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() {
@@ -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') {
@@ -109,6 +150,14 @@ TestRunner.addSniffer = function(receiver, methodName) {
});
};
+/**
+ * @param {string} module
+ * @return {!Promise<undefined>}
+ */
+TestRunner.loadModule = function(module) {
+ return self.runtime.loadModulePromise(module);
+};
+
/**
* @param {!Array<string>} lazyModules
* @return {!Promise<!Array<undefined>>}
@@ -117,6 +166,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 +194,43 @@ 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;
+};
+
+/**
+ * @param {!Function} testFunction
+ * @return {!Function}
+ */
+function debugTest(testFunction) {
+ self.test = testFunction;
+ TestRunner.addResult = console.log;
+ TestRunner.completeTest = () => console.log('Test completed');
+ return () => {};
+}
+
(function() {
/**
* @param {string|!Event} message

Powered by Google App Engine
This is Rietveld 408576698