- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / editor / editor-test.js
1 function initialize_EditorTests()
2 {
3
4 InspectorTest.createTestEditor = function(clientHeight, textEditorDelegate)
5 {
6     loadScript("CodeMirrorTextEditor.js");
7     var textEditor = new WebInspector.CodeMirrorTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate());
8     if (clientHeight)
9         textEditor.element.style.height = clientHeight + "px";
10     textEditor.show(WebInspector.inspectorView.element);
11     return textEditor;
12 };
13
14 InspectorTest.fillEditorWithText = function(textEditor, lineCount)
15 {
16     var textModel = textEditor._textModel;
17     var lines = [];
18     for (var i = 0; i < lineCount; ++i)
19         lines.push(i);
20     textModel.setText(lines.join("\n"));
21 }
22
23 InspectorTest.textWithSelection = function(text, selection)
24 {
25     if (!selection)
26         return text;
27
28     function lineWithCursor(line, column, cursorChar)
29     {
30         return line.substring(0, column) + cursorChar + line.substring(column);
31     }
32
33     var lines = text.split("\n");
34     selection = selection.normalize();
35     var endCursorChar = selection.isEmpty() ? "|" : "<";
36     lines[selection.endLine] = lineWithCursor(lines[selection.endLine], selection.endColumn, endCursorChar);
37     if (!selection.isEmpty()) {
38         lines[selection.startLine] = lineWithCursor(lines[selection.startLine], selection.startColumn, ">");
39     }
40     return lines.join("\n");
41 }
42
43 InspectorTest.dumpTextWithSelection = function(textEditor, dumpWhiteSpaces)
44 {
45     var text = InspectorTest.textWithSelection(textEditor.text(), textEditor.selection());
46     if (dumpWhiteSpaces)
47         text = text.replace(/ /g, ".");
48     InspectorTest.addResult(text);
49 }
50
51 InspectorTest.typeIn = function(typeText)
52 {
53     for(var charIndex = 0; charIndex < typeText.length; ++charIndex) {
54         switch (typeText[charIndex]) {
55         case "L":
56             eventSender.keyDown("leftArrow");
57             break;
58         case "R":
59             eventSender.keyDown("rightArrow");
60             break;
61         case "U":
62             eventSender.keyDown("upArrow");
63             break;
64         case "D":
65             eventSender.keyDown("downArrow");
66             break;
67         default:
68             eventSender.keyDown(typeText[charIndex]);
69         }
70     }
71 }
72
73 }