| 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..3fd9059e2080266e63c38e22203e4bc7138f059a
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/inspector/console/console-focus.html
|
| @@ -0,0 +1,169 @@
|
| +<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 < 20; 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)
|
| + logMessages();
|
| + else
|
| + InspectorTest.addSniffer(Console.ConsolePrompt.prototype, "_editorSetForTest", logMessages);
|
| +
|
| + function logMessages() {
|
| + InspectorTest.waitForConsoleMessages(minimumViewportMessagesCount, beginTests);
|
| + InspectorTest.evaluateInConsole("logToConsole()");
|
| + }
|
| +
|
| + function clearFocus() {
|
| + var focusedElement = document.deepActiveElement();
|
| + if (focusedElement)
|
| + focusedElement.blur();
|
| + }
|
| +
|
| + function beginTests() {
|
| + InspectorTest.runTestSuite(testSuite);
|
| + }
|
| +
|
| + var testSuite = [
|
| + function verifyViewportIsTallEnough(next)
|
| + {
|
| + viewport.invalidate();
|
| + viewport.forceScrollItemToBeFirst(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));
|
| + InspectorTest.completeTest();
|
| + return;
|
| + }
|
| + InspectorTest.addResult(String.sprintf("Viewport contains %d messages", viewportMessagesCount));
|
| + next();
|
| + },
|
| +
|
| + function testExpandingObjectShouldNotJump(next) {
|
| + dumpFocusInfo();
|
| + clickObjectInMessage(1);
|
| + InspectorTest.addSniffer(ObjectUI.ObjectPropertyTreeElement, "populateWithProperties", onExpanded);
|
| +
|
| + 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);
|
| +
|
| + 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");
|
| + }
|
| + InspectorTest.addResult("Is at bottom: " + viewport.element.isScrolledToBottom() + ", should stick: " + viewport.stickToBottom());
|
| + }
|
| +}
|
| +
|
| +</script>
|
| +</head>
|
| +
|
| +<body onload="runTest()">
|
| +<p>
|
| +Tests that interacting with the console gives appropriate focus.
|
| +</p>
|
| +
|
| +</body>
|
| +</html>
|
|
|