test_composition_event_created_in_chrome.html (3017B)
1 <!doctype html> 2 <html> 3 4 <head> 5 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 6 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <script src="/tests/SimpleTest/EventUtils.js"></script> 9 </head> 10 11 <body> 12 13 <input id="input"> 14 15 <script type="application/javascript"> 16 17 // In nsEditorEventListener, when listening event is not created with proper 18 // event interface, it asserts the fact. 19 SimpleTest.waitForExplicitFinish(); 20 21 var gInputElement = document.getElementById("input"); 22 23 function getEditor(aInputElement) { 24 var editableElement = SpecialPowers.wrap(aInputElement); 25 ok(editableElement.editor, "There is no editor for the input element"); 26 return editableElement.editor; 27 } 28 29 var gEditor; 30 31 function testNotGenerateCompositionByCreatedEvents(aEventInterface) { 32 var compositionEvent = document.createEvent(aEventInterface); 33 if (compositionEvent.initCompositionEvent) { 34 compositionEvent.initCompositionEvent("compositionstart", true, true, window, ""); 35 } else if (compositionEvent.initMouseEvent) { 36 compositionEvent.initMouseEvent("compositionstart", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 37 } 38 gInputElement.dispatchEvent(compositionEvent); 39 ok(!gEditor.composing, "Composition shouldn't be started with a created compositionstart event (" + aEventInterface + ")"); 40 41 compositionEvent = document.createEvent(aEventInterface); 42 if (compositionEvent.initCompositionEvent) { 43 compositionEvent.initCompositionEvent("compositionupdate", true, false, window, "abc"); 44 } else if (compositionEvent.initMouseEvent) { 45 compositionEvent.initMouseEvent("compositionupdate", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 46 } 47 gInputElement.dispatchEvent(compositionEvent); 48 ok(!gEditor.composing, "Composition shouldn't be started with a created compositionupdate event (" + aEventInterface + ")"); 49 is(gInputElement.value, "", "Input element shouldn't be modified with a created compositionupdate event (" + aEventInterface + ")"); 50 51 compositionEvent = document.createEvent(aEventInterface); 52 if (compositionEvent.initCompositionEvent) { 53 compositionEvent.initCompositionEvent("compositionend", true, false, window, "abc"); 54 } else if (compositionEvent.initMouseEvent) { 55 compositionEvent.initMouseEvent("compositionend", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 56 } 57 gInputElement.dispatchEvent(compositionEvent); 58 ok(!gEditor.composing, "Composition shouldn't be committed with a created compositionend event (" + aEventInterface + ")"); 59 is(gInputElement.value, "", "Input element shouldn't be committed with a created compositionend event (" + aEventInterface + ")"); 60 } 61 62 function doTests() { 63 gInputElement.focus(); 64 gEditor = getEditor(gInputElement); 65 66 testNotGenerateCompositionByCreatedEvents("CompositionEvent"); 67 testNotGenerateCompositionByCreatedEvents("MouseEvent"); 68 69 SimpleTest.finish(); 70 } 71 72 SimpleTest.waitForFocus(doTests); 73 74 </script> 75 </body> 76 </html>