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