Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/inspector/console/console-focus.html |
| diff --git a/third_party/WebKit/LayoutTests/inspector/console/console-focus.html b/third_party/WebKit/LayoutTests/inspector/console/console-focus.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..580eedbd83c7c10802c83deb53c61bdb8e8645eb |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/inspector/console/console-focus.html |
| @@ -0,0 +1,179 @@ |
| +<html> |
| +<head> |
| +<script src="../../http/tests/inspector/inspector-test.js"></script> |
| +<script src="../../http/tests/inspector/console-test.js"></script> |
| +<script> |
| + |
| +function logToConsole() |
| +{ |
| + console.log({a: 1}); |
| + for (var i = 0; i < 40; i++) |
| + console.log(i); |
| +} |
| + |
| +var test = function() |
| +{ |
| + InspectorTest.fixConsoleViewportDimensions(600, 200); |
| + var minimumViewportMessagesCount = 10; |
| + var consoleView = Console.ConsoleView.instance(); |
| + var viewport = consoleView._viewport; |
| + var prompt = consoleView._prompt; |
| + clearFocus(); |
| + if (prompt._editor) |
|
pfeldman
2017/04/25 18:40:56
We should not have races in the tests, is there a
luoe
2017/04/25 23:00:34
I need the editor for checking the cursor position
|
| + logMessages(); |
| + else |
| + InspectorTest.addSniffer(Console.ConsolePrompt.prototype, "_editorSetForTest", logMessages); |
| + |
| + function logMessages() { |
| + InspectorTest.waitForConsoleMessages(22, beginTests); |
|
pfeldman
2017/04/25 18:40:56
() => InspectorTest.runTestSuite(testSuite)
luoe
2017/04/25 23:00:34
Done.
|
| + InspectorTest.evaluateInConsole("logToConsole()"); |
| + } |
| + |
| + function clearFocus() { |
| + var focusedElement = document.deepActiveElement(); |
| + if (focusedElement) |
| + focusedElement.blur(); |
|
pfeldman
2017/04/25 18:40:56
Where does this put the focus though? It might be
luoe
2017/04/25 23:00:34
Done, document.body.
|
| + } |
| + |
| + function beginTests() { |
| + InspectorTest.runTestSuite(testSuite); |
| + } |
| + |
| + var testSuite = [ |
| + function verifyViewportIsTallEnough(next) |
| + { |
| + viewport.invalidate(); |
|
pfeldman
2017/04/25 18:40:56
Changes to viewport API will now require updating
luoe
2017/04/25 23:00:34
Removed.
|
| + viewport.forceScrollItemToBeFirst(0); |
|
pfeldman
2017/04/25 18:40:56
ditto
luoe
2017/04/25 23:00:34
Replaced with setting scrollTop = 0.
|
| + var viewportMessagesCount = viewport.lastVisibleIndex() - viewport.firstVisibleIndex() + 1; |
| + if (viewportMessagesCount < minimumViewportMessagesCount) { |
| + InspectorTest.addResult(String.sprintf("Test cannot be run as viewport is not tall enough. It is required to contain at least %d messages, but %d only fit", minimumViewportMessagesCount, viewportMessagesCount)); |
|
pfeldman
2017/04/25 18:40:56
You can't have test giving up, it either works or
luoe
2017/04/25 23:00:34
Removed, this check doesn't really belong in a tes
|
| + InspectorTest.completeTest(); |
| + return; |
| + } |
| + InspectorTest.addResult(String.sprintf("Viewport contains %d messages", viewportMessagesCount)); |
| + next(); |
| + }, |
| + |
| + function testFocusingConsoleShouldNotJump(next) { |
| + clearFocus(); |
| + dumpFocusInfo(); |
| + consoleView.focus(); |
| + dumpFocusInfo(); |
|
pfeldman
2017/04/25 18:40:56
We should only dump the scrollTop, that's what we
luoe
2017/04/25 23:00:34
Done.
|
| + next(); |
| + }, |
| + |
| + function testExpandingObjectShouldNotJump(next) { |
| + clearFocus(); |
| + dumpFocusInfo(); |
| + clickObjectInMessage(1); |
| + InspectorTest.addSniffer(ObjectUI.ObjectPropertyTreeElement, "populateWithProperties", onExpanded); |
|
pfeldman
2017/04/25 18:40:56
Once again, we are not testing ObjectPropertySecti
luoe
2017/04/25 23:00:34
Done. For some reason I thought this was only hap
|
| + |
| + function onExpanded() |
| + { |
| + viewport.refresh(); |
| + dumpFocusInfo(); |
| + next(); |
| + } |
| + }, |
| + |
| + function testClickingWithSelectedTextShouldNotJump(next) { |
| + clearFocus(); |
| + dumpFocusInfo(); |
| + |
| + var messageElement = consoleView.itemElement(1).element(); |
| + var firstTextNode = messageElement.traverseNextTextNode(); |
| + window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNode, 1); |
| + |
| + clickObjectInMessage(1); |
| + viewport.refresh(); |
| + dumpFocusInfo(); |
| + |
| + InspectorTest.addResult("Scrolling to bottom"); |
| + consoleView._immediatelyScrollToBottom(); |
| + |
| + messageElement = consoleView._visibleViewMessages.peekLast().element(); |
| + firstTextNode = messageElement.traverseNextTextNode(); |
| + window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNode, 1); |
| + dumpFocusInfo(); |
| + next(); |
| + }, |
| + |
| + function testClickToFocusAndLoadConsoleHistoryShouldJump(next) { |
| + InspectorTest.evaluateInConsole("'history entry 1'", onMessageAdded); |
|
pfeldman
2017/04/25 18:40:56
Not sure what these are testing...
luoe
2017/04/25 23:00:34
Removed.
|
| + |
| + function onMessageAdded() { |
| + viewport.invalidate(); |
| + viewport.forceScrollItemToBeFirst(0); |
| + clearFocus(); |
| + dumpFocusInfo(); |
| + |
| + InspectorTest.addResult("Clicking container"); |
| + consoleView._messagesElement.click(); |
| + dumpFocusInfo(); |
| + |
| + InspectorTest.addResult("Sending up key"); |
| + var upKeyEvent = InspectorTest.createKeyEvent("Up"); |
| + // KeyCode cannot be set normally. |
| + Object.defineProperty(upKeyEvent, "keyCode", {value: 38}); |
| + prompt._editor.element.dispatchEvent(upKeyEvent); |
| + dumpFocusInfo(); |
| + InspectorTest.addResult("Selection in prompt: " + prompt._editor.selection().toString()); |
| + |
| + next(); |
| + } |
| + }, |
| + |
| + function testClickingBelowPromptShouldMoveCursor(next) { |
| + InspectorTest.addResult("Clearing console"); |
| + Console.ConsoleView.clearConsole(); |
| + viewport.invalidate(); |
| + clearFocus(); |
| + dumpFocusInfo(); |
| + |
| + prompt.setText("foobar"); |
| + prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0, 1)); |
| + InspectorTest.addResult("Selection before: " + prompt._editor.selection().toString()); |
| + |
| + consoleView._messagesElement.click(); |
| + |
| + InspectorTest.addResult("Selection after: " + prompt._editor.selection().toString()); |
| + dumpFocusInfo(); |
| + next(); |
| + } |
| + ]; |
| + |
| + function clickObjectInMessage(index) { |
| + var previewElement = consoleView._visibleViewMessages[index].element().querySelector('.console-object-preview'); |
| + var previewRect = previewElement.getBoundingClientRect(); |
| + var clientX = previewRect.left + previewRect.width / 2; |
| + var clientY = previewRect.top + previewRect.height / 2; |
| + |
| + InspectorTest.addResult('Clicking to expand object'); |
| + previewElement.dispatchEvent(new MouseEvent('click', {clientX, clientY, bubbles: true})); |
| + } |
| + |
| + function dumpFocusInfo() |
| + { |
| + var focusedElement = document.deepActiveElement(); |
| + if (focusedElement) { |
| + var id = focusedElement.id ? (", id: " + focusedElement.id) : ""; |
| + var className = focusedElement.className ? (", class: " + focusedElement.className) : ""; |
| + InspectorTest.addResult("Focused element: " + focusedElement.tagName + id + className); |
| + } else { |
| + InspectorTest.addResult("No focus"); |
| + } |
| + var scrollTop = viewport.element.scrollTop; |
| + InspectorTest.addResult("Viewport scrollTop: " + scrollTop); |
| + } |
| +} |
| + |
| +</script> |
| +</head> |
| + |
| +<body onload="runTest()"> |
| +<p> |
| +Tests that interacting with the console gives appropriate focus. |
| +</p> |
| + |
| +</body> |
| +</html> |