| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 function testShiftClickSelectionBelow(next) | 114 function testShiftClickSelectionBelow(next) |
| 115 { | 115 { |
| 116 emulateShiftClickOnMessage(messagesCount - minimumViewportMessagesCo
unt); | 116 emulateShiftClickOnMessage(messagesCount - minimumViewportMessagesCo
unt); |
| 117 dumpSelectionModel(); | 117 dumpSelectionModel(); |
| 118 dumpViewportRenderedItems(); | 118 dumpViewportRenderedItems(); |
| 119 next(); | 119 next(); |
| 120 }, | 120 }, |
| 121 | 121 |
| 122 function testRemoveSelection(next) | 122 function testRemoveSelection(next) |
| 123 { | 123 { |
| 124 var selection = window.getSelection(); | 124 var selection = viewport.element.getComponentSelection(); |
| 125 selection.removeAllRanges(); | 125 selection.removeAllRanges(); |
| 126 dumpSelectionModel(); | 126 dumpSelectionModel(); |
| 127 dumpViewportRenderedItems(); | 127 dumpViewportRenderedItems(); |
| 128 next(); | 128 next(); |
| 129 }, | 129 }, |
| 130 | 130 |
| 131 function testReversedVisibleSelection(next) | 131 function testReversedVisibleSelection(next) |
| 132 { | 132 { |
| 133 selectMessages(middleMessage + 1, 6, middleMessage - 4, 6); | 133 selectMessages(middleMessage + 1, 6, middleMessage - 4, 6); |
| 134 dumpSelectionModel(); | 134 dumpSelectionModel(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 | 154 |
| 155 function testZeroOffsetSelection(next) | 155 function testZeroOffsetSelection(next) |
| 156 { | 156 { |
| 157 viewport.forceScrollItemToBeLast(messagesCount - 1); | 157 viewport.forceScrollItemToBeLast(messagesCount - 1); |
| 158 var lastMessageElement = viewport.renderedElementAt(messagesCount -
1); | 158 var lastMessageElement = viewport.renderedElementAt(messagesCount -
1); |
| 159 // there is a blue-colored "world" span in last message. | 159 // there is a blue-colored "world" span in last message. |
| 160 var blueSpan = lastMessageElement; | 160 var blueSpan = lastMessageElement; |
| 161 while (blueSpan.nodeName !== "SPAN" || blueSpan.textContent !== "wor
ld") | 161 while (blueSpan.nodeName !== "SPAN" || blueSpan.textContent !== "wor
ld") |
| 162 blueSpan = blueSpan.traverseNextNode(); | 162 blueSpan = blueSpan.traverseNextNode(); |
| 163 | 163 |
| 164 window.getSelection().setBaseAndExtent(blueSpan, 0, blueSpan, blueSp
an.textContent.length); | 164 viewport.element.getComponentSelection().setBaseAndExtent(blueSpan,
0, blueSpan, blueSpan.textContent.length); |
| 165 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); | 165 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); |
| 166 next(); | 166 next(); |
| 167 }, | 167 }, |
| 168 | 168 |
| 169 function testSelectAll(next) | 169 function testSelectAll(next) |
| 170 { | 170 { |
| 171 viewport.forceScrollItemToBeFirst(0); | 171 viewport.forceScrollItemToBeFirst(0); |
| 172 | 172 |
| 173 // Set some initial selection in console. | 173 // Set some initial selection in console. |
| 174 var base = consoleView.itemElement(messagesCount - 2).element(); | 174 var base = consoleView.itemElement(messagesCount - 2).element(); |
| 175 var extent = consoleView.itemElement(messagesCount - 1).element(); | 175 var extent = consoleView.itemElement(messagesCount - 1).element(); |
| 176 window.getSelection().setBaseAndExtent(base, 0, extent, 0); | 176 viewport.element.getComponentSelection().setBaseAndExtent(base, 0, e
xtent, 0); |
| 177 | 177 |
| 178 // Try to select all messages. | 178 // Try to select all messages. |
| 179 document.execCommand("selectAll"); | 179 document.execCommand("selectAll"); |
| 180 | 180 |
| 181 var text = viewport._selectedText(); | 181 var text = viewport._selectedText(); |
| 182 var count = text ? text.split("\n").length : 0; | 182 var count = text ? text.split("\n").length : 0; |
| 183 InspectorTest.addResult(count === messagesCount ? "Selected all " +
count + " messages." : "Selected " + count + " messages instead of " + messagesC
ount); | 183 InspectorTest.addResult(count === messagesCount ? "Selected all " +
count + " messages." : "Selected " + count + " messages instead of " + messagesC
ount); |
| 184 next(); | 184 next(); |
| 185 }, | 185 }, |
| 186 | 186 |
| 187 function testSelectWithNonTextNodeContainer(next) | 187 function testSelectWithNonTextNodeContainer(next) |
| 188 { | 188 { |
| 189 viewport.forceScrollItemToBeFirst(0); | 189 viewport.forceScrollItemToBeFirst(0); |
| 190 | 190 |
| 191 var nonTextNodeBase = consoleView.itemElement(1).element(); | 191 var nonTextNodeBase = consoleView.itemElement(1).element(); |
| 192 var nonTextNodeExtent = consoleView.itemElement(2).element(); | 192 var nonTextNodeExtent = consoleView.itemElement(2).element(); |
| 193 var textNodeBase = consoleView.itemElement(1).element().traverseNext
TextNode(); | 193 var textNodeBase = consoleView.itemElement(1).element().traverseNext
TextNode(); |
| 194 var textNodeExtent = consoleView.itemElement(2).element().traverseNe
xtTextNode(); | 194 var textNodeExtent = consoleView.itemElement(2).element().traverseNe
xtTextNode(); |
| 195 | 195 |
| 196 window.getSelection().setBaseAndExtent(nonTextNodeBase, 0, nonTextNo
deExtent, 0); | 196 viewport.element.getComponentSelection().setBaseAndExtent(nonTextNod
eBase, 0, nonTextNodeExtent, 0); |
| 197 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); | 197 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); |
| 198 | 198 |
| 199 window.getSelection().setBaseAndExtent(textNodeBase, 0, nonTextNodeE
xtent, 0); | 199 viewport.element.getComponentSelection().setBaseAndExtent(textNodeBa
se, 0, nonTextNodeExtent, 0); |
| 200 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); | 200 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); |
| 201 | 201 |
| 202 window.getSelection().setBaseAndExtent(nonTextNodeBase, 0, textNodeE
xtent, 0); | 202 viewport.element.getComponentSelection().setBaseAndExtent(nonTextNod
eBase, 0, textNodeExtent, 0); |
| 203 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); | 203 InspectorTest.addResult("Selected text: " + viewport._selectedText()
); |
| 204 | 204 |
| 205 next(); | 205 next(); |
| 206 } | 206 } |
| 207 ]; | 207 ]; |
| 208 | 208 |
| 209 var awaitingMessagesCount = messagesCount; | 209 var awaitingMessagesCount = messagesCount; |
| 210 function messageAdded() | 210 function messageAdded() |
| 211 { | 211 { |
| 212 if (!--awaitingMessagesCount) | 212 if (!--awaitingMessagesCount) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 241 { | 241 { |
| 242 viewport.refresh(); | 242 viewport.refresh(); |
| 243 var firstVisibleIndex = viewport.firstVisibleIndex(); | 243 var firstVisibleIndex = viewport.firstVisibleIndex(); |
| 244 var lastVisibleIndex = viewport.lastVisibleIndex(); | 244 var lastVisibleIndex = viewport.lastVisibleIndex(); |
| 245 InspectorTest.addResult("first visible message index: " + firstVisibleIn
dex); | 245 InspectorTest.addResult("first visible message index: " + firstVisibleIn
dex); |
| 246 } | 246 } |
| 247 | 247 |
| 248 function emulateShiftClickOnMessage(messageIndex) | 248 function emulateShiftClickOnMessage(messageIndex) |
| 249 { | 249 { |
| 250 viewport.refresh(); | 250 viewport.refresh(); |
| 251 var selection = window.getSelection(); | 251 var selection = viewport.element.getComponentSelection(); |
| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 280 { | 280 { |
| 281 if (Math.abs(toMessage - fromMessage) > minimumViewportMessagesCount) { | 281 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)); | 282 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(); | 283 InspectorTest.completeTest(); |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 viewport.forceScrollItemToBeFirst(Math.min(fromMessage, toMessage)); | 286 viewport.forceScrollItemToBeFirst(Math.min(fromMessage, toMessage)); |
| 287 | 287 |
| 288 var from = selectionContainerAndOffset(consoleView.itemElement(fromMessa
ge).element(), fromTextOffset); | 288 var from = selectionContainerAndOffset(consoleView.itemElement(fromMessa
ge).element(), fromTextOffset); |
| 289 var to = selectionContainerAndOffset(consoleView.itemElement(toMessage).
element(), toTextOffset); | 289 var to = selectionContainerAndOffset(consoleView.itemElement(toMessage).
element(), toTextOffset); |
| 290 window.getSelection().setBaseAndExtent(from.container, from.offset, to.c
ontainer, to.offset); | 290 viewport.element.getComponentSelection().setBaseAndExtent(from.container
, from.offset, to.container, to.offset); |
| 291 viewport.refresh(); | 291 viewport.refresh(); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 </script> | 294 </script> |
| 295 </head> | 295 </head> |
| 296 <body onload="runTest()"> | 296 <body onload="runTest()"> |
| 297 <p> | 297 <p> |
| 298 Tests that console viewport handles selection properly. | 298 Tests that console viewport handles selection properly. |
| 299 </p> | 299 </p> |
| 300 </body> | 300 </body> |
| 301 </html> | 301 </html> |
| OLD | NEW |