File: test_composition_event_created_in_chrome.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (76 lines) | stat: -rw-r--r-- 3,017 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!doctype html>
<html>

<head>
  <link rel="stylesheet" href="/tests/SimpleTest/test.css">

  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
</head>

<body>

<input id="input">

<script type="application/javascript">

// In nsEditorEventListener, when listening event is not created with proper
// event interface, it asserts the fact.
SimpleTest.waitForExplicitFinish();

var gInputElement = document.getElementById("input");

function getEditor(aInputElement) {
  var editableElement = SpecialPowers.wrap(aInputElement);
  ok(editableElement.editor, "There is no editor for the input element");
  return editableElement.editor;
}

var gEditor;

function testNotGenerateCompositionByCreatedEvents(aEventInterface) {
  var compositionEvent = document.createEvent(aEventInterface);
  if (compositionEvent.initCompositionEvent) {
    compositionEvent.initCompositionEvent("compositionstart", true, true, window, "");
  } else if (compositionEvent.initMouseEvent) {
    compositionEvent.initMouseEvent("compositionstart", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  }
  gInputElement.dispatchEvent(compositionEvent);
  ok(!gEditor.composing, "Composition shouldn't be started with a created compositionstart event (" + aEventInterface + ")");

  compositionEvent = document.createEvent(aEventInterface);
  if (compositionEvent.initCompositionEvent) {
    compositionEvent.initCompositionEvent("compositionupdate", true, false, window, "abc");
  } else if (compositionEvent.initMouseEvent) {
    compositionEvent.initMouseEvent("compositionupdate", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  }
  gInputElement.dispatchEvent(compositionEvent);
  ok(!gEditor.composing, "Composition shouldn't be started with a created compositionupdate event (" + aEventInterface + ")");
  is(gInputElement.value, "", "Input element shouldn't be modified with a created compositionupdate event (" + aEventInterface + ")");

  compositionEvent = document.createEvent(aEventInterface);
  if (compositionEvent.initCompositionEvent) {
    compositionEvent.initCompositionEvent("compositionend", true, false, window, "abc");
  } else if (compositionEvent.initMouseEvent) {
    compositionEvent.initMouseEvent("compositionend", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  }
  gInputElement.dispatchEvent(compositionEvent);
  ok(!gEditor.composing, "Composition shouldn't be committed with a created compositionend event (" + aEventInterface + ")");
  is(gInputElement.value, "", "Input element shouldn't be committed with a created compositionend event (" + aEventInterface + ")");
}

function doTests() {
  gInputElement.focus();
  gEditor = getEditor(gInputElement);

  testNotGenerateCompositionByCreatedEvents("CompositionEvent");
  testNotGenerateCompositionByCreatedEvents("MouseEvent");

  SimpleTest.finish();
}

SimpleTest.waitForFocus(doTests);

</script>
</body>
</html>