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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, callback) |
61 { | 61 { |
62 callback = callback || new Function(); | 62 callback = callback || 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 for (var charIndex = 0; charIndex < typeText.length; charIndex++) { |
65 // As soon as the last key event was processed, the whole text was proce ssed. | 66 var character = typeText[charIndex]; |
lushnikov
2016/07/21 16:54:25
how's this code different from the old one? I don'
einbinder
2016/07/21 20:35:50
Oh, I guess it turned out the same
| |
66 var iterationCallback = charIndex + 1 === typeText.length ? callback : n oop; | 67 var command; |
67 switch (typeText[charIndex]) { | 68 switch (character) { |
68 case "\n": | 69 case "\n": |
69 InspectorTest.fakeKeyEvent(editor, "Enter", null, iterationCallback) ; | 70 command = "Enter"; |
70 break; | 71 break; |
71 case "L": | 72 case "L": |
72 InspectorTest.fakeKeyEvent(editor, "ArrowLeft", null, iterationCallb ack); | 73 command = "ArrowLeft"; |
73 break; | 74 break; |
74 case "R": | 75 case "R": |
75 InspectorTest.fakeKeyEvent(editor, "ArrowRight", null, iterationCall back); | 76 command = "ArrowRight"; |
76 break; | 77 break; |
77 case "U": | 78 case "U": |
78 InspectorTest.fakeKeyEvent(editor, "ArrowUp", null, iterationCallbac k); | 79 command = "ArrowUp"; |
79 break; | 80 break; |
80 case "D": | 81 case "D": |
81 InspectorTest.fakeKeyEvent(editor, "ArrowDown", null, iterationCallb ack); | 82 command = "ArrowDown"; |
82 break; | 83 break; |
83 default: | 84 default: |
84 InspectorTest.fakeKeyEvent(editor, typeText[charIndex], null, iterat ionCallback); | 85 command = character; |
85 } | 86 } |
87 InspectorTest.fakeKeyEvent(editor, command, null, charIndex + 1 === type Text.length ? callback : noop); | |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
89 var eventCodes = { | 91 var eventCodes = { |
90 Enter: 13, | 92 Enter: 13, |
91 Home: 36, | 93 Home: 36, |
92 ArrowLeft: 37, | 94 ArrowLeft: 37, |
93 ArrowUp: 38, | 95 ArrowUp: 38, |
94 ArrowRight: 39, | 96 ArrowRight: 39, |
95 ArrowDown: 40 | 97 ArrowDown: 40 |
96 }; | 98 }; |
97 | 99 |
98 function createCodeMirrorFakeEvent(eventType, code, charCode, modifiers) | 100 function createCodeMirrorFakeEvent(editor, eventType, code, charCode, modifiers) |
99 { | 101 { |
100 function eventPreventDefault() | 102 function eventPreventDefault() |
101 { | 103 { |
102 this._handled = true; | 104 this._handled = true; |
103 } | 105 } |
104 var event = { | 106 var event = { |
105 _handled: false, | 107 _handled: false, |
106 type: eventType, | 108 type: eventType, |
107 keyCode: code, | 109 keyCode: code, |
108 charCode: charCode, | 110 charCode: charCode, |
109 preventDefault: eventPreventDefault, | 111 preventDefault: eventPreventDefault, |
110 stopPropagation: function(){}, | 112 stopPropagation: function(){}, |
113 target: editor._codeMirror.display.input.textarea | |
111 }; | 114 }; |
112 if (modifiers) { | 115 if (modifiers) { |
113 for (var i = 0; i < modifiers.length; ++i) | 116 for (var i = 0; i < modifiers.length; ++i) |
114 event[modifiers[i]] = true; | 117 event[modifiers[i]] = true; |
115 } | 118 } |
116 return event; | 119 return event; |
117 } | 120 } |
118 | 121 |
119 function fakeCodeMirrorKeyEvent(editor, eventType, code, charCode, modifiers) | 122 function fakeCodeMirrorKeyEvent(editor, eventType, code, charCode, modifiers) |
120 { | 123 { |
121 var event = createCodeMirrorFakeEvent(eventType, code, charCode, modifiers); | 124 var event = createCodeMirrorFakeEvent(editor, eventType, code, charCode, mod ifiers); |
122 switch(eventType) { | 125 switch(eventType) { |
123 case "keydown": | 126 case "keydown": |
124 editor._codeMirror.triggerOnKeyDown(event); | 127 editor._codeMirror.triggerOnKeyDown(event); |
125 break; | 128 break; |
126 case "keypress": | 129 case "keypress": |
127 editor._codeMirror.triggerOnKeyPress(event); | 130 editor._codeMirror.triggerOnKeyPress(event); |
128 break; | 131 break; |
129 case "keyup": | 132 case "keyup": |
130 editor._codeMirror.triggerOnKeyUp(event); | 133 editor._codeMirror.triggerOnKeyUp(event); |
131 break; | 134 break; |
132 default: | 135 default: |
133 throw new Error("Unknown KeyEvent type"); | 136 throw new Error("Unknown KeyEvent type"); |
134 } | 137 } |
135 return event._handled; | 138 return event._handled; |
136 } | 139 } |
137 | 140 |
138 function fakeCodeMirrorInputEvent(editor, character) | 141 function fakeCodeMirrorInputEvent(editor, character) |
139 { | 142 { |
140 if (typeof character === "string") | 143 if (typeof character === "string") |
141 editor._codeMirror.display.input.value += character; | 144 editor._codeMirror.display.input.textarea.value += character; |
142 } | 145 } |
143 | 146 |
144 InspectorTest.fakeKeyEvent = function(editor, originalCode, modifiers, callback) | 147 InspectorTest.fakeKeyEvent = function(editor, originalCode, modifiers, callback) |
145 { | 148 { |
146 modifiers = modifiers || []; | 149 modifiers = modifiers || []; |
147 var code; | 150 var code; |
148 var charCode; | 151 var charCode; |
149 if (originalCode === "'") { | 152 if (originalCode === "'") { |
150 code = 222; | 153 code = 222; |
151 charCode = 0; | 154 charCode = 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 var keyName = sortedKeys[i]; | 202 var keyName = sortedKeys[i]; |
200 if (!keyName.length) | 203 if (!keyName.length) |
201 keyName = "<Empty string>"; | 204 keyName = "<Empty string>"; |
202 else | 205 else |
203 keyName = "'" + keyName + "'"; | 206 keyName = "'" + keyName + "'"; |
204 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]); | 207 InspectorTest.addResult(keyName + ": " + listHashMap[sortedKeys[i]]); |
205 } | 208 } |
206 } | 209 } |
207 | 210 |
208 } | 211 } |
OLD | NEW |