test_text_event_in_content.html (2679B)
1 <!doctype html> 2 <html> 3 <head> 4 <title>Not dispatching DOM "text" event on web apps</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <input id="input"> 11 <textarea id="textarea"></textarea> 12 <div contenteditable id="editor"><p><br></p></div> 13 <script> 14 SimpleTest.waitForExplicitFinish(); 15 SimpleTest.waitForFocus(async function doTests() { 16 await SpecialPowers.pushPrefEnv({ 17 set: [["test.ime_content_observer.assert_invalid_cache", true]], 18 }); 19 for (let editorId of ["input", "textarea", "editor"]) { 20 let editor = document.getElementById(editorId); 21 editor.focus(); 22 let fired = false; 23 function onText() { 24 fired = true; 25 } 26 editor.addEventListener("text", onText); 27 28 fired = false; 29 synthesizeCompositionChange({ 30 composition: {string: "abc", 31 clauses: [{length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE}]}, 32 caret: {start: 3, length: 0}, 33 }); 34 ok(!fired, `Starting composition shouldn't fire DOM "text" event in ${editorId}`); 35 fired = false; 36 synthesizeComposition({type: "compositioncommitasis", key: {key: "KEY_Enter"}}); 37 ok(!fired, `Committing composition with the latest string shouldn't fire DOM "text" event in ${editorId}`); 38 39 fired = false; 40 synthesizeCompositionChange({ 41 composition: {string: "def", 42 clauses: [{length: 3, attr: COMPOSITION_ATTR_RAW_CLAUSE}]}, 43 caret: {start: 3, length: 0}, 44 }); 45 ok(!fired, `Restarting composition shouldn't fire DOM "text" event in ${editorId}`); 46 fired = false; 47 synthesizeComposition({type: "compositioncommit", data: "", key: {key: "KEY_Escape"}}); 48 ok(!fired, `Committing composition with empty string shouldn't fire DOM "text" event in ${editorId}`); 49 50 fired = false; 51 synthesizeCompositionChange({ 52 composition: {string: "de", 53 clauses: [{length: 2, attr: COMPOSITION_ATTR_RAW_CLAUSE}]}, 54 caret: {start: 2, length: 0}, 55 }); 56 ok(!fired, `Restarting composition shouldn't fire DOM "text" event in ${editorId}`); 57 fired = false; 58 synthesizeComposition({type: "compositioncommit", data: "def", key: {key: "KEY_Escape"}}); 59 ok(!fired, `Committing composition with new string shouldn't fire DOM "text" event in ${editorId}`); 60 61 fired = false; 62 synthesizeComposition({type: "compositioncommit", data: "ghi"}); 63 ok(!fired, `Inserting string shouldn't fire DOM "text" event in ${editorId}`); 64 65 editor.removeEventListener("text", onText); 66 } 67 SimpleTest.finish(); 68 }); 69 </script> 70 </body> 71 </html>