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..b72e040b98ae1aa8a10ae64f2266d2b5e2660533 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/inspector/console/console-focus.html |
@@ -0,0 +1,105 @@ |
+<html> |
+<head> |
+<script src="../../http/tests/inspector/inspector-test.js"></script> |
+<script src="../../http/tests/inspector/console-test.js"></script> |
+<script> |
+ |
+var test = function() |
+{ |
+ var consoleView = Console.ConsoleView.instance(); |
+ var viewport = consoleView._viewport; |
+ var prompt = consoleView._prompt; |
+ var consoleEditor; |
+ InspectorTest.waitUntilConsoleEditorLoaded().then(e => consoleEditor = e).then(logMessages); |
+ |
+ // Ensure that the body is focusable. |
+ document.body.tabIndex = -1; |
+ function clearFocus() { |
+ document.body.focus(); |
+ } |
+ |
+ function logMessages() { |
+ InspectorTest.waitForConsoleMessages(2, () => { |
+ viewport.element.scrollTop = 0; |
+ InspectorTest.runTestSuite(testSuite); |
+ }); |
+ InspectorTest.evaluateInConsole("'foo " + "\n".repeat(50) + "bar'"); |
+ } |
+ |
+ var testSuite = [ |
+ function testClickingWithSelectedTextShouldNotFocusPrompt(next) { |
pfeldman
2017/04/27 21:51:51
But does it scroll? We are fixing scrolling here,
luoe
2017/04/27 22:24:40
Done.
|
+ clearFocus(); |
+ dumpFocusInfo(); |
+ |
+ // Make a selection. |
+ var messageElement = consoleView.itemElement(0).element(); |
+ var firstTextNode = messageElement.traverseNextTextNode(); |
+ window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNode, 1); |
+ |
+ clickObjectInMessage(0); |
+ dumpFocusInfo(); |
+ window.getSelection().removeAllRanges(); |
+ next(); |
+ }, |
+ |
+ function testClickOnMessageShouldFocusPromptWithoutScrolling(next) { |
+ clearFocus(); |
+ dumpFocusInfo(); |
+ InspectorTest.addResult("Viewport scrollTop before: " + viewport.element.scrollTop); |
+ |
+ clickObjectInMessage(0); |
+ |
+ dumpFocusInfo(); |
+ InspectorTest.addResult("Viewport scrollTop after: " + viewport.element.scrollTop); |
+ next(); |
+ }, |
+ |
+ function testClickOutsideMessageListShouldFocusPromptAndMoveCaretToEnd(next) { |
pfeldman
2017/04/27 21:51:51
ditto
luoe
2017/04/27 22:24:40
Done.
|
+ clearFocus(); |
+ dumpFocusInfo(); |
+ |
+ prompt.setText("foobar"); |
+ consoleEditor.setSelection(TextUtils.TextRange.createFromLocation(0, 1)); |
+ InspectorTest.addResult("Selection before: " + consoleEditor.selection().toString()); |
+ |
+ consoleView._messagesElement.click(); |
+ |
+ InspectorTest.addResult("Selection after: " + consoleEditor.selection().toString()); |
+ dumpFocusInfo(); |
+ next(); |
+ } |
+ ]; |
+ |
+ function clickObjectInMessage(index) { |
+ var previewElement = consoleView._visibleViewMessages[index].element().querySelector('.source-code'); |
+ var previewRect = previewElement.getBoundingClientRect(); |
+ var clientX = previewRect.left + previewRect.width / 2; |
+ var clientY = previewRect.top + previewRect.height / 2; |
+ |
+ InspectorTest.addResult('Clicking message ' + index); |
+ previewElement.dispatchEvent(new MouseEvent('click', {clientX: clientX, clientY: 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"); |
+ } |
+ } |
+} |
+ |
+</script> |
+</head> |
+ |
+<body onload="runTest()"> |
+<p> |
+Tests that interacting with the console gives appropriate focus. |
+</p> |
+ |
+</body> |
+</html> |