5 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
7 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
15 <script type=
"application/javascript">
17 // In nsEditorEventListener, when listening event is not created with proper
18 // event interface, it asserts the fact.
19 SimpleTest.waitForExplicitFinish();
21 var gInputElement = document.getElementById(
"input");
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;
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);
38 gInputElement.dispatchEvent(compositionEvent);
39 ok(!gEditor.composing,
"Composition shouldn't be started with a created compositionstart event (" + aEventInterface +
")");
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);
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 +
")");
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);
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 +
")");
63 gInputElement.focus();
64 gEditor = getEditor(gInputElement);
66 testNotGenerateCompositionByCreatedEvents(
"CompositionEvent");
67 testNotGenerateCompositionByCreatedEvents(
"MouseEvent");
72 SimpleTest.waitForFocus(doTests);