OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script src="../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../http/tests/inspector/workspace-test.js"></script> |
| 5 <script src="../http/tests/inspector/debugger-test.js"></script> |
| 6 <script src="resources/blink-fs.js"></script> |
| 7 <script src="editor/editor-test.js"></script> |
| 8 <script> |
| 9 function test() |
| 10 { |
| 11 WebInspector.experimentsSettings.jumpToPreviousLocation.enableForTest(); |
| 12 WebInspector.showPanel("sources"); |
| 13 var panel = WebInspector.panels.sources; |
| 14 |
| 15 function rollback() |
| 16 { |
| 17 panel._historyManager.rollback(); |
| 18 } |
| 19 |
| 20 function rollover() |
| 21 { |
| 22 panel._historyManager.rollover(); |
| 23 } |
| 24 |
| 25 function clickAtEditor(editor, lineNumber, columnNumber) |
| 26 { |
| 27 editor.scrollToLine(lineNumber); |
| 28 var coordinates = editor.cursorPositionToCoordinates(lineNumber, columnN
umber); |
| 29 eventSender.mouseMoveTo(coordinates.x, coordinates.y); |
| 30 eventSender.mouseDown(); |
| 31 eventSender.mouseUp(); |
| 32 dumpSelection(editor, "Mouse click (" + lineNumber + ", " + columnNumber
+ ")"); |
| 33 } |
| 34 |
| 35 function clickAndDump(editor, callback, lines, columns) |
| 36 { |
| 37 var iterationsAmount = lines.length; |
| 38 function innerClickAndDump(iteration) |
| 39 { |
| 40 if (iteration === iterationsAmount) { |
| 41 callback(); |
| 42 return; |
| 43 } |
| 44 clickAtEditor(editor, lines[iteration], columns[iteration]); |
| 45 setTimeout(innerClickAndDump.bind(this, iteration + 1), 0); |
| 46 } |
| 47 innerClickAndDump(0); |
| 48 } |
| 49 |
| 50 function dumpLineColumn(line, column) |
| 51 { |
| 52 return "line: " + line + " column: " + column; |
| 53 } |
| 54 |
| 55 function dumpSelection(editor, label) |
| 56 { |
| 57 var selection = editor.selection(); |
| 58 var label = "<" + label + ">"; |
| 59 var fileName = "[" + editor._url.split("/").pop() + "]"; |
| 60 var selectionText = ""; |
| 61 if (selection.isEmpty()) |
| 62 selectionText = "line: " + selection.startLine + " column: " + selec
tion.startColumn; |
| 63 else |
| 64 selectionText = "(NOT EMPTY): " + selection.toString(); |
| 65 InspectorTest.addResult(label + " " + selectionText + " " + fileName); |
| 66 } |
| 67 |
| 68 InspectorTest.runTestSuite([ |
| 69 function testSimpleMovements(next) |
| 70 { |
| 71 InspectorTest.showScriptSource("blink-fs.js", onContentLoaded); |
| 72 |
| 73 function onContentLoaded() |
| 74 { |
| 75 var editor = panel.visibleView.textEditor; |
| 76 dumpSelection(editor, "Initial position"); |
| 77 clickAtEditor(editor, 4, 7); |
| 78 |
| 79 InspectorTest.typeIn("\nSome more text here"); |
| 80 dumpSelection(editor, "Typed in some text"); |
| 81 |
| 82 rollback(); |
| 83 dumpSelection(editor, "Rolled back"); |
| 84 InspectorTest.typeIn("\nSome more text here as well\n"); |
| 85 dumpSelection(editor, "Typed in some text"); |
| 86 |
| 87 rollover(); |
| 88 dumpSelection(editor, "Rolled over"); |
| 89 next(); |
| 90 } |
| 91 }, |
| 92 |
| 93 function testSequentialJumps(next) |
| 94 { |
| 95 var editor = panel.visibleView.textEditor; |
| 96 const jumpsToDo = 4; |
| 97 clickAndDump(editor, jumpBack, [10, 11, 12, 13], [3, 4, 5, 6]); |
| 98 |
| 99 function jumpBack() |
| 100 { |
| 101 for (var i = 0; i < jumpsToDo; ++i) { |
| 102 rollback(); |
| 103 dumpSelection(editor, "Rolled back"); |
| 104 } |
| 105 for (var i = 0; i < jumpsToDo; ++i) { |
| 106 rollover(); |
| 107 dumpSelection(editor, "Rolled over"); |
| 108 } |
| 109 next(); |
| 110 } |
| 111 }, |
| 112 |
| 113 function testDeletePreviousJumpLocations(next) |
| 114 { |
| 115 var editor = panel.visibleView.textEditor; |
| 116 editor.editRange(new WebInspector.TextRange(9, 0, 15, 0), ""); |
| 117 dumpSelection(editor, "Removed lines from 9 to 15"); |
| 118 rollback(); |
| 119 dumpSelection(editor, "Rolled back"); |
| 120 rollover(); |
| 121 dumpSelection(editor, "Rolled over"); |
| 122 next(); |
| 123 }, |
| 124 |
| 125 function testDeleteNextJumpLocations(next) |
| 126 { |
| 127 var editor = panel.visibleView.textEditor; |
| 128 const jumpsToDo = 4; |
| 129 clickAndDump(editor, step2, [10, 11, 12, 13], [3, 4, 5, 6]); |
| 130 |
| 131 function step2() |
| 132 { |
| 133 for (var i = 0; i < jumpsToDo; ++i) |
| 134 rollback(); |
| 135 dumpSelection(editor, "Rolled back 4 times"); |
| 136 editor.editRange(new WebInspector.TextRange(9, 0, 11, 0), ""); |
| 137 dumpSelection(editor, "Removed lines from 9 to 11"); |
| 138 rollover(); |
| 139 dumpSelection(editor, "Rolled over"); |
| 140 next(); |
| 141 } |
| 142 }, |
| 143 |
| 144 function testCrossFileJump(next) |
| 145 { |
| 146 InspectorTest.showScriptSource("workspace-test.js", onContentLoaded)
; |
| 147 function onContentLoaded() |
| 148 { |
| 149 var editor = panel.visibleView.textEditor; |
| 150 dumpSelection(editor, "Opened workspace-test.js"); |
| 151 clickAndDump(editor, step2, [10, 11], [1, 1]); |
| 152 } |
| 153 function step2() |
| 154 { |
| 155 for (var i = 0; i < 4; ++i) { |
| 156 rollback(); |
| 157 dumpSelection(panel.visibleView.textEditor, "Rolled back"); |
| 158 } |
| 159 for (var i = 0; i < 4; ++i) { |
| 160 rollover(); |
| 161 dumpSelection(panel.visibleView.textEditor, "Rolled over"); |
| 162 } |
| 163 next(); |
| 164 } |
| 165 }, |
| 166 |
| 167 function testCloseCrossFile(next) |
| 168 { |
| 169 var selectedTab = panel._editorContainer._tabbedPane.selectedTabId; |
| 170 panel._editorContainer._tabbedPane.closeTab(selectedTab); |
| 171 dumpSelection(panel.visibleView.textEditor, "Close active tab"); |
| 172 for (var i = 0; i < 1; ++i) { |
| 173 rollback(); |
| 174 dumpSelection(panel.visibleView.textEditor, "Rolled back"); |
| 175 } |
| 176 for (var i = 0; i < 3; ++i) { |
| 177 rollover(); |
| 178 dumpSelection(panel.visibleView.textEditor, "Rolled over"); |
| 179 } |
| 180 next(); |
| 181 }, |
| 182 |
| 183 function testHistoryDepth(next) |
| 184 { |
| 185 var lines = []; |
| 186 var columns = []; |
| 187 const jumpsAmount = WebInspector.EditingLocationHistoryManager.Histo
ryDepth; |
| 188 for(var i = 0; i < jumpsAmount; ++i) { |
| 189 lines.push(i + 10); |
| 190 columns.push(7); |
| 191 } |
| 192 var editor = panel.visibleView.textEditor; |
| 193 clickAndDump(editor, step2, lines, columns); |
| 194 function step2() |
| 195 { |
| 196 for (var i = 0; i < jumpsAmount; ++i) { |
| 197 rollback(); |
| 198 dumpSelection(editor, "Rolled back"); |
| 199 } |
| 200 next(); |
| 201 } |
| 202 }, |
| 203 |
| 204 function testInFileSearch(next) |
| 205 { |
| 206 var searchableView = panel.searchableView(); |
| 207 searchableView.showSearchField(); |
| 208 dumpSelection(panel.visibleView.textEditor, "Before searching"); |
| 209 InspectorTest.typeIn("generate_"); |
| 210 for (var i = 0; i < 3; ++i) |
| 211 searchableView.handleFindPreviousShortcut(); |
| 212 searchableView.closeSearch(); |
| 213 dumpSelection(panel.visibleView.textEditor, "After searching"); |
| 214 rollback(); |
| 215 dumpSelection(panel.visibleView.textEditor, "Rolled back"); |
| 216 rollover(); |
| 217 dumpSelection(panel.visibleView.textEditor, "Rolled over"); |
| 218 next(); |
| 219 }, |
| 220 |
| 221 function testShowAnchorLocation(next) |
| 222 { |
| 223 dumpSelection(panel.visibleView.textEditor, "Before switching to oth
er panel"); |
| 224 InspectorTest.waitForScriptSource("workspace-test.js", onScriptSourc
e); |
| 225 function onScriptSource(uiSourceCode) |
| 226 { |
| 227 var linkifier = new WebInspector.Linkifier(); |
| 228 var anchorURI = uiSourceCode.uri(); |
| 229 var jumpAnchor = linkifier.linkifyLocation(anchorURI, 10, 1); |
| 230 WebInspector.showPanel("timeline"); |
| 231 WebInspector.showAnchorLocation(jumpAnchor); |
| 232 InspectorTest.addResult("Selection: " + panel.visibleView.textEd
itor.selection().toString()); |
| 233 dumpSelection(panel.visibleView.textEditor, "Showed anchor in "
+ anchorURI.split("/").pop() + " with line 333 column 3"); |
| 234 rollback(); |
| 235 dumpSelection(panel.visibleView.textEditor, "Rolled back"); |
| 236 rollover(); |
| 237 dumpSelection(panel.visibleView.textEditor, "Rolled over"); |
| 238 next(); |
| 239 } |
| 240 }, |
| 241 |
| 242 function testShowUISourceCode(next) |
| 243 { |
| 244 dumpSelection(panel.visibleView.textEditor, "Initial state"); |
| 245 |
| 246 InspectorTest.waitForScriptSource("blink-fs.js", onScriptSourceLoade
d); |
| 247 function onScriptSourceLoaded(uiSourceCode) |
| 248 { |
| 249 var jumps = [20, 10, 30]; |
| 250 for (var i = 0; i < jumps.length; ++i) { |
| 251 panel.showUISourceCode(uiSourceCode, jumps[i]); |
| 252 dumpSelection(panel.visibleView.textEditor, "jump to line "
+ jumps[i]); |
| 253 } |
| 254 panel.highlightPosition(40, 10); |
| 255 dumpSelection(panel.visibleView.textEditor, "highlight line 40")
; |
| 256 for (var i = 0; i < jumps.length + 1; ++i) { |
| 257 rollback(); |
| 258 dumpSelection(panel.visibleView.textEditor, "rollback"); |
| 259 } |
| 260 next(); |
| 261 } |
| 262 } |
| 263 ]); |
| 264 }; |
| 265 </script> |
| 266 </head> |
| 267 <body onload="runTest()"> |
| 268 <p>Tests that jumping to previous location works as intended.</p> |
| 269 </body> |
| 270 </html> |
OLD | NEW |