Web Inspector: home button behaviour is wrong in DTE
[WebKit-https.git] / LayoutTests / inspector / editor / editor-test.js
1 function initialize_EditorTests()
2 {
3
4 InspectorTest.createTestEditor = function(clientHeight, chunkSize, textEditorDelegate)
5 {
6     WebInspector.debugDefaultTextEditor = true;
7     var textEditor = new WebInspector.DefaultTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate());
8     textEditor.overrideViewportForTest(0, clientHeight || 100, chunkSize || 10);
9     textEditor.show(WebInspector.inspectorView.element);
10     return textEditor;
11 };
12
13 InspectorTest.fillEditorWithText = function(textEditor, lineCount)
14 {
15     var textModel = textEditor._textModel;
16     var lines = [];
17     for (var i = 0; i < lineCount; ++i)
18         lines.push(i);
19     textModel.setText(lines.join("\n"));
20 }
21
22 InspectorTest.textWithSelection = function(text, selection)
23 {
24     if (!selection)
25         return text;
26
27     function lineWithCursor(line, column, cursorChar)
28     {
29         return line.substring(0, column) + cursorChar + line.substring(column);
30     }
31
32     var lines = text.split("\n");
33     selection = selection.normalize();
34     var endCursorChar = selection.isEmpty() ? "|" : "<";
35     lines[selection.endLine] = lineWithCursor(lines[selection.endLine], selection.endColumn, endCursorChar);
36     if (!selection.isEmpty()) {
37         lines[selection.startLine] = lineWithCursor(lines[selection.startLine], selection.startColumn, ">");
38     }
39     return lines.join("\n");
40 }
41
42 InspectorTest.insertTextLine = function(line)
43 {
44     function enter()
45     {
46         eventSender.keyDown("\n");
47     }
48
49     function innerInsertTextLine()
50     {
51         textInputController.insertText(line);
52     }
53     setTimeout(innerInsertTextLine);
54     setTimeout(enter);
55 }
56
57 InspectorTest.dumpEditorChunks = function(textEditor)
58 {
59     InspectorTest.addResult("Chunk model");
60     var chunks = textEditor._mainPanel._textChunks;
61     for (var i = 0; i < chunks.length; ++i)
62         InspectorTest.addResult("Chunk [" + i + "] " + chunks[i].startLine + ":" + chunks[i].endLine + " (" + (chunks[i]._expanded ? "expanded" : "collapsed") + ")");
63 };
64
65 InspectorTest.dumpEditorModel = function(textEditor)
66 {
67     InspectorTest.addResult("Text model");
68     var textModel = textEditor._textModel;
69     for (var i = 0; i < textModel.linesCount; ++i) {
70         var prefix = "[" + i + "]";
71         while (prefix.length < 10)
72             prefix += " ";
73         InspectorTest.addResult(prefix + textModel.line(i));
74     }
75 };
76
77 InspectorTest.dumpEditorDOM = function(textEditor)
78 {
79     InspectorTest.addResult("Editor DOM");
80     var element = textEditor._mainPanel._container;
81     for (var node = element.firstChild; node; node = node.nextSibling) {
82         if (node._chunk)
83             var prefix = "[" + node._chunk.startLine + ":" + node._chunk.endLine + "]";
84         else
85             var prefix = "[" + node.lineNumber + "]";
86         while (prefix.length < 10)
87             prefix += " ";
88         InspectorTest.addResult(prefix + node.outerHTML);
89     }
90 };
91
92 InspectorTest.dumpEditorHTML = function(textEditor, mainPanelOnly)
93 {
94     var element = mainPanelOnly ? textEditor._mainPanel.element : textEditor.element;
95     var dumpedHTML = element.innerHTML.replace(/<div/g, "\n<div");
96     var dumpedHTML = dumpedHTML.replace(/height: [0-9]+/g, "height: <number>");
97     InspectorTest.addResult(dumpedHTML);
98 };
99
100 InspectorTest.getLineElement = function(textEditor, lineNumber)
101 {
102     return textEditor._mainPanel.chunkForLine(lineNumber).expandedLineRow(lineNumber);
103 };
104
105 }