| <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 resetAndDumpFocusAndScrollTop() { |
| document.body.focus(); |
| viewport.element.scrollTop = 0; |
| dumpFocusAndScrollInfo(); |
| } |
| |
| function logMessages() { |
| InspectorTest.waitForConsoleMessages(2, () => InspectorTest.runTestSuite(testSuite)); |
| InspectorTest.evaluateInConsole("'foo " + "\n".repeat(50) + "bar'"); |
| } |
| |
| var testSuite = [ |
| function testClickingWithSelectedTextShouldNotFocusPrompt(next) { |
| resetAndDumpFocusAndScrollTop(); |
| |
| // Make a selection. |
| var messageElement = consoleView.itemElement(0).element(); |
| var firstTextNode = messageElement.traverseNextTextNode(); |
| window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNode, 1); |
| |
| clickObjectInMessage(0); |
| dumpFocusAndScrollInfo(); |
| window.getSelection().removeAllRanges(); |
| next(); |
| }, |
| |
| function testClickOnMessageShouldFocusPromptWithoutScrolling(next) { |
| resetAndDumpFocusAndScrollTop(); |
| |
| clickObjectInMessage(0); |
| |
| dumpFocusAndScrollInfo(); |
| next(); |
| }, |
| |
| function testClickOutsideMessageListShouldFocusPromptAndMoveCaretToEnd(next) { |
| prompt.setText("foobar"); |
| consoleEditor.setSelection(TextUtils.TextRange.createFromLocation(0, 1)); |
| resetAndDumpFocusAndScrollTop(); |
| InspectorTest.addResult("Selection before: " + consoleEditor.selection().toString()); |
| |
| InspectorTest.addResult("Clicking on container"); |
| consoleView._messagesElement.click(); |
| |
| dumpFocusAndScrollInfo(); |
| InspectorTest.addResult("Selection after: " + consoleEditor.selection().toString()); |
| 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 dumpFocusAndScrollInfo() |
| { |
| var focusedElement = document.deepActiveElement(); |
| if (focusedElement) |
| InspectorTest.addResult("Focused element: " + focusedElement.tagName); |
| else |
| InspectorTest.addResult("No focus"); |
| InspectorTest.addResult("Viewport scrolled to top: " + String(viewport.element.scrollTop === 0)); |
| } |
| } |
| |
| </script> |
| </head> |
| |
| <body onload="runTest()"> |
| <p> |
| Tests that interacting with the console gives appropriate focus. |
| </p> |
| |
| </body> |
| </html> |