Bug 1497480 - Part 3: Add tests for spell-checking in ShadowDOM; r=smaug a=jcristau
authorEdgar Chen <echen@mozilla.com>
Fri, 02 Nov 2018 00:07:30 +0000
changeset 501043 f9639e65bc99f3a2ced65aab2ec17d1f2095734a
parent 501042 ad24ecd2dd3979ec8e13ab4ba79d370c4423fbbd
child 501044 013f4e5f93fdcb87ee41e26057e56e19f80428d7
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1497480
milestone64.0
Bug 1497480 - Part 3: Add tests for spell-checking in ShadowDOM; r=smaug a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D9802
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug1497480.html
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -253,16 +253,18 @@ skip-if = toolkit == 'android' # bug 131
 [test_bug1368544.html]
 [test_bug1385905.html]
 [test_bug1390562.html]
 [test_bug1394758.html]
 [test_bug1399722.html]
 [test_bug1406726.html]
 [test_bug1409520.html]
 [test_bug1425997.html]
+[test_bug1497480.html]
+skip-if = toolkit == 'android'
 
 [test_abs_positioner_appearance.html]
 [test_abs_positioner_positioning_elements.html]
 skip-if = android_version == '18' # bug 1147989
 [test_CF_HTML_clipboard.html]
 subsuite = clipboard
 [test_composition_event_created_in_chrome.html]
 [test_contenteditable_focus.html]
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1497480.html
@@ -0,0 +1,93 @@
+<!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="/tests/SimpleTest/AddTask.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 onSpellCheck = SpecialPowers.Cu.import(
+  "resource://testing-common/AsyncSpellCheckTestHelper.jsm", null).onSpellCheck;
+
+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.
+  await new Promise((resolve) => {
+    onSpellCheck(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) => {
+    onSpellCheck(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) => {
+    onSpellCheck(target, function() {
+      ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
+         "Spell-checking should be performed when pressing enter in contenteditable in ShadowDOM");
+      SimpleTest.executeSoon(resolve);
+    });
+  });
+});
+
+</script>
+</body>
+</html>