OLD | NEW |
---|---|
1 function initialize_EditorTests() | 1 function initialize_EditorTests() |
2 { | 2 { |
3 | 3 |
4 InspectorTest.createTestEditor = function(clientHeight, textEditorDelegate) | 4 InspectorTest.createTestEditor = function(clientHeight, textEditorDelegate) |
5 { | 5 { |
6 var textEditor = new WebInspector.CodeMirrorTextEditor("", textEditorDelegat e || new WebInspector.TextEditorDelegate()); | 6 var textEditor = new WebInspector.CodeMirrorTextEditor("", textEditorDelegat e || new WebInspector.TextEditorDelegate()); |
7 clientHeight = clientHeight || 100; | 7 clientHeight = clientHeight || 100; |
8 textEditor.element.style.height = clientHeight + "px"; | 8 textEditor.element.style.height = clientHeight + "px"; |
9 textEditor.element.style.flex = "none"; | 9 textEditor.element.style.flex = "none"; |
10 textEditor.show(WebInspector.inspectorView.element); | 10 textEditor.show(WebInspector.inspectorView.element); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 var selection = selections[i]; | 50 var selection = selections[i]; |
51 if (typeof selection.column === "number") { | 51 if (typeof selection.column === "number") { |
52 selection.from = selection.column; | 52 selection.from = selection.column; |
53 selection.to = selection.column; | 53 selection.to = selection.column; |
54 } | 54 } |
55 coords.push(new WebInspector.TextRange(selection.line, selection.from, s election.line, selection.to)); | 55 coords.push(new WebInspector.TextRange(selection.line, selection.from, s election.line, selection.to)); |
56 } | 56 } |
57 editor.setSelections(coords); | 57 editor.setSelections(coords); |
58 } | 58 } |
59 | 59 |
60 InspectorTest.typeIn = function(editor, typeText, callback) | 60 InspectorTest.typeIn = function(editor, typeText, finalCallback) |
61 { | 61 { |
62 callback = callback || new Function(); | 62 finalCallback = finalCallback || new Function(); |
63 var charIndex = 0; | |
63 var noop = new Function(); | 64 var noop = new Function(); |
64 for(var charIndex = 0; charIndex < typeText.length; ++charIndex) { | 65 iterationCallback(); |
65 // As soon as the last key event was processed, the whole text was proce ssed. | 66 |
66 var iterationCallback = charIndex + 1 === typeText.length ? callback : n oop; | 67 function iterationCallback() |
67 switch (typeText[charIndex]) { | 68 { |
69 var character = typeText[charIndex]; | |
lushnikov
2016/07/20 01:40:13
typeText[charIndex++]
einbinder
2016/07/21 20:35:50
Done.
| |
70 var command; | |
71 var callback = noop; | |
72 switch (character) { | |
68 case "\n": | 73 case "\n": |
69 InspectorTest.fakeKeyEvent(editor, "Enter", null, iterationCallback) ; | 74 command = "Enter"; |
75 callback = iterationCallback; | |
lushnikov
2016/07/20 01:40:13
should we do this?
einbinder
2016/07/21 20:35:50
nope
| |
70 break; | 76 break; |
71 case "L": | 77 case "L": |
72 InspectorTest.fakeKeyEvent(editor, "ArrowLeft", null, iterationCallb ack); | 78 command = "ArrowLeft"; |
73 break; | 79 break; |
74 case "R": | 80 case "R": |
75 InspectorTest.fakeKeyEvent(editor, "ArrowRight", null, iterationCall back); | 81 command = "ArrowRight"; |
76 break; | 82 break; |
77 case "U": | 83 case "U": |
78 InspectorTest.fakeKeyEvent(editor, "ArrowUp", null, iterationCallbac k); | 84 command = "ArrowUp"; |
79 break; | 85 break; |
80 case "D": | 86 case "D": |
81 InspectorTest.fakeKeyEvent(editor, "ArrowDown", null, iterationCallb ack); | 87 command = "ArrowDown"; |
82 break; | 88 break; |
83 default: | 89 default: |
84 InspectorTest.fakeKeyEvent(editor, typeText[charIndex], null, iterat ionCallback); | 90 command = character; |
91 } | |
92 charIndex++; | |
93 if (typeText.length === charIndex) | |
94 callback = finalCallback; | |
95 else if (typeText[charIndex] === "\n") | |
96 callback = iterationCallback; | |
97 InspectorTest.fakeKeyEvent(editor, command, null, callback); | |
98 if (callback === noop) { | |
lushnikov
2016/07/20 01:40:13
nit: braces
einbinder
2016/07/21 20:35:50
Done.
| |
99 iterationCallback(); | |
85 } | 100 } |
86 } | 101 } |
87 } | 102 } |
88 | 103 |
89 var eventCodes = { | 104 var eventCodes = { |
90 Enter: 13, | 105 Enter: 13, |
91 Home: 36, | 106 Home: 36, |
92 ArrowLeft: 37, | 107 ArrowLeft: 37, |
93 ArrowUp: 38, | 108 ArrowUp: 38, |
94 ArrowRight: 39, | 109 ArrowRight: 39, |
95 ArrowDown: 40 | 110 ArrowDown: 40 |
96 }; | 111 }; |
97 | 112 |
98 function createCodeMirrorFakeEvent(eventType, code, charCode, modifiers) | 113 function createCodeMirrorFakeEvent(editor, eventType, code, charCode, modifiers) |
99 { | 114 { |
100 function eventPreventDefault() | 115 function eventPreventDefault() |
101 { | 116 { |
102 this._handled = true; | 117 this._handled = true; |
103 } | 118 } |
104 var event = { | 119 var event = { |
105 _handled: false, | 120 _handled: false, |
106 type: eventType, | 121 type: eventType, |
107 keyCode: code, | 122 keyCode: code, |
108 charCode: charCode, | 123 charCode: charCode, |
109 preventDefault: eventPreventDefault, | 124 preventDefault: eventPreventDefault, |
110 stopPropagation: function(){}, | 125 stopPropagation: function(){}, |
126 target: editor._codeMirror.display.input.textarea | |
111 }; | 127 }; |
112 if (modifiers) { | 128 if (modifiers) { |
113 for (var i = 0; i < modifiers.length; ++i) | 129 for (var i = 0; i < modifiers.length; ++i) |
114 event[modifiers[i]] = true; | 130 event[modifiers[i]] = true; |
115 } | 131 } |
116 return event; | 132 return event; |
117 } | 133 } |
118 | 134 |
119 function fakeCodeMirrorKeyEvent(editor, eventType, code, charCode, modifiers) | 135 function fakeCodeMirrorKeyEvent(editor, eventType, code, charCode, modifiers) |
120 { | 136 { |
121 var event = createCodeMirrorFakeEvent(eventType, code, charCode, modifiers); | 137 var event = createCodeMirrorFakeEvent(editor, eventType, code, charCode, mod ifiers); |
122 switch(eventType) { | 138 switch(eventType) { |
123 case "keydown": | 139 case "keydown": |
124 editor._codeMirror.triggerOnKeyDown(event); | 140 editor._codeMirror.triggerOnKeyDown(event); |
125 break; | 141 break; |
126 case "keypress": | 142 case "keypress": |
127 editor._codeMirror.triggerOnKeyPress(event); | 143 editor._codeMirror.triggerOnKeyPress(event); |
128 break; | 144 break; |
129 case "keyup": | 145 case "keyup": |
130 editor._codeMirror.triggerOnKeyUp(event); | 146 editor._codeMirror.triggerOnKeyUp(event); |
131 break; | 147 break; |
132 default: | 148 default: |
133 throw new Error("Unknown KeyEvent type"); | 149 throw new Error("Unknown KeyEvent type"); |
134 } | 150 } |
135 return event._handled; | 151 return event._handled; |
136 } | 152 } |
137 | 153 |
138 function fakeCodeMirrorInputEvent(editor, character) | 154 function fakeCodeMirrorInputEvent(editor, character) |
139 { | 155 { |
140 if (typeof character === "string") | 156 if (typeof character === "string") |
141 editor._codeMirror.display.input.value += character; | 157 editor._codeMirror.display.input.textarea.value += character; |
142 } | 158 } |
143 | 159 |
144 InspectorTest.fakeKeyEvent = function(editor, originalCode, modifiers, callback) | 160 InspectorTest.fakeKeyEvent = function(editor, originalCode, modifiers, callback) |
145 { | 161 { |
146 modifiers = modifiers || []; | 162 modifiers = modifiers || []; |
147 var code; | 163 var code; |
148 var charCode; | 164 var charCode; |
149 if (originalCode === "'") { | 165 if (originalCode === "'") { |
150 code = 222; | 166 code = 222; |
151 charCode = 0; | 167 charCode = 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 var keyName = sortedKeys[i]; | 215 var keyName = sortedKeys[i]; |
200 if (!keyName.length) | 216 if (!keyName.length) |
201 keyName = "<Empty string>"; | 217 keyName = "<Empty string>"; |
202 else | 218 else |
203 keyName = "'" + keyName + "'"; | 219 keyName = "'" + keyName + "'"; |
204 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]); | 220 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]); |
205 } | 221 } |
206 } | 222 } |
207 | 223 |
208 } | 224 } |
OLD | NEW |