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 var test = function() | |
8 { | |
9 var consoleView = Console.ConsoleView.instance(); | |
10 var viewport = consoleView._viewport; | |
11 var prompt = consoleView._prompt; | |
12 var consoleEditor; | |
13 InspectorTest.waitUntilConsoleEditorLoaded().then(e => consoleEditor = e).th en(logMessages); | |
14 | |
15 // Ensure that the body is focusable. | |
16 document.body.tabIndex = -1; | |
17 function clearFocus() { | |
18 document.body.focus(); | |
19 } | |
20 | |
21 function logMessages() { | |
22 InspectorTest.waitForConsoleMessages(2, () => { | |
23 viewport.element.scrollTop = 0; | |
24 InspectorTest.runTestSuite(testSuite); | |
25 }); | |
26 InspectorTest.evaluateInConsole("'foo " + "\n".repeat(50) + "bar'"); | |
27 } | |
28 | |
29 var testSuite = [ | |
30 function testClickingWithSelectedTextShouldNotFocusPrompt(next) { | |
pfeldman
2017/04/27 21:51:51
But does it scroll? We are fixing scrolling here,
luoe
2017/04/27 22:24:40
Done.
| |
31 clearFocus(); | |
32 dumpFocusInfo(); | |
33 | |
34 // Make a selection. | |
35 var messageElement = consoleView.itemElement(0).element(); | |
36 var firstTextNode = messageElement.traverseNextTextNode(); | |
37 window.getSelection().setBaseAndExtent(firstTextNode, 0, firstTextNo de, 1); | |
38 | |
39 clickObjectInMessage(0); | |
40 dumpFocusInfo(); | |
41 window.getSelection().removeAllRanges(); | |
42 next(); | |
43 }, | |
44 | |
45 function testClickOnMessageShouldFocusPromptWithoutScrolling(next) { | |
46 clearFocus(); | |
47 dumpFocusInfo(); | |
48 InspectorTest.addResult("Viewport scrollTop before: " + viewport.ele ment.scrollTop); | |
49 | |
50 clickObjectInMessage(0); | |
51 | |
52 dumpFocusInfo(); | |
53 InspectorTest.addResult("Viewport scrollTop after: " + viewport.elem ent.scrollTop); | |
54 next(); | |
55 }, | |
56 | |
57 function testClickOutsideMessageListShouldFocusPromptAndMoveCaretToEnd(n ext) { | |
pfeldman
2017/04/27 21:51:51
ditto
luoe
2017/04/27 22:24:40
Done.
| |
58 clearFocus(); | |
59 dumpFocusInfo(); | |
60 | |
61 prompt.setText("foobar"); | |
62 consoleEditor.setSelection(TextUtils.TextRange.createFromLocation(0, 1)); | |
63 InspectorTest.addResult("Selection before: " + consoleEditor.selecti on().toString()); | |
64 | |
65 consoleView._messagesElement.click(); | |
66 | |
67 InspectorTest.addResult("Selection after: " + consoleEditor.selectio n().toString()); | |
68 dumpFocusInfo(); | |
69 next(); | |
70 } | |
71 ]; | |
72 | |
73 function clickObjectInMessage(index) { | |
74 var previewElement = consoleView._visibleViewMessages[index].element().q uerySelector('.source-code'); | |
75 var previewRect = previewElement.getBoundingClientRect(); | |
76 var clientX = previewRect.left + previewRect.width / 2; | |
77 var clientY = previewRect.top + previewRect.height / 2; | |
78 | |
79 InspectorTest.addResult('Clicking message ' + index); | |
80 previewElement.dispatchEvent(new MouseEvent('click', {clientX: clientX, clientY: clientY, bubbles: true})); | |
81 } | |
82 | |
83 function dumpFocusInfo() | |
84 { | |
85 var focusedElement = document.deepActiveElement(); | |
86 if (focusedElement) { | |
87 var id = focusedElement.id ? (", id: " + focusedElement.id) : ""; | |
88 var className = focusedElement.className ? (", class: " + focusedEle ment.className) : ""; | |
89 InspectorTest.addResult("Focused element: " + focusedElement.tagName + id + className); | |
90 } else { | |
91 InspectorTest.addResult("No focus"); | |
92 } | |
93 } | |
94 } | |
95 | |
96 </script> | |
97 </head> | |
98 | |
99 <body onload="runTest()"> | |
100 <p> | |
101 Tests that interacting with the console gives appropriate focus. | |
102 </p> | |
103 | |
104 </body> | |
105 </html> | |
OLD | NEW |