summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/test_composition_with_highlight_in_texteditor.html
blob: 0990d87adb5f638b28bdcb7ed6796d64c2083e2f (plain)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test crash bug 1785311</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<input value="abc">
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(() => {
  const input = document.querySelector("input");
  input.focus();
  const editor = SpecialPowers.wrap(input).editor;
  const selectionController = editor.selectionController;
  const findSelection = selectionController.getSelection(
    SpecialPowers.Ci.nsISelectionController.SELECTION_FIND
  );
  const editActionListener = {
    QueryInterface: SpecialPowers.ChromeUtils.generateQI(["nsIEditActionListener"]),
    WillDeleteText: () => {},
    DidInsertText: () => {},
    WillDeleteRanges: () => {},
  };
  // Highlight "a"
  findSelection.setBaseAndExtent(
    editor.rootElement.firstChild, 0,
    editor.rootElement.firstChild, 1
  );
  try {
    editor.addEditActionListener(editActionListener);
    // Start composition at end of <input>
    editor.selection.collapse(editor.rootElement.firstChild, "abc".length);
    synthesizeCompositionChange({
      composition: {
        string: "d",
        clauses: [
          { length: 1, attr: COMPOSITION_ATTR_RAW_CLAUSE },
        ],
      },
      caret: {
        start: 1,
        length: 0,
      },
    });
    synthesizeComposition({
      type: "compositioncommitasis",
    });
    ok(true, "Should not crash");
  } finally {
    editor.removeEditActionListener(editActionListener);
    SimpleTest.finish();
  }
});
</script>
</body>
</html>