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 const html = '<p id="editable" contenteditable>Foo</p>'; | |
17 document.body.appendChild(iframe); | |
18 const childDocument = iframe.contentDocument; | |
19 childDocument.open(); | |
yosin_UTC9
2016/08/24 02:11:44
nit: You could write:
childDocument.body.innerHTML
chongz
2016/08/24 02:42:01
Done.
| |
20 childDocument.write(html); | |
21 childDocument.close(); | |
22 | |
23 var actualBeforeInputCount = 0; | |
24 const editable = childDocument.getElementById('editable'); | |
25 editable.addEventListener('beforeinput', event => { | |
26 actualBeforeInputCount++; | |
27 if (actualBeforeInputCount == expectedBeforeInputCount && iframe.par entNode) { | |
yosin_UTC9
2016/08/24 02:11:44
nit: We don't need to have {} for one statement th
chongz
2016/08/24 02:42:01
Done.
| |
28 iframe.parentNode.removeChild(iframe); | |
yosin_UTC9
2016/08/24 02:11:44
nit: iframe.remove() is shorter.
chongz
2016/08/24 02:42:01
Done.
| |
29 } | |
30 }); | |
31 | |
32 editable.focus(); | |
33 beforeInputTrigger(childDocument, editable); | |
34 | |
35 if (iframe.parentNode) { | |
yosin_UTC9
2016/08/24 02:11:44
nit: We don't need to have {} for one statement th
chongz
2016/08/24 02:42:01
Done.
| |
36 iframe.parentNode.removeChild(iframe); | |
yosin_UTC9
2016/08/24 02:11:44
nit: iframe.remove() is shorter.
chongz
2016/08/24 02:42:01
Done.
| |
37 } | |
38 assert_equals(actualBeforeInputCount, expectedBeforeInputCount, comments ); | |
39 } | |
40 | |
41 // Text command. | |
42 testBeforeInputCrash(1, () => eventSender.keyDown('a'), 'Testing insertText "a"'); | |
43 testBeforeInputCrash(1, () => eventSender.keyDown('Enter', ['shiftKey']), 'T esting insertLineBreak'); | |
44 testBeforeInputCrash(1, () => eventSender.keyDown('Delete'), 'Testing delete CharacterForward'); | |
45 | |
46 // Styling command. | |
47 testBeforeInputCrash(1, (childDocument, editable) => { | |
48 var selection = childDocument.getSelection(); | |
49 selection.collapse(editable, 0); | |
50 selection.extend(editable, 1); | |
51 testRunner.execCommand('bold'); | |
52 }, 'Testing bold'); | |
53 | |
54 // Cut & Paste. | |
55 testBeforeInputCrash(1, (childDocument, editable) => { | |
56 var selection = childDocument.getSelection(); | |
57 selection.collapse(editable, 0); | |
58 selection.extend(editable, 1); | |
59 eventSender.keyDown('Cut'); | |
60 }, 'Testing deleteByCut'); | |
61 testBeforeInputCrash(1, () => eventSender.keyDown('Paste'), 'Testing insertF romPaste'); | |
62 | |
63 // Undo & Redo. | |
64 testBeforeInputCrash(2, () => { | |
65 eventSender.keyDown('a'); | |
66 testRunner.execCommand('undo'); | |
67 }, 'Testing undo'); | |
68 testBeforeInputCrash(3, () => { | |
69 eventSender.keyDown('a'); | |
70 testRunner.execCommand('undo'); | |
71 testRunner.execCommand('redo'); | |
72 }, 'Testing redo'); | |
73 }, 'Testing beforeinput in removed iframe'); | |
74 </script> | |
75 </body> | |
76 </html> | |
OLD | NEW |