OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>InputEvent: execCommand test</title> |
| 5 <script src="../../../resources/testharness.js"></script> |
| 6 <script src="../../../resources/testharnessreport.js"></script> |
| 7 </head> |
| 8 <body> |
| 9 <p id="txt" contenteditable></p> |
| 10 <script> |
| 11 test(function() { |
| 12 var lastBeforeInputType = ''; |
| 13 var lastInputType = ''; |
| 14 var txt = document.getElementById('txt'); |
| 15 txt.addEventListener('beforeinput', function(event) { |
| 16 assert_true(event instanceof InputEvent); |
| 17 assert_false(event.isComposing); |
| 18 lastBeforeInputType = event.inputType; |
| 19 }); |
| 20 txt.addEventListener('input', function(event) { |
| 21 assert_true(event instanceof InputEvent); |
| 22 assert_false(event.isComposing); |
| 23 lastInputType = event.inputType; |
| 24 }); |
| 25 if (!window.eventSender) { |
| 26 document.write('This test requires eventSender'); |
| 27 } else { |
| 28 var kNoInputEventFired = 'noInputEventFired'; |
| 29 function testExecCommandInputType(command, args, inputType) { |
| 30 lastBeforeInputType = kNoInputEventFired; |
| 31 lastInputType = kNoInputEventFired; |
| 32 document.execCommand(command, false, args); |
| 33 assert_equals(lastBeforeInputType, kNoInputEventFired, `execCommand(
${command}, false, ${args}) shouldn't fire beforeinput`); |
| 34 assert_equals(lastInputType, inputType, `execCommand(${command}, fal
se, ${args}) should produce inputType: ${inputType}`); |
| 35 } |
| 36 |
| 37 txt.focus(); |
| 38 // InsertText |
| 39 testExecCommandInputType('insertText', 'a', 'insertText'); |
| 40 testExecCommandInputType('insertText', 'bc', 'insertText'); |
| 41 assert_equals('abc', txt.innerHTML); |
| 42 |
| 43 // Styling |
| 44 var selection = window.getSelection(); |
| 45 selection.collapse(txt, 0); |
| 46 selection.extend(txt, 1); |
| 47 // TODO(chongz): Add |inputType| for 'bold'. |
| 48 testExecCommandInputType('bold', 'bc', ''); |
| 49 assert_equals('<b>abc</b>', txt.innerHTML); |
| 50 |
| 51 // Copy shouldn't fire 'input'. |
| 52 testExecCommandInputType('copy', null, kNoInputEventFired); |
| 53 // Paste should fire 'input'. |
| 54 // TODO(chongz): Add |inputType| for 'paste'. |
| 55 testExecCommandInputType('paste', null, ''); |
| 56 } |
| 57 }, 'Testing input with execCommand'); |
| 58 </script> |
| 59 </body> |
| 60 </html> |
OLD | NEW |