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

Unified Diff: webkit/glue/devtools/js/tests.js

Issue 155142: DevTools: merge TestSuite.Controller into TestSuite (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/devtools/js/tests.js
===================================================================
--- webkit/glue/devtools/js/tests.js (revision 20023)
+++ webkit/glue/devtools/js/tests.js (working copy)
@@ -18,6 +18,8 @@
* @constructor
*/
TestSuite = function() {
+ this.controlTaken_ = false;
+ this.timerId_ = -1;
};
@@ -26,7 +28,11 @@
* @param {string} message Failure description.
*/
TestSuite.prototype.fail = function(message) {
- throw message;
+ if (this.controlTaken_) {
+ this.reportFailure_(message);
+ } else {
+ throw message;
+ }
};
@@ -65,33 +71,9 @@
/**
- * Runs all global functions starting with 'test' as unit tests.
- */
-TestSuite.prototype.runAllTests = function() {
- // For debugging purposes.
- for (var name in this) {
- if (name.substring(0, 4) == 'test' &&
- typeof this[name] == 'function') {
- this.runTest(name);
- }
- }
-};
-
-
-/**
- * Manual controller for async tests.
- * @constructor.
- */
-TestSuite.Controller = function() {
- this.controlTaken_ = false;
- this.timerId_ = -1;
-};
-
-
-/**
* Takes control over execution.
*/
-TestSuite.Controller.prototype.takeControl = function() {
+TestSuite.prototype.takeControl = function() {
this.controlTaken_ = true;
// Set up guard timer.
var self = this;
@@ -104,11 +86,10 @@
/**
* Releases control over execution.
*/
-TestSuite.Controller.prototype.releaseControl = function() {
- this.controlTaken_ = false;
+TestSuite.prototype.releaseControl = function() {
if (this.timerId_ != -1) {
+ clearTimeout(this.timerId_);
this.timerId_ = -1;
- clearTimeout(this.timerId_);
}
this.reportOk_();
};
@@ -117,7 +98,7 @@
/**
* Async tests use this one to report that they are completed.
*/
-TestSuite.Controller.prototype.reportOk_ = function() {
+TestSuite.prototype.reportOk_ = function() {
window.domAutomationController.send('[OK]');
};
@@ -125,10 +106,10 @@
/**
* Async tests use this one to report failures.
*/
-TestSuite.Controller.prototype.reportFailure_ = function(error) {
+TestSuite.prototype.reportFailure_ = function(error) {
if (this.timerId_ != -1) {
+ clearTimeout(this.timerId_);
this.timerId_ = -1;
- clearTimeout(this.timerId_);
}
window.domAutomationController.send('[FAILED] ' + error);
};
@@ -138,14 +119,13 @@
* Runs all global functions starting with 'test' as unit tests.
*/
TestSuite.prototype.runTest = function(testName) {
- var controller = new TestSuite.Controller();
try {
- this[testName](controller);
- if (!controller.controlTaken_) {
- controller.reportOk_();
+ this[testName]();
+ if (!this.controlTaken_) {
+ this.reportOk_();
}
} catch (e) {
- controller.reportFailure_(e);
+ this.reportFailure_(e);
}
};
@@ -204,7 +184,7 @@
/**
* Tests that resources tab is enabled when corresponding item is selected.
*/
-TestSuite.prototype.testEnableResourcesTab = function(controller) {
+TestSuite.prototype.testEnableResourcesTab = function() {
this.showPanel('resources');
var test = this;
@@ -216,7 +196,7 @@
WebInspector.panels.resources.refresh();
WebInspector.resources[identifier]._resourcesTreeElement.select();
- controller.releaseControl();
+ test.releaseControl();
};
// Following call should lead to reload that we capture in the
@@ -224,14 +204,14 @@
WebInspector.panels.resources._enableResourceTracking();
// We now have some time to report results to controller.
- controller.takeControl();
+ this.takeControl();
};
/**
* Tests resource headers.
*/
-TestSuite.prototype.testResourceHeaders = function(controller) {
+TestSuite.prototype.testResourceHeaders = function() {
this.showPanel('resources');
var test = this;
@@ -281,19 +261,19 @@
test.assertTrue(responseOk);
test.assertTrue(timingOk);
test.assertTrue(typeof resource.endTime != 'undefnied');
- controller.releaseControl();
+ test.releaseControl();
}
};
WebInspector.panels.resources._enableResourceTracking();
- controller.takeControl();
+ this.takeControl();
};
/**
* Test that profiler works.
*/
-TestSuite.prototype.testProfilerTab = function(controller) {
+TestSuite.prototype.testProfilerTab = function() {
this.showPanel('profiles');
var test = this;
@@ -310,7 +290,7 @@
// that we actually have profiled page's code.
while (node) {
if (node.functionName.indexOf("fib") != -1) {
- controller.releaseControl();
+ test.releaseControl();
}
node = node.traverseNextNode(true, null, true);
}
@@ -320,14 +300,14 @@
InspectorController.startProfiling();
window.setTimeout('InspectorController.stopProfiling();', 1000);
- controller.takeControl();
+ this.takeControl();
};
/**
* Tests that scripts tab can be open and populated with inspected scripts.
*/
-TestSuite.prototype.testShowScriptsTab = function(controller) {
+TestSuite.prototype.testShowScriptsTab = function() {
var parsedDebuggerTestPageHtml = false;
var parsedDebuggerTestJs = false;
@@ -357,14 +337,14 @@
}
if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) {
- controller.releaseControl();
+ test.releaseControl();
}
};
this.showPanel('scripts');
// Wait until all scripts are added to the debugger.
- controller.takeControl();
+ this.takeControl();
};
@@ -381,7 +361,7 @@
/**
* Tests console eval.
*/
-TestSuite.prototype.testConsoleEval = function(controller) {
+TestSuite.prototype.testConsoleEval = function() {
WebInspector.console.visible = true;
WebInspector.console.prompt.text = '123';
WebInspector.console.promptElement.handleKeyEvent(
@@ -393,17 +373,17 @@
originalConsoleAddMessage.call(this, commandResult);
WebInspector.Console.prototype.addMessage = originalConsoleAddMessage;
test.assertEquals('123', commandResult.toMessageElement().textContent);
- controller.releaseControl();
+ test.releaseControl();
};
- controller.takeControl();
+ this.takeControl();
};
/**
* Tests console log.
*/
-TestSuite.prototype.testConsoleLog = function(controller) {
+TestSuite.prototype.testConsoleLog = function() {
WebInspector.console.visible = true;
var messages = WebInspector.console.messages;
var index = 0;
@@ -444,7 +424,7 @@
/**
* Tests eval of global objects.
*/
-TestSuite.prototype.testEvalGlobal = function(controller) {
+TestSuite.prototype.testEvalGlobal = function() {
WebInspector.console.visible = true;
WebInspector.console.prompt.text = 'foo';
WebInspector.console.promptElement.handleKeyEvent(
@@ -455,19 +435,47 @@
WebInspector.Console.prototype.addMessage = function(commandResult) {
originalConsoleAddMessage.call(this, commandResult);
test.assertEquals('fooValue', commandResult.toMessageElement().textContent);
- controller.releaseControl();
+ test.releaseControl();
};
- controller.takeControl();
+ this.takeControl();
};
/**
* Tests eval on call frame.
*/
-TestSuite.prototype.testEvalCallFrame = function(controller) {
+TestSuite.prototype.testEvalCallFrame = function() {
};
-var uiTests = new TestSuite();
+/**
+ * Test runner for the test suite.
+ */
+var uiTests = {};
+
+
+/**
+ * Run each test from the test suit on a fresh instance of the suite.
+ */
+uiTests.runAllTests = function() {
+ // For debugging purposes.
+ for (var name in TestSuite.prototype) {
+ if (name.substring(0, 4) == 'test' &&
+ typeof TestSuite.prototype[name] == 'function') {
+ uiTests.runTest(name);
+ }
+ }
+};
+
+
+/**
+ * Run specified test on a fresh instance of the test suite.
+ * @param {string} name Name of a test method from TestSuite class.
+ */
+uiTests.runTest = function(name) {
+ new TestSuite().runTest(name);
+};
+
+
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698