3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../http/tests/inspector/console-test.js"></script>
5 <script src=
"../http/tests/inspector/workspace-test.js"></script>
6 <script src=
"../http/tests/inspector/debugger-test.js"></script>
7 <script src=
"resources/example-fileset-for-test.js"></script>
8 <script src=
"editor/editor-test.js"></script>
12 var panel
= WebInspector
.panels
.sources
;
13 var sourcesView
= panel
._sourcesView
;
14 var historyManager
= sourcesView
._historyManager
;
15 var editorContainer
= sourcesView
._editorContainer
;
19 historyManager
.rollback();
24 historyManager
.rollover();
27 function dumpSelection(editor
, label
)
29 var selection
= editor
.selection();
30 var label
= "<" + label
+ ">";
31 var fileName
= "[" + editor
._url
.split("/").pop() + "]";
32 var selectionText
= "";
33 if (selection
.isEmpty())
34 selectionText
= "line: " + selection
.startLine
+ " column: " + selection
.startColumn
;
36 selectionText
= "(NOT EMPTY): " + selection
.toString();
37 InspectorTest
.addResult(label
+ " " + selectionText
+ " " + fileName
);
40 function eventSenderClickAtEditor(editor
, lineNumber
, columnNumber
)
42 editor
.scrollToLine(lineNumber
);
43 var coordinates
= editor
.cursorPositionToCoordinates(lineNumber
, columnNumber
);
44 eventSender
.mouseMoveTo(coordinates
.x
, coordinates
.y
);
45 eventSender
.mouseDown();
46 eventSender
.mouseUp();
47 dumpSelection(editor
, "Mouse click (" + lineNumber
+ ", " + columnNumber
+ ")");
50 function clickAndDump(editor
, lines
, columns
)
52 for (var i
= 0; i
< lines
.length
; ++i
) {
53 var lineNumber
= lines
[i
];
54 var columnNumber
= columns
[i
];
55 var originSelection
= editor
.selection();
56 editor
.setSelection(WebInspector
.TextRange
.createFromLocation(lineNumber
, columnNumber
));
57 editor
._delegate
.onJumpToPosition(originSelection
, editor
.selection());
58 dumpSelection(editor
, "Mouse click (" + lineNumber
+ ", " + columnNumber
+ ")");
62 InspectorTest
.runTestSuite([
63 function testSimpleMovements(next
)
65 InspectorTest
.showScriptSource("example-fileset-for-test.js", onContentLoaded
);
67 function onContentLoaded()
69 var editor
= panel
.visibleView
.textEditor
;
70 dumpSelection(editor
, "Initial position");
71 eventSenderClickAtEditor(editor
, 4, 7, true);
73 InspectorTest
.typeIn(editor
, "\nSome more text here", step2
);
77 var editor
= panel
.visibleView
.textEditor
;
78 dumpSelection(editor
, "Typed in some text");
81 dumpSelection(editor
, "Rolled back");
82 InspectorTest
.typeIn(editor
, "\nSome more text here as well\n", step3
);
86 var editor
= panel
.visibleView
.textEditor
;
87 dumpSelection(editor
, "Typed in some text");
90 dumpSelection(editor
, "Rolled over");
95 function testSequentialJumps(next
)
97 var editor
= panel
.visibleView
.textEditor
;
98 // Hide inspector view to significantly speed up following tests from testsuite.
99 InspectorTest
.hideInspectorView();
101 clickAndDump(editor
, [10, 11, 12, 13], [3, 4, 5, 6]);
103 for (var i
= 0; i
< jumpsToDo
; ++i
) {
105 dumpSelection(editor
, "Rolled back");
107 for (var i
= 0; i
< jumpsToDo
; ++i
) {
109 dumpSelection(editor
, "Rolled over");
114 function testDeletePreviousJumpLocations(next
)
116 var editor
= panel
.visibleView
.textEditor
;
117 editor
.editRange(new WebInspector
.TextRange(9, 0, 15, 0), "");
118 dumpSelection(editor
, "Removed lines from 9 to 15");
120 dumpSelection(editor
, "Rolled back");
122 dumpSelection(editor
, "Rolled over");
126 function testDeleteNextJumpLocations(next
)
128 var editor
= panel
.visibleView
.textEditor
;
130 clickAndDump(editor
, [10, 11, 12, 13], [3, 4, 5, 6]);
132 for (var i
= 0; i
< jumpsToDo
; ++i
)
134 dumpSelection(editor
, "Rolled back 4 times");
135 editor
.editRange(new WebInspector
.TextRange(9, 0, 11, 0), "");
136 dumpSelection(editor
, "Removed lines from 9 to 11");
138 dumpSelection(editor
, "Rolled over");
142 function testCrossFileJump(next
)
144 InspectorTest
.showScriptSource("workspace-test.js", onContentLoaded
);
145 function onContentLoaded()
147 var editor
= panel
.visibleView
.textEditor
;
148 dumpSelection(editor
, "Opened workspace-test.js");
149 clickAndDump(editor
, [10, 11], [1, 1]);
150 for (var i
= 0; i
< 4; ++i
) {
152 dumpSelection(panel
.visibleView
.textEditor
, "Rolled back");
154 for (var i
= 0; i
< 4; ++i
) {
156 dumpSelection(panel
.visibleView
.textEditor
, "Rolled over");
162 function testCloseCrossFile(next
)
164 var selectedTab
= editorContainer
._tabbedPane
.selectedTabId
;
165 editorContainer
._tabbedPane
.closeTab(selectedTab
);
166 dumpSelection(panel
.visibleView
.textEditor
, "Close active tab");
167 for (var i
= 0; i
< 1; ++i
) {
169 dumpSelection(panel
.visibleView
.textEditor
, "Rolled back");
171 for (var i
= 0; i
< 3; ++i
) {
173 dumpSelection(panel
.visibleView
.textEditor
, "Rolled over");
178 function testHistoryDepth(next
)
182 const jumpsAmount
= WebInspector
.EditingLocationHistoryManager
.HistoryDepth
;
183 for(var i
= 0; i
< jumpsAmount
; ++i
) {
187 var editor
= panel
.visibleView
.textEditor
;
188 clickAndDump(editor
, lines
, columns
);
189 for (var i
= 0; i
< jumpsAmount
; ++i
) {
191 dumpSelection(editor
, "Rolled back");
196 function testInFileSearch(next
)
198 var searchableView
= panel
.searchableView();
200 dumpSelection(panel
.visibleView
.textEditor
, "Before searching");
202 searchableView
.showSearchField();
203 searchableView
._searchInputElement
.value
= "generate_";
204 searchableView
._performSearch(true, true);
205 for (var i
= 0; i
< 3; ++i
)
206 searchableView
.handleFindNextShortcut();
207 searchableView
.handleCancelSearchShortcut();
209 dumpSelection(panel
.visibleView
.textEditor
, "After searching");
211 dumpSelection(panel
.visibleView
.textEditor
, "Rolled back");
213 dumpSelection(panel
.visibleView
.textEditor
, "Rolled over");
217 function testShowAnchorLocation(next
)
219 dumpSelection(panel
.visibleView
.textEditor
, "Before switching to other panel");
220 InspectorTest
.waitForScriptSource("workspace-test.js", onScriptSource
);
221 function onScriptSource(uiSourceCode
)
223 var linkifier
= new WebInspector
.Linkifier();
224 var anchorURI
= WebInspector
.networkMapping
.networkURL(uiSourceCode
);
225 var anchor
= linkifier
.linkifyScriptLocation(WebInspector
.targetManager
.mainTarget(), null, anchorURI
, 10, 1);
226 WebInspector
.Revealer
.revealPromise(anchor
[WebInspector
.Linkifier
._uiLocationSymbol
]).then(function() {
227 InspectorTest
.addResult("Selection: " + panel
.visibleView
.textEditor
.selection().toString());
228 dumpSelection(panel
.visibleView
.textEditor
, "Showed anchor in " + anchorURI
.split("/").pop() + " with line 333 column 3");
230 dumpSelection(panel
.visibleView
.textEditor
, "Rolled back");
232 dumpSelection(panel
.visibleView
.textEditor
, "Rolled over");
238 function testShowUISourceCode(next
)
240 dumpSelection(panel
.visibleView
.textEditor
, "Initial state");
242 InspectorTest
.waitForScriptSource("example-fileset-for-test.js", onScriptSourceLoaded
);
243 function onScriptSourceLoaded(uiSourceCode
)
245 var jumps
= [20, 10, 30];
246 for (var i
= 0; i
< jumps
.length
; ++i
) {
247 panel
.showUISourceCode(uiSourceCode
, jumps
[i
]);
248 dumpSelection(panel
.visibleView
.textEditor
, "jump to line " + jumps
[i
]);
250 panel
.showUISourceCode(uiSourceCode
, 40, 10);
251 dumpSelection(panel
.visibleView
.textEditor
, "highlight line 40");
252 for (var i
= 0; i
< jumps
.length
+ 1; ++i
) {
254 dumpSelection(panel
.visibleView
.textEditor
, "rollback");
263 <body onload=
"runTest()">
264 <p>Tests that jumping to previous location works as intended.
</p>