diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /extensions/spellcheck/tests | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'extensions/spellcheck/tests')
10 files changed, 546 insertions, 0 deletions
diff --git a/extensions/spellcheck/tests/chrome/base/base_utf.aff b/extensions/spellcheck/tests/chrome/base/base_utf.aff new file mode 100644 index 0000000000..493157b301 --- /dev/null +++ b/extensions/spellcheck/tests/chrome/base/base_utf.aff @@ -0,0 +1,198 @@ +# OpenOffice.org’s en_US.aff file +# with Unicode apostrophe: ’ + +SET UTF-8 +TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ' + +MAXNGRAMSUGS 1 +WORDCHARS .'’ + +PFX A Y 1 +PFX A 0 re . + +PFX I Y 1 +PFX I 0 in . + +PFX U Y 1 +PFX U 0 un . + +PFX C Y 1 +PFX C 0 de . + +PFX E Y 1 +PFX E 0 dis . + +PFX F Y 1 +PFX F 0 con . + +PFX K Y 1 +PFX K 0 pro . + +SFX V N 2 +SFX V e ive e +SFX V 0 ive [^e] + +SFX N Y 3 +SFX N e ion e +SFX N y ication y +SFX N 0 en [^ey] + +SFX X Y 3 +SFX X e ions e +SFX X y ications y +SFX X 0 ens [^ey] + +SFX H N 2 +SFX H y ieth y +SFX H 0 th [^y] + +SFX Y Y 1 +SFX Y 0 ly . + +SFX G Y 2 +SFX G e ing e +SFX G 0 ing [^e] + +SFX J Y 2 +SFX J e ings e +SFX J 0 ings [^e] + +SFX D Y 4 +SFX D 0 d e +SFX D y ied [^aeiou]y +SFX D 0 ed [^ey] +SFX D 0 ed [aeiou]y + +SFX T N 4 +SFX T 0 st e +SFX T y iest [^aeiou]y +SFX T 0 est [aeiou]y +SFX T 0 est [^ey] + +SFX R Y 4 +SFX R 0 r e +SFX R y ier [^aeiou]y +SFX R 0 er [aeiou]y +SFX R 0 er [^ey] + +SFX Z Y 4 +SFX Z 0 rs e +SFX Z y iers [^aeiou]y +SFX Z 0 ers [aeiou]y +SFX Z 0 ers [^ey] + +SFX S Y 4 +SFX S y ies [^aeiou]y +SFX S 0 s [aeiou]y +SFX S 0 es [sxzh] +SFX S 0 s [^sxzhy] + +SFX P Y 3 +SFX P y iness [^aeiou]y +SFX P 0 ness [aeiou]y +SFX P 0 ness [^y] + +SFX M Y 1 +SFX M 0 's . + +SFX B Y 3 +SFX B 0 able [^aeiou] +SFX B 0 able ee +SFX B e able [^aeiou]e + +SFX L Y 1 +SFX L 0 ment . + +REP 88 +REP a ei +REP ei a +REP a ey +REP ey a +REP ai ie +REP ie ai +REP are air +REP are ear +REP are eir +REP air are +REP air ere +REP ere air +REP ere ear +REP ere eir +REP ear are +REP ear air +REP ear ere +REP eir are +REP eir ere +REP ch te +REP te ch +REP ch ti +REP ti ch +REP ch tu +REP tu ch +REP ch s +REP s ch +REP ch k +REP k ch +REP f ph +REP ph f +REP gh f +REP f gh +REP i igh +REP igh i +REP i uy +REP uy i +REP i ee +REP ee i +REP j di +REP di j +REP j gg +REP gg j +REP j ge +REP ge j +REP s ti +REP ti s +REP s ci +REP ci s +REP k cc +REP cc k +REP k qu +REP qu k +REP kw qu +REP o eau +REP eau o +REP o ew +REP ew o +REP oo ew +REP ew oo +REP ew ui +REP ui ew +REP oo ui +REP ui oo +REP ew u +REP u ew +REP oo u +REP u oo +REP u oe +REP oe u +REP u ieu +REP ieu u +REP ue ew +REP ew ue +REP uff ough +REP oo ieu +REP ieu oo +REP ier ear +REP ear ier +REP ear air +REP air ear +REP w qu +REP qu w +REP z ss +REP ss z +REP shun tion +REP shun sion +REP shun cion +McDonalds’sá/w +McDonald’sszá/g3) st:McDonaldâs po:noun_prs is:TRANS +McDonald’sszal/g4) st:McDonaldâs po:noun_prs is:INSTR +McDonald’ssal/w diff --git a/extensions/spellcheck/tests/chrome/base/base_utf.dic b/extensions/spellcheck/tests/chrome/base/base_utf.dic new file mode 100644 index 0000000000..b2b536d285 --- /dev/null +++ b/extensions/spellcheck/tests/chrome/base/base_utf.dic @@ -0,0 +1,29 @@ +28 +created/U +create/XKVNGADS +imply/GNSDX +natural/PUY +like/USPBY +convey/BDGS +look/GZRDS +text +hello +said +sawyer +NASA +rotten +day +tomorrow +seven +FAQ/SM +can’t +doesn’t +etc +won’t +lip +text +horrifying +speech +suggest +uncreate/V +Hunspell diff --git a/extensions/spellcheck/tests/chrome/chrome.toml b/extensions/spellcheck/tests/chrome/chrome.toml new file mode 100644 index 0000000000..36eff0016a --- /dev/null +++ b/extensions/spellcheck/tests/chrome/chrome.toml @@ -0,0 +1,11 @@ +[DEFAULT] +skip-if = ["os == 'android'"] + +["test_add_remove_dictionaries.xhtml"] +skip-if = ["verify"] +support-files = [ + "base/base_utf.dic", + "base/base_utf.aff", + "map/maputf.dic", + "map/maputf.aff", +] diff --git a/extensions/spellcheck/tests/chrome/map/maputf.aff b/extensions/spellcheck/tests/chrome/map/maputf.aff new file mode 100644 index 0000000000..30edb2a785 --- /dev/null +++ b/extensions/spellcheck/tests/chrome/map/maputf.aff @@ -0,0 +1,11 @@ +# With MAP suggestion, Hunspell can add missing accents to a word. + +SET UTF-8 + +# switch off ngram suggestion for testing +MAXNGRAMSUGS 0 + +MAP 3 +MAP uúü +MAP öóo +MAP ß(ss) diff --git a/extensions/spellcheck/tests/chrome/map/maputf.dic b/extensions/spellcheck/tests/chrome/map/maputf.dic new file mode 100644 index 0000000000..1c6fa8d058 --- /dev/null +++ b/extensions/spellcheck/tests/chrome/map/maputf.dic @@ -0,0 +1,4 @@ +3 +Frühstück +tükörfúró +groß diff --git a/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml b/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml new file mode 100644 index 0000000000..fc2eacf31e --- /dev/null +++ b/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml @@ -0,0 +1,129 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window title="Add and remove dictionaries test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:html="http://www.w3.org/1999/xhtml" + onload="RunTest();"> + + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <script type="application/javascript"> + <![CDATA[ +SimpleTest.waitForExplicitFinish(); + +function getMisspelledWords(editor) { + return editor.selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK).toString(); +} + +function getDictionaryList(editor) { + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; + return spellchecker.GetDictionaryList(); +} + +function getCurrentDictionary(editor) { + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; + return spellchecker.getCurrentDictionaries()[0]; +} + +function setCurrentDictionary(editor, dictionary) { + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; + return spellchecker.setCurrentDictionaries([dictionary]); +} + +function RunTest() { + var textbox = document.getElementById('textbox'); + textbox.focus(); + var editor = textbox.editor; + + // eslint-disable-next-line mozilla/use-services + var dir = Cc["@mozilla.org/file/directory_service;1"]. + getService(Ci.nsIProperties). + get("CurWorkD", Ci.nsIFile); + dir.append("chrome"); + dir.append("extensions"); + dir.append("spellcheck"); + dir.append("tests"); + dir.append("chrome"); + + var hunspell = Cc["@mozilla.org/spellchecker/engine;1"] + .getService(Ci.mozISpellCheckingEngine); + + // install base dictionary + var base = dir.clone(); + base.append("base"); + ok(base.exists()); + hunspell.addDirectory(base); + + // install map dictionary + var map = dir.clone(); + map.append("map"); + ok(map.exists()); + hunspell.addDirectory(map); + + const {maybeOnSpellCheck} = ChromeUtils.importESModule( + "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"); + maybeOnSpellCheck(textbox, function () { + + // test that base and map dictionaries are available + var dicts = getDictionaryList(editor); + isnot(dicts.indexOf("base-utf"), -1, "base is available"); + isnot(dicts.indexOf("maputf"), -1, "map is available"); + + // select base dictionary + setCurrentDictionary(editor, "base-utf").then(() => { + /* eslint-disable no-useless-concat */ + maybeOnSpellCheck(textbox, function () { + // test that base dictionary is in use + is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings"); + is(getCurrentDictionary(editor), "base-utf", "current dictionary"); + + // select map dictionary + setCurrentDictionary(editor, "maputf").then(() => { + // Focus again, so the spelling gets updated. + textbox.blur(); + textbox.focus(); + + maybeOnSpellCheck(textbox, function () { + // test that map dictionary is in use + is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (1)"); + is(getCurrentDictionary(editor), "maputf", "current dictionary"); + + // uninstall map dictionary + hunspell.removeDirectory(map); + + // Focus again, so the spelling gets updated. + textbox.blur(); + textbox.focus(); + + maybeOnSpellCheck(textbox, function () { + // test that map dictionary is not in use + isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (2)"); + isnot(getCurrentDictionary(editor), "maputf", "current dictionary"); + + // test that base dictionary is available and map dictionary is unavailable + var dicts = getDictionaryList(editor); + isnot(dicts.indexOf("base-utf"), -1, "base is available"); + is(dicts.indexOf("maputf"), -1, "map is unavailable"); + + // uninstall base dictionary + hunspell.removeDirectory(base); + + maybeOnSpellCheck(textbox, function () { + SimpleTest.finish(); + }); + }); + }); + }); + }); + }); + }); +} + ]]> + </script> + <html:input id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/> +</window> diff --git a/extensions/spellcheck/tests/mochitest/helper_bug1170484.js b/extensions/spellcheck/tests/mochitest/helper_bug1170484.js new file mode 100644 index 0000000000..227e35e81a --- /dev/null +++ b/extensions/spellcheck/tests/mochitest/helper_bug1170484.js @@ -0,0 +1,12 @@ +/* eslint-env mozilla/chrome-script */ + +// Chrome scripts are run with synchronous messages, so make sure we're completely +// decoupled from the content process before doing this work. +Cu.dispatch(function () { + let chromeWin = Services.ww.activeWindow; + let contextMenu = chromeWin.document.getElementById("contentAreaContextMenu"); + var suggestion = contextMenu.querySelector(".spell-suggestion"); + suggestion.doCommand(); + contextMenu.hidePopup(); + sendAsyncMessage("spellingCorrected"); +}); diff --git a/extensions/spellcheck/tests/mochitest/mochitest.toml b/extensions/spellcheck/tests/mochitest/mochitest.toml new file mode 100644 index 0000000000..2815db0b63 --- /dev/null +++ b/extensions/spellcheck/tests/mochitest/mochitest.toml @@ -0,0 +1,8 @@ +[DEFAULT] +skip-if = ["os == 'android'"] + +["test_bug1170484.html"] +support-files = ["helper_bug1170484.js"] +skip-if = ["os == 'linux'"] #Bug 1202570 + +["test_bug1272623.html"] diff --git a/extensions/spellcheck/tests/mochitest/test_bug1170484.html b/extensions/spellcheck/tests/mochitest/test_bug1170484.html new file mode 100644 index 0000000000..a4e50ebd01 --- /dev/null +++ b/extensions/spellcheck/tests/mochitest/test_bug1170484.html @@ -0,0 +1,59 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1170484 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1170484</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"/> + <script type="application/javascript"> + + /** Test for Bug 1170484 */ + SimpleTest.waitForExplicitFinish(); + + var { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule( + "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" + ); + + SimpleTest.waitForFocus(doTest, window); + function doTest() { + var mutations = 0; + var observer = new MutationObserver(() => { mutations++; }); + observer.observe($('area'), { childList: true, characterData: true, characterDataOldValue: true, subtree: true }); + var inputEvents = 0; + $('area').addEventListener('input', () => ++inputEvents); + + // Clicking the contentEditable during onload doesn't seem to do anything. + // Not sure why, but postponing through the event loop seems to be enough. + SimpleTest.executeSoon(function() { + synthesizeMouseAtCenter($('misspelled'), {}, window); + maybeOnSpellCheck($('area'), function() { + synthesizeMouseAtCenter($('misspelled'), {type: 'contextmenu'}, window); + var mm = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('helper_bug1170484.js')) + info("Loaded chrome script"); + mm.addMessageListener('spellingCorrected', function() { + is($('area').textContent, 'testing spellcheck', "Spelling corrected properly"); + is(mutations, 1, "Got correct number of mutations"); + is(inputEvents, 1, "Got correct number of input events"); + SimpleTest.finish(); + }); + }); + }); + } + + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1170484">Mozilla Bug 1170484</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> + <div id="area" contenteditable="true">testing <span id="misspelled">spellechek</span></div> +</pre> +</body> +</html> diff --git a/extensions/spellcheck/tests/mochitest/test_bug1272623.html b/extensions/spellcheck/tests/mochitest/test_bug1272623.html new file mode 100644 index 0000000000..f26938edad --- /dev/null +++ b/extensions/spellcheck/tests/mochitest/test_bug1272623.html @@ -0,0 +1,85 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1272623 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1272623</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> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1272623">Mozilla Bug 1272623</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> + <div id="area" contenteditable="true"><b style="font-weight:normal;">testing <span id="misspelled">spellechek</span></b></div> + <div id="area2" contenteditable="true">testing <span id="misspelled2" style="font-weight:bold;">spellechek</span></div> +</pre> +<script> + +/** Test for Bug 1272623 */ + + var maybeOnSpellCheck; + + async function performCorrection(misspelled, area) { + synthesizeMouseAtCenter($(misspelled), {}, window); + await new Promise(resolve => maybeOnSpellCheck($(area), resolve)); + synthesizeMouseAtCenter($(misspelled), {type: 'contextmenu'}, window); + + // Perform the spelling correction + let mm = SpecialPowers.loadChromeScript(function() { + /* eslint-env mozilla/chrome-script */ + const {BrowserTestUtils} = ChromeUtils.importESModule( + "resource://testing-common/BrowserTestUtils.sys.mjs" + ); + + // Chrome scripts are run with synchronous messages, so make sure we're completely + // decoupled from the content process before doing this work. + Cu.dispatch(async function() { + let chromeWin = Services.ww.activeWindow; + let contextMenu = chromeWin.document.getElementById("contentAreaContextMenu"); + let suggestion = contextMenu.querySelector(".spell-suggestion"); + if (!suggestion) { + await BrowserTestUtils.waitForMutationCondition( + contextMenu, + { childList: true }, + () => contextMenu.querySelector(".spell-suggestion") + ); + suggestion = contextMenu.querySelector(".spell-suggestion"); + } + suggestion.doCommand(); + contextMenu.hidePopup(); + sendAsyncMessage("spellingCorrected"); + }); + }); + info("Loaded chrome script"); + await new Promise(resolve => mm.addMessageListener('spellingCorrected', resolve)); + } + + add_task(async function() { + maybeOnSpellCheck = SpecialPowers.ChromeUtils.importESModule( + "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" + ).maybeOnSpellCheck; + + // Wait for the page to be ready + await new Promise(resolve => SimpleTest.waitForFocus(() => SimpleTest.executeSoon(resolve), window)); + + // Check that <b> tags aren't inserted inside of other <b> tags when it would change the style + await performCorrection('misspelled', 'area'); + is($('area').innerHTML, "<b style=\"font-weight:normal;\">testing <span id=\"misspelled\">spellcheck</span></b>"); + is($('area').textContent, 'testing spellcheck', "Spelling corrected properly"); + + // Check that nodes aren't removed when the entire text inside of them is spelling-corrected + await performCorrection('misspelled2', 'area2'); + is($('area2').innerHTML, "testing <span id=\"misspelled2\" style=\"font-weight:bold;\">spellcheck</span>"); + is($('area2').textContent, 'testing spellcheck', "Spelling corrected properly"); + }); +</script> +</body> +</html> |