summaryrefslogtreecommitdiffstats
path: root/editor/spellchecker/tests/test_bug1497480.html
blob: a7063271f4d16c649efd8126ba0b7771cafa23d7 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1497480
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1497480</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script src="spellcheck.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>

</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1497480">Mozilla Bug 1497480</a>
<p id="display"></p>

<div id="outOfTarget" contenteditable>Bug 1497480</div>
<div id="light"></div>

<script>

/** Test for Bug 1497480 **/
let gMisspeltWords = [];
let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.import(
  "resource://testing-common/AsyncSpellCheckTestHelper.jsm"
);

const template = document.createElement("template");
template.innerHTML = `<div id="target" contenteditable>Test</div>`;

let shadow = document.getElementById("light").attachShadow({mode: "closed"});
shadow.appendChild(template.content.cloneNode(true));

let target = shadow.getElementById("target");
let outOfTarget = document.getElementById("outOfTarget");

function getEditor() {
  var win = window;
  var editingSession = SpecialPowers.wrap(win).docShell.editingSession;
  return editingSession.getEditorForWindow(win);
}

// Wait for the page to be ready for testing
add_task(async function() {
  await new Promise((resolve) => {
    SimpleTest.waitForFocus(() => {
      SimpleTest.executeSoon(resolve);
    }, window);
  });

  // Wait for first full spell-checking.
  synthesizeMouseAtCenter(outOfTarget, {}, window);
  await new Promise((resolve) => {
    maybeOnSpellCheck(outOfTarget, function() {
      resolve();
    });
  });
});

// Should perform spell-checking when anchor navigates away from ShadowDOM.
add_task(async function() {
  synthesizeMouseAtCenter(target, {}, window);
  sendString(" spellechek");
  gMisspeltWords.push("spellechek");
  synthesizeMouseAtCenter(outOfTarget, {}, window);
  await new Promise((resolve) => {
    maybeOnSpellCheck(target, function() {
      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
         "Spell-checking should be performed when anchor navigates away from ShadowDOM");
      SimpleTest.executeSoon(resolve);
    });
  });
});

// Should perform spell-checking when pressing enter in contenteditable in ShadowDOM.
add_task(async function() {
  synthesizeMouseAtCenter(target, {}, window);
  sendString(" spellechck");
  gMisspeltWords.push("spellechck");
  synthesizeKey("KEY_Enter", {}, window);
  await new Promise((resolve) => {
    maybeOnSpellCheck(target, function() {
      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
         "Spell-checking should be performed when pressing enter in contenteditable in ShadowDOM");
      SimpleTest.executeSoon(resolve);
    });
  });
});

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