| OLD | NEW |
| (Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../http/tests/inspector/console-test.js"></script> |
| 5 <script> |
| 6 |
| 7 function logToConsole() |
| 8 { |
| 9 console.log({a: 1}); |
| 10 for (var i = 0; i < 40; i++) |
| 11 console.log(i); |
| 12 } |
| 13 |
| 14 var test = function() |
| 15 { |
| 16 InspectorTest.fixConsoleViewportDimensions(600, 200); |
| 17 var minimumViewportMessagesCount = 10; |
| 18 var consoleView = Console.ConsoleView.instance(); |
| 19 var viewport = consoleView._viewport; |
| 20 var prompt = consoleView._prompt; |
| 21 clearFocus(); |
| 22 if (prompt._editor) |
| 23 logMessages(); |
| 24 else |
| 25 InspectorTest.addSniffer(Console.ConsolePrompt.prototype, "_editorSetFor
Test", logMessages); |
| 26 |
| 27 function logMessages() { |
| 28 InspectorTest.waitForConsoleMessages(22, beginTests); |
| 29 InspectorTest.evaluateInConsole("logToConsole()"); |
| 30 } |
| 31 |
| 32 function clearFocus() { |
| 33 var focusedElement = document.deepActiveElement(); |
| 34 if (focusedElement) |
| 35 focusedElement.blur(); |
| 36 } |
| 37 |
| 38 function beginTests() { |
| 39 InspectorTest.runTestSuite(testSuite); |
| 40 } |
| 41 |
| 42 var testSuite = [ |
| 43 function verifyViewportIsTallEnough(next) |
| 44 { |
| 45 viewport.invalidate(); |
| 46 viewport.forceScrollItemToBeFirst(0); |
| 47 var viewportMessagesCount = viewport.lastVisibleIndex() - viewport.f
irstVisibleIndex() + 1; |
| 48 if (viewportMessagesCount < minimumViewportMessagesCount) { |
| 49 InspectorTest.addResult(String.sprintf("Test cannot be run as vi
ewport is not tall enough. It is required to contain at least %d messages, but %
d only fit", minimumViewportMessagesCount, viewportMessagesCount)); |
| 50 InspectorTest.completeTest(); |
| 51 return; |
| 52 } |
| 53 InspectorTest.addResult(String.sprintf("Viewport contains %d message
s", viewportMessagesCount)); |
| 54 next(); |
| 55 }, |
| 56 |
| 57 function testFocusingConsoleShouldNotJumpOrMoveCursor(next) { |
| 58 clearFocus(); |
| 59 prompt.setText("foobar"); |
| 60 prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0
, 1)); |
| 61 viewport.forceScrollItemToBeFirst(0); |
| 62 dumpFocusInfo(); |
| 63 InspectorTest.addResult("Selection before: " + prompt._editor.select
ion().toString()); |
| 64 |
| 65 consoleView.focus(); |
| 66 |
| 67 InspectorTest.addResult("Selection after: " + prompt._editor.selecti
on().toString()); |
| 68 dumpFocusInfo(); |
| 69 next(); |
| 70 }, |
| 71 |
| 72 function testExpandingObjectShouldNotJump(next) { |
| 73 clearFocus(); |
| 74 dumpFocusInfo(); |
| 75 clickObjectInMessage(1); |
| 76 InspectorTest.addSniffer(ObjectUI.ObjectPropertyTreeElement, "popula
teWithProperties", onExpanded); |
| 77 |
| 78 function onExpanded() |
| 79 { |
| 80 viewport.refresh(); |
| 81 dumpFocusInfo(); |
| 82 next(); |
| 83 } |
| 84 }, |
| 85 |
| 86 function testClickingWithSelectedTextShouldNotJump(next) { |
| 87 clearFocus(); |
| 88 dumpFocusInfo(); |
| 89 |
| 90 var messageElement = consoleView.itemElement(1).element(); |
| 91 var firstTextNode = messageElement.traverseNextTextNode(); |
| 92 window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNo
de, 1); |
| 93 |
| 94 clickObjectInMessage(1); |
| 95 viewport.refresh(); |
| 96 dumpFocusInfo(); |
| 97 |
| 98 InspectorTest.addResult("Scrolling to bottom"); |
| 99 consoleView._immediatelyScrollToBottom(); |
| 100 |
| 101 messageElement = consoleView._visibleViewMessages.peekLast().element
(); |
| 102 firstTextNode = messageElement.traverseNextTextNode(); |
| 103 window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNo
de, 1); |
| 104 dumpFocusInfo(); |
| 105 next(); |
| 106 }, |
| 107 |
| 108 function testClickToFocusAndLoadConsoleHistoryShouldJump(next) { |
| 109 InspectorTest.evaluateInConsole("'history entry 1'", onMessageAdded)
; |
| 110 |
| 111 function onMessageAdded() { |
| 112 viewport.invalidate(); |
| 113 viewport.forceScrollItemToBeFirst(0); |
| 114 clearFocus(); |
| 115 dumpFocusInfo(); |
| 116 |
| 117 InspectorTest.addResult("Clicking container"); |
| 118 consoleView._messagesElement.click(); |
| 119 dumpFocusInfo(); |
| 120 |
| 121 InspectorTest.addResult("Sending up key"); |
| 122 var upKeyEvent = InspectorTest.createKeyEvent("Up"); |
| 123 // KeyCode cannot be set normally. |
| 124 Object.defineProperty(upKeyEvent, "keyCode", {value: 38}); |
| 125 prompt._editor.element.dispatchEvent(upKeyEvent); |
| 126 dumpFocusInfo(); |
| 127 InspectorTest.addResult("Selection in prompt: " + prompt._editor
.selection().toString()); |
| 128 |
| 129 next(); |
| 130 } |
| 131 }, |
| 132 |
| 133 function testClickingBelowPromptShouldMoveCursor(next) { |
| 134 InspectorTest.addResult("Clearing console"); |
| 135 Console.ConsoleView.clearConsole(); |
| 136 viewport.invalidate(); |
| 137 clearFocus(); |
| 138 dumpFocusInfo(); |
| 139 |
| 140 prompt.setText("foobar"); |
| 141 prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0
, 1)); |
| 142 InspectorTest.addResult("Selection before: " + prompt._editor.select
ion().toString()); |
| 143 |
| 144 consoleView._messagesElement.click(); |
| 145 |
| 146 InspectorTest.addResult("Selection after: " + prompt._editor.selecti
on().toString()); |
| 147 dumpFocusInfo(); |
| 148 next(); |
| 149 } |
| 150 ]; |
| 151 |
| 152 function clickObjectInMessage(index) { |
| 153 var previewElement = consoleView._visibleViewMessages[index].element().q
uerySelector('.console-object-preview'); |
| 154 var previewRect = previewElement.getBoundingClientRect(); |
| 155 var clientX = previewRect.left + previewRect.width / 2; |
| 156 var clientY = previewRect.top + previewRect.height / 2; |
| 157 |
| 158 InspectorTest.addResult('Clicking to expand object'); |
| 159 previewElement.dispatchEvent(new MouseEvent('click', {clientX, clientY,
bubbles: true})); |
| 160 } |
| 161 |
| 162 function dumpFocusInfo() |
| 163 { |
| 164 var focusedElement = document.deepActiveElement(); |
| 165 if (focusedElement) { |
| 166 var id = focusedElement.id ? (", id: " + focusedElement.id) : ""; |
| 167 var className = focusedElement.className ? (", class: " + focusedEle
ment.className) : ""; |
| 168 InspectorTest.addResult("Focused element: " + focusedElement.tagName
+ id + className); |
| 169 } else { |
| 170 InspectorTest.addResult("No focus"); |
| 171 } |
| 172 var scrollTop = viewport.element.scrollTop; |
| 173 InspectorTest.addResult("Viewport scrollTop: " + scrollTop); |
| 174 } |
| 175 } |
| 176 |
| 177 </script> |
| 178 </head> |
| 179 |
| 180 <body onload="runTest()"> |
| 181 <p> |
| 182 Tests that interacting with the console gives appropriate focus. |
| 183 </p> |
| 184 |
| 185 </body> |
| 186 </html> |
| OLD | NEW |