OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>InputEvent: beforeinput inputType</title> | 4 <title>InputEvent: beforeinput inputType</title> |
5 <script src="../../../resources/testharness.js"></script> | 5 <script src="../../../resources/testharness.js"></script> |
6 <script src="../../../resources/testharnessreport.js"></script> | 6 <script src="../../../resources/testharnessreport.js"></script> |
7 </head> | 7 </head> |
8 <body> | 8 <body> |
9 <input type="text" id="txt"> | 9 <input type="text" id="txt"> |
10 <script> | 10 <script> |
11 test(function() { | 11 test(function() { |
12 var lastBeforeInputType = ''; | 12 var lastBeforeInputType = ''; |
13 var lastInputType = ''; | 13 var lastInputType = ''; |
14 var txt = document.getElementById('txt'); | 14 var txt = document.getElementById('txt'); |
15 txt.addEventListener('beforeinput', function(event) { | 15 txt.addEventListener('beforeinput', function(event) { |
16 assert_true(event instanceof InputEvent); | 16 assert_true(event instanceof InputEvent); |
17 assert_false(event.isComposing); | 17 assert_false(event.isComposing); |
18 lastBeforeInputType = event.inputType; | 18 lastBeforeInputType = event.inputType; |
19 }); | 19 }); |
20 txt.addEventListener('input', function(event) { | 20 txt.addEventListener('input', function(event) { |
21 assert_true(event instanceof InputEvent); | 21 assert_true(event instanceof InputEvent); |
22 assert_false(event.isComposing); | 22 assert_false(event.isComposing); |
23 lastInputType = event.inputType; | 23 lastInputType = event.inputType; |
24 }); | 24 }); |
25 if (!window.eventSender) { | 25 if (!window.eventSender) { |
26 document.write('This test requires eventSender'); | 26 document.write('This test requires eventSender'); |
27 } else { | 27 } else { |
28 var kNoInputEventFired = 'noInputEventFired'; | 28 const NO_INPUT_EVENT_FIRED = 'NO_INPUT_EVENT_FIRED'; |
29 function testKeyDownInputType(key, modifiers, inputType) { | 29 function testKeyDownInputType(key, modifiers, beforeInputType, inputType
) { |
30 lastBeforeInputType = kNoInputEventFired; | 30 inputType = inputType || beforeInputType; |
31 lastInputType = kNoInputEventFired; | 31 lastBeforeInputType = NO_INPUT_EVENT_FIRED; |
| 32 lastInputType = NO_INPUT_EVENT_FIRED; |
32 eventSender.keyDown(key, modifiers); | 33 eventSender.keyDown(key, modifiers); |
33 assert_equals(lastBeforeInputType, inputType, `${modifiers.toString(
)}+${key} should produce beforeInputType: ${inputType}`); | 34 assert_equals(lastBeforeInputType, beforeInputType, `${modifiers.toS
tring()}+${key} should produce beforeInputType: ${inputType}`); |
34 assert_equals(lastInputType, inputType, `${modifiers.toString()}+${k
ey} should produce inputType: ${inputType}`); | 35 assert_equals(lastInputType, inputType, `${modifiers.toString()}+${k
ey} should produce inputType: ${inputType}`); |
35 } | 36 } |
36 | 37 |
37 txt.focus(); | 38 txt.focus(); |
38 // Typing | 39 // Typing |
39 testKeyDownInputType('a', [], 'insertText'); | 40 testKeyDownInputType('a', [], 'insertText'); |
40 testKeyDownInputType('6', [], 'insertText'); | 41 testKeyDownInputType('6', [], 'insertText'); |
41 testKeyDownInputType('Backspace', [], 'deleteContent'); | 42 testKeyDownInputType('Backspace', [], 'deleteContentBackward'); |
42 testKeyDownInputType('l', ['shiftKey'], 'insertText'); | 43 testKeyDownInputType('l', ['shiftKey'], 'insertText'); |
43 testKeyDownInputType('w', ['shiftKey'], 'insertText'); | 44 testKeyDownInputType('w', ['shiftKey'], 'insertText'); |
| 45 // TODO(chongz): Add tests for Enter key on <textarea> and ContentEditab
le. |
| 46 testKeyDownInputType('Enter', [], 'insertLineBreak', NO_INPUT_EVENT_FIRE
D); |
| 47 testKeyDownInputType('Enter', ['shiftKey'], 'insertLineBreak', NO_INPUT_
EVENT_FIRED); |
44 | 48 |
45 // Keyboard commands | 49 // Keyboard commands |
46 var isMacOS = (navigator.userAgent.indexOf('Mac OS X') != -1); | 50 var isMacOS = (navigator.userAgent.indexOf('Mac OS X') != -1); |
47 if (!isMacOS) { | 51 if (!isMacOS) { |
48 // MacOS's eventSender does not work on hot keys other than arrows. | 52 // MacOS's eventSender does not work on hot keys other than arrows. |
49 testKeyDownInputType('z', ['ctrlKey'], 'undo'); | 53 testKeyDownInputType('z', ['ctrlKey'], 'undo'); |
50 testKeyDownInputType('z', ['ctrlKey', 'shiftKey'], 'redo'); | 54 testKeyDownInputType('z', ['ctrlKey', 'shiftKey'], 'redo'); |
51 } | 55 } |
52 // Move command should not generate input events. | 56 // Move command should not generate input events. |
53 testKeyDownInputType('ArrowLeft', [], kNoInputEventFired); | 57 testKeyDownInputType('ArrowLeft', [], NO_INPUT_EVENT_FIRED); |
54 testKeyDownInputType('ArrowLeft', ['shiftKey'], kNoInputEventFired); | 58 testKeyDownInputType('ArrowLeft', ['shiftKey'], NO_INPUT_EVENT_FIRED); |
55 testKeyDownInputType('Home', [], kNoInputEventFired); | 59 testKeyDownInputType('Home', [], NO_INPUT_EVENT_FIRED); |
56 } | 60 } |
57 }, 'Testing beforeinput inputType'); | 61 }, 'Testing beforeinput inputType'); |
58 </script> | 62 </script> |
59 </body> | 63 </body> |
60 </html> | 64 </html> |
OLD | NEW |