2518ce1c5c1175b6f282a7ddfc1ff7c85c58758e
[WebKit-https.git] / LayoutTests / inspector / editor / editor-test.js
1 function initialize_EditorTests()
2 {
3
4 InspectorTest.createTestEditor = function(lineCount, 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     var textModel = textEditor._textModel;
11     var lines = [];
12     for (var i = 0; i < lineCount; ++i)
13         lines.push(i);
14     textModel.setText(lines.join("\n"));
15     return textEditor;
16 };
17
18 InspectorTest.dumpEditorChunks = function(textEditor)
19 {
20     InspectorTest.addResult("Chunk model");
21     var chunks = textEditor._mainPanel._textChunks;
22     for (var i = 0; i < chunks.length; ++i)
23         InspectorTest.addResult("Chunk [" + i + "] " + chunks[i].startLine + ":" + chunks[i].endLine + " (" + (chunks[i]._expanded ? "expanded" : "collapsed") + ")");
24 };
25
26 InspectorTest.dumpEditorModel = function(textEditor)
27 {
28     InspectorTest.addResult("Text model");
29     var textModel = textEditor._textModel;
30     for (var i = 0; i < textModel.linesCount; ++i) {
31         var prefix = "[" + i + "]";
32         while (prefix.length < 10)
33             prefix += " ";
34         InspectorTest.addResult(prefix + textModel.line(i));
35     }
36 };
37
38 InspectorTest.dumpEditorDOM = function(textEditor)
39 {
40     InspectorTest.addResult("Editor DOM");
41     var element = textEditor._mainPanel._container;
42     for (var node = element.firstChild; node; node = node.nextSibling) {
43         if (node._chunk)
44             var prefix = "[" + node._chunk.startLine + ":" + node._chunk.endLine + "]";
45         else
46             var prefix = "[" + node.lineNumber + "]";
47         while (prefix.length < 10)
48             prefix += " ";
49         InspectorTest.addResult(prefix + node.outerHTML);
50     }
51 };
52
53 }