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

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: all 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..15685ddcfb1522fa688a2b49f93012f69b312f36 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,9 +4,11 @@
/* eslint-disable no-console */
-/** @type {!{notifyDone: function()}|undefined} */
+/** @type {!{logToStderr: function(), notifyDone: function()}|undefined} */
self.testRunner;
+Host.isUnderTest = () => true;
dgozman 2017/06/19 22:55:52 Why this?
chenwilliam 2017/06/19 23:48:18 I accidentally ran unit tests w/ integration test
+
TestRunner.executeTestScript = function() {
const testScriptURL = /** @type {string} */ (Runtime.queryParam('test'));
fetch(testScriptURL)
@@ -57,6 +59,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 +89,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 +160,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 +188,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}
+ */
+TestRunner.debugTest = function(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