Commit 13c68582 authored by pfeldman@chromium.org's avatar pfeldman@chromium.org

DevTools: Console tests.

Review URL: http://codereview.chromium.org/149178

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19904 0039d316-1c4b-4281-b951-d872f2087c98
parent beea9c0e
......@@ -44,6 +44,7 @@ const int kActionDelayMs = 500;
const wchar_t kSimplePage[] = L"files/devtools/simple_page.html";
const wchar_t kJsPage[] = L"files/devtools/js_page.html";
const wchar_t kDebuggerTestPage[] = L"files/devtools/debugger_test_page.html";
const wchar_t kConsoleTestPage[] = L"files/devtools/console_test_page.html";
class DevToolsSanityTest : public InProcessBrowserTest {
public:
......@@ -144,4 +145,14 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) {
RunTest("testShowScriptsTab", kDebuggerTestPage);
}
// Tests console eval.
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleEval) {
RunTest("testConsoleEval", kConsoleTestPage);
}
// Tests console log.
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleLog) {
RunTest("testConsoleLog", kConsoleTestPage);
}
} // namespace
<html>
<head>
<script type="text/javascript">
console.log('log');
console.debug('debug');
console.info('info');
console.warn('warn');
console.error('error');
console.log('Message format number %i, %d and %f', 1, 2, 3.5);
console.log('Message %s for %s', 'format', 'string');
console.log('Object %o', {'foo' : 'bar' });
for (var i = 0; i < 5; ++i) {
console.log('repeated');
}
for (var i = 0; i < 2; ++i) {
console.count('count');
}
console.group('group');
console.groupEnd();
console.time('timer');
console.timeEnd('timer');
</script>
</head>
<body>
</body>
</html>
......@@ -384,6 +384,11 @@ DevToolsHostStub.prototype.addResourceSourceToFrame = function(
};
DevToolsHostStub.prototype.addSourceToFrame = function(mimeType, source,
element) {
};
if (!window['DevToolsHost']) {
window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub();
window['RemoteDebuggerCommandExecutor'] =
......
......@@ -52,6 +52,18 @@ TestSuite.prototype.assertTrue = function(value) {
};
/**
* Contains assertion tests that string contains substring.
* @param {string} string Outer.
* @param {string} substring Inner.
*/
TestSuite.prototype.assertContains = function(string, substring) {
if (string.indexOf(substring) == -1) {
this.fail('Expected to: "' + string + '" to contain "' + substring + '"');
}
};
/**
* Runs all global functions starting with 'test' as unit tests.
*/
......@@ -137,6 +149,18 @@ TestSuite.prototype.runTest = function(testName) {
};
/**
* @param {string} panelName Name of the panel to show.
*/
TestSuite.prototype.showPanel = function(panelName) {
// Open Scripts panel.
var toolbar = document.getElementById('toolbar');
var button = toolbar.getElementsByClassName(panelName)[0];
button.click();
this.assertEquals(WebInspector.panels[panelName],
WebInspector.currentPanel);
};
// UI Tests
......@@ -180,8 +204,7 @@ TestSuite.prototype.testMainResource = function() {
* Tests that resources tab is enabled when corresponding item is selected.
*/
TestSuite.prototype.testEnableResourcesTab = function(controller) {
WebInspector.panels.elements.hide();
WebInspector.panels.resources.show();
this.showPanel('resources');
var test = this;
var oldAddResource = WebInspector.addResource;
......@@ -208,15 +231,14 @@ TestSuite.prototype.testEnableResourcesTab = function(controller) {
* Test that profiler works.
*/
TestSuite.prototype.testProfilerTab = function(controller) {
var panel = WebInspector.panels.profiles;
WebInspector.panels.elements.hide();
panel.show();
this.showPanel('profiles');
var oldAddProfile = WebInspector.addProfile;
WebInspector.addProfile = function(profile) {
WebInspector.addProfile = oldAddProfile;
oldAddProfile.call(this, profile);
var panel = WebInspector.panels.profiles;
panel.showProfile(profile);
var node = panel.visibleView.profileDataGridTree.children[0];
// Iterate over displayed functions and search for a function
......@@ -276,21 +298,84 @@ TestSuite.prototype.testShowScriptsTab = function(controller) {
if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) {
controller.reportOk();
}
controller.reportOk();
};
// Open Scripts panel.
var toolbar = document.getElementById('toolbar');
var scriptsButton = toolbar.getElementsByClassName('scripts')[0];
scriptsButton.click();
this.assertEquals(WebInspector.panels.scripts, WebInspector.currentPanel);
this.showPanel('scripts');
// Wait until all scripts are added to the debugger.
controller.takeControl();
};
var uiTests = new TestSuite();
TestSuite.ConsoleEnter = {
keyIdentifier : 'Enter',
preventDefault : function() {},
stopPropagation : function() {}
};
/**
* Tests console eval.
*/
TestSuite.prototype.testConsoleEval = function(controller) {
var test = this;
var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage;
WebInspector.Console.prototype.addMessage = function(commandResult) {
originalConsoleAddMessage.call(this, commandResult);
WebInspector.Console.prototype.addMessage = originalConsoleAddMessage;
test.assertEquals('123', commandResult.toMessageElement().textContent);
controller.reportOk();
};
WebInspector.console.visible = true;
WebInspector.console.prompt.text = '123';
WebInspector.console.promptElement.handleKeyEvent(TestSuite.ConsoleEnter);
controller.takeControl();
};
/**
* Tests console log.
*/
TestSuite.prototype.testConsoleLog = function(controller) {
WebInspector.console.visible = true;
var messages = WebInspector.console.messages;
var index = 0;
var test = this;
var assertNext = function(line, message, opt_level, opt_count, opt_substr) {
var elem = messages[index++].toMessageElement();
var clazz = elem.getAttribute('class');
var expectation = (opt_count || '') + 'console_test_page.html:' +
line + message;
if (opt_substr) {
test.assertContains(elem.textContent, expectation);
} else {
test.assertEquals(expectation, elem.textContent);
}
if (opt_level) {
test.assertContains(clazz, 'console-' + opt_level + '-level');
}
};
assertNext('5', 'log', 'log');
assertNext('7', 'debug', 'log');
assertNext('9', 'info', 'log');
assertNext('11', 'warn', 'warning');
assertNext('13', 'error', 'error');
assertNext('15', 'Message format number 1, 2 and 3.5');
assertNext('17', 'Message format for string');
assertNext('19', 'Object Object');
assertNext('22', 'repeated', 'log', 5);
assertNext('26', 'count: 1');
assertNext('26', 'count: 2');
assertNext('29', 'group', 'group-title');
index++;
assertNext('33', 'timer:', 'log', '', true);
};
var uiTests = new TestSuite();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment