OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
4 <script src="../../http/tests/inspector/console-test.js"></script> | 4 <script src="../../http/tests/inspector/console-test.js"></script> |
5 <script> | 5 <script> |
6 function populateConsoleWithMessages(count) | 6 function populateConsoleWithMessages(count) |
7 { | 7 { |
8 for (var i = 0; i < count - 1; ++i) | 8 for (var i = 0; i < count - 1; ++i) |
9 console.log("Message #" + i); | 9 console.log("Message #" + i); |
10 console.log("hello %cworld", "color: blue"); | 10 console.log("hello %cworld", "color: blue"); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (!selection || !selection.rangeCount) { | 252 if (!selection || !selection.rangeCount) { |
253 InspectorTest.addResult("FAILURE: There's no selection"); | 253 InspectorTest.addResult("FAILURE: There's no selection"); |
254 return; | 254 return; |
255 } | 255 } |
256 viewport.forceScrollItemToBeFirst(Math.max(messageIndex - minimumViewpor
tMessagesCount / 2, 0)); | 256 viewport.forceScrollItemToBeFirst(Math.max(messageIndex - minimumViewpor
tMessagesCount / 2, 0)); |
257 var element = consoleView.itemElement(messageIndex).element(); | 257 var element = consoleView.itemElement(messageIndex).element(); |
258 selection.setBaseAndExtent(selection.anchorNode, selection.anchorOffset,
element, 0); | 258 selection.setBaseAndExtent(selection.anchorNode, selection.anchorOffset,
element, 0); |
259 viewport.refresh(); | 259 viewport.refresh(); |
260 } | 260 } |
261 | 261 |
262 function selectionContainerAndOffset(container, offset) | |
263 { | |
264 var charCount = 0; | |
265 var node = container; | |
266 while (node = node.traverseNextTextNode(true)) { | |
267 var length = node.textContent.length; | |
268 if (charCount + length >= offset) { | |
269 return { | |
270 container: node, | |
271 offset: offset - charCount | |
272 }; | |
273 } | |
274 charCount += length; | |
275 } | |
276 return null; | |
277 } | |
278 | |
279 function selectMessages(fromMessage, fromTextOffset, toMessage, toTextOffset
) | 262 function selectMessages(fromMessage, fromTextOffset, toMessage, toTextOffset
) |
280 { | 263 { |
281 if (Math.abs(toMessage - fromMessage) > minimumViewportMessagesCount) { | 264 if (Math.abs(toMessage - fromMessage) > minimumViewportMessagesCount) { |
282 InspectorTest.addResult(String.sprintf("FAILURE: Cannot select more
than %d messages (requested to select from %d to %d", minimumViewportMessagesCou
nt, fromMessage, toMessage)); | 265 InspectorTest.addResult(String.sprintf("FAILURE: Cannot select more
than %d messages (requested to select from %d to %d", minimumViewportMessagesCou
nt, fromMessage, toMessage)); |
283 InspectorTest.completeTest(); | 266 InspectorTest.completeTest(); |
284 return; | 267 return; |
285 } | 268 } |
286 viewport.forceScrollItemToBeFirst(Math.min(fromMessage, toMessage)); | 269 viewport.forceScrollItemToBeFirst(Math.min(fromMessage, toMessage)); |
287 | 270 |
288 var from = selectionContainerAndOffset(consoleView.itemElement(fromMessa
ge).element(), fromTextOffset); | 271 InspectorTest.selectConsoleMessages(fromMessage, fromTextOffset, toMessa
ge, toTextOffset); |
289 var to = selectionContainerAndOffset(consoleView.itemElement(toMessage).
element(), toTextOffset); | |
290 window.getSelection().setBaseAndExtent(from.container, from.offset, to.c
ontainer, to.offset); | |
291 viewport.refresh(); | 272 viewport.refresh(); |
292 } | 273 } |
293 } | 274 } |
294 </script> | 275 </script> |
295 </head> | 276 </head> |
296 <body onload="runTest()"> | 277 <body onload="runTest()"> |
297 <p> | 278 <p> |
298 Tests that console viewport handles selection properly. | 279 Tests that console viewport handles selection properly. |
299 </p> | 280 </p> |
300 </body> | 281 </body> |
301 </html> | 282 </html> |
OLD | NEW |