Web Inspector: create helper InspectorTest method to dump editor HTML
[WebKit-https.git] / LayoutTests / inspector / editor / editor-test.js
1 function initialize_EditorTests()
2 {
3
4 InspectorTest.createTestEditor = function(clientHeight, chunkSize)
5 {
6     WebInspector.debugDefaultTextEditor = true;
7     var textEditor = new WebInspector.DefaultTextEditor("", 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.insertTextLine = function(line)
23 {
24     function enter()
25     {
26         eventSender.keyDown("\n");
27     }
28
29     function innerInsertTextLine()
30     {
31         textInputController.insertText(line);
32     }
33     setTimeout(innerInsertTextLine);
34     setTimeout(enter);
35 }
36
37 InspectorTest.dumpEditorChunks = function(textEditor)
38 {
39     InspectorTest.addResult("Chunk model");
40     var chunks = textEditor._mainPanel._textChunks;
41     for (var i = 0; i < chunks.length; ++i)
42         InspectorTest.addResult("Chunk [" + i + "] " + chunks[i].startLine + ":" + chunks[i].endLine + " (" + (chunks[i]._expanded ? "expanded" : "collapsed") + ")");
43 };
44
45 InspectorTest.dumpEditorModel = function(textEditor)
46 {
47     InspectorTest.addResult("Text model");
48     var textModel = textEditor._textModel;
49     for (var i = 0; i < textModel.linesCount; ++i) {
50         var prefix = "[" + i + "]";
51         while (prefix.length < 10)
52             prefix += " ";
53         InspectorTest.addResult(prefix + textModel.line(i));
54     }
55 };
56
57 InspectorTest.dumpEditorDOM = function(textEditor)
58 {
59     InspectorTest.addResult("Editor DOM");
60     var element = textEditor._mainPanel._container;
61     for (var node = element.firstChild; node; node = node.nextSibling) {
62         if (node._chunk)
63             var prefix = "[" + node._chunk.startLine + ":" + node._chunk.endLine + "]";
64         else
65             var prefix = "[" + node.lineNumber + "]";
66         while (prefix.length < 10)
67             prefix += " ";
68         InspectorTest.addResult(prefix + node.outerHTML);
69     }
70 };
71
72 InspectorTest.dumpEditorHTML = function(textEditor, mainPanelOnly)
73 {
74     var element = mainPanelOnly ? textEditor._mainPanel.element : textEditor.element;
75     var dumpedHTML = element.innerHTML.replace(/<div/g, "\n<div");
76     InspectorTest.addResult(dumpedHTML);
77 };
78
79 InspectorTest.getLineElement = function(textEditor, lineNumber)
80 {
81     return textEditor._mainPanel.chunkForLine(lineNumber).expandedLineRow(lineNumber);
82 };
83
84 }