Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: third_party/WebKit/LayoutTests/inspector/console/console-focus.html

Issue 2840663002: DevTools: clicking in console messages should not jump to bottom (Closed)
Patch Set: test Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 < 20; 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(minimumViewportMessagesCount, begin Tests);
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 testExpandingObjectShouldNotJump(next) {
58 dumpFocusInfo();
59 clickObjectInMessage(1);
60 InspectorTest.addSniffer(ObjectUI.ObjectPropertyTreeElement, "popula teWithProperties", onExpanded);
61
62 function onExpanded()
63 {
64 viewport.refresh();
65 dumpFocusInfo();
66 next();
67 }
68 },
69
70 function testClickingWithSelectedTextShouldNotJump(next) {
71 clearFocus();
72 dumpFocusInfo();
73
74 var messageElement = consoleView.itemElement(1).element();
75 var firstTextNode = messageElement.traverseNextTextNode();
76 window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNo de, 1);
77
78 clickObjectInMessage(1);
79 viewport.refresh();
80 dumpFocusInfo();
81
82 InspectorTest.addResult("Scrolling to bottom");
83 consoleView._immediatelyScrollToBottom();
84
85 messageElement = consoleView._visibleViewMessages.peekLast().element ();
86 firstTextNode = messageElement.traverseNextTextNode();
87 window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNo de, 1);
88 dumpFocusInfo();
89 next();
90 },
91
92 function testClickToFocusAndLoadConsoleHistoryShouldJump(next) {
93 InspectorTest.evaluateInConsole("'history entry 1'", onMessageAdded) ;
94
95 function onMessageAdded() {
96 viewport.invalidate();
97 viewport.forceScrollItemToBeFirst(0);
98 clearFocus();
99 dumpFocusInfo();
100
101 InspectorTest.addResult("Clicking container");
102 consoleView._messagesElement.click();
103 dumpFocusInfo();
104
105 InspectorTest.addResult("Sending up key");
106 var upKeyEvent = InspectorTest.createKeyEvent("Up");
107 // KeyCode cannot be set normally.
108 Object.defineProperty(upKeyEvent, "keyCode", {value: 38});
109 prompt._editor.element.dispatchEvent(upKeyEvent);
110 dumpFocusInfo();
111 InspectorTest.addResult("Selection in prompt: " + prompt._editor .selection().toString());
112
113 next();
114 }
115 },
116
117 function testClickingBelowPromptShouldMoveCursor(next) {
118 InspectorTest.addResult("Clearing console");
119 Console.ConsoleView.clearConsole();
120 viewport.invalidate();
121 clearFocus();
122 dumpFocusInfo();
123
124 prompt.setText("foobar");
125 prompt._editor.setSelection(TextUtils.TextRange.createFromLocation(0 , 1));
126 InspectorTest.addResult("Selection before: " + prompt._editor.select ion().toString());
127
128 consoleView._messagesElement.click();
129
130 InspectorTest.addResult("Selection after: " + prompt._editor.selecti on().toString());
131 dumpFocusInfo();
132 next();
133 }
134 ];
135
136 function clickObjectInMessage(index) {
137 var previewElement = consoleView._visibleViewMessages[index].element().q uerySelector('.console-object-preview');
138 var previewRect = previewElement.getBoundingClientRect();
139 var clientX = previewRect.left + previewRect.width / 2;
140 var clientY = previewRect.top + previewRect.height / 2;
141
142 InspectorTest.addResult('Clicking to expand object');
143 previewElement.dispatchEvent(new MouseEvent('click', {clientX, clientY, bubbles: true}));
144 }
145
146 function dumpFocusInfo()
147 {
148 var focusedElement = document.deepActiveElement();
149 if (focusedElement) {
150 var id = focusedElement.id ? (", id: " + focusedElement.id) : "";
151 var className = focusedElement.className ? (", class: " + focusedEle ment.className) : "";
152 InspectorTest.addResult("Focused element: " + focusedElement.tagName + id + className);
153 } else {
154 InspectorTest.addResult("No focus");
155 }
156 InspectorTest.addResult("Is at bottom: " + viewport.element.isScrolledTo Bottom() + ", should stick: " + viewport.stickToBottom());
157 }
158 }
159
160 </script>
161 </head>
162
163 <body onload="runTest()">
164 <p>
165 Tests that interacting with the console gives appropriate focus.
166 </p>
167
168 </body>
169 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698