OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>InputEvent: beforeinput shouldn't crash in removed iframe</title> |
| 5 <script src="../../../resources/testharness.js"></script> |
| 6 <script src="../../../resources/testharnessreport.js"></script> |
| 7 </head> |
| 8 <body> |
| 9 <script> |
| 10 test(function() { |
| 11 assert_not_equals(window.eventSender, undefined, 'This test requires eventSe
nder.'); |
| 12 assert_not_equals(window.testRunner, undefined, 'This test requires testRunn
er.'); |
| 13 |
| 14 function testBeforeInputCrash(expectedBeforeInputCount, beforeInputTrigger,
comments) { |
| 15 const iframe = document.createElement('iframe'); |
| 16 document.body.appendChild(iframe); |
| 17 const childDocument = iframe.contentDocument; |
| 18 childDocument.body.innerHTML = '<p id="editable" contenteditable>Foo</p>
'; |
| 19 |
| 20 var actualBeforeInputCount = 0; |
| 21 const editable = childDocument.getElementById('editable'); |
| 22 editable.addEventListener('beforeinput', event => { |
| 23 actualBeforeInputCount++; |
| 24 if (actualBeforeInputCount == expectedBeforeInputCount && iframe.par
entNode) |
| 25 iframe.remove(); |
| 26 }); |
| 27 |
| 28 editable.focus(); |
| 29 beforeInputTrigger(childDocument, editable); |
| 30 |
| 31 if (iframe.parentNode) |
| 32 iframe.remove(); |
| 33 assert_equals(actualBeforeInputCount, expectedBeforeInputCount, comments
); |
| 34 } |
| 35 |
| 36 // Text command. |
| 37 testBeforeInputCrash(1, () => eventSender.keyDown('a'), 'Testing insertText
"a"'); |
| 38 testBeforeInputCrash(1, () => eventSender.keyDown('Enter', ['shiftKey']), 'T
esting insertLineBreak'); |
| 39 testBeforeInputCrash(1, () => eventSender.keyDown('Delete'), 'Testing delete
CharacterForward'); |
| 40 |
| 41 // Styling command. |
| 42 testBeforeInputCrash(1, (childDocument, editable) => { |
| 43 var selection = childDocument.getSelection(); |
| 44 selection.collapse(editable, 0); |
| 45 selection.extend(editable, 1); |
| 46 testRunner.execCommand('bold'); |
| 47 }, 'Testing bold'); |
| 48 |
| 49 // Cut & Paste. |
| 50 testBeforeInputCrash(1, (childDocument, editable) => { |
| 51 var selection = childDocument.getSelection(); |
| 52 selection.collapse(editable, 0); |
| 53 selection.extend(editable, 1); |
| 54 eventSender.keyDown('Cut'); |
| 55 }, 'Testing deleteByCut'); |
| 56 testBeforeInputCrash(1, () => eventSender.keyDown('Paste'), 'Testing insertF
romPaste'); |
| 57 |
| 58 // Undo & Redo. |
| 59 testBeforeInputCrash(2, () => { |
| 60 eventSender.keyDown('a'); |
| 61 testRunner.execCommand('undo'); |
| 62 }, 'Testing undo'); |
| 63 testBeforeInputCrash(3, () => { |
| 64 eventSender.keyDown('a'); |
| 65 testRunner.execCommand('undo'); |
| 66 testRunner.execCommand('redo'); |
| 67 }, 'Testing redo'); |
| 68 }, 'Testing beforeinput in removed iframe'); |
| 69 </script> |
| 70 </body> |
| 71 </html> |
OLD | NEW |