diff --git a/editor/AsyncSpellCheckTestHelper.jsm b/editor/AsyncSpellCheckTestHelper.jsm index 6c28c4fafa46..77bfee17b162 100644 --- a/editor/AsyncSpellCheckTestHelper.jsm +++ b/editor/AsyncSpellCheckTestHelper.jsm @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var EXPORTED_SYMBOLS = ["onSpellCheck"]; +var EXPORTED_SYMBOLS = ["maybeOnSpellCheck", "onSpellCheck"]; const SPELL_CHECK_ENDED_TOPIC = "inlineSpellChecker-spellCheck-ended"; const SPELL_CHECK_STARTED_TOPIC = "inlineSpellChecker-spellCheck-started"; @@ -24,7 +24,7 @@ const SPELL_CHECK_STARTED_TOPIC = "inlineSpellChecker-spellCheck-started"; * of the event loop have passed to determine it has not * started. */ -function onSpellCheck(editableElement, callback) { +function maybeOnSpellCheck(editableElement, callback) { let editor = editableElement.editor; if (!editor) { let win = editableElement.ownerGlobal; @@ -72,9 +72,9 @@ function onSpellCheck(editableElement, callback) { let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); timer.init( function tick() { - // Wait an arbitrarily large number -- 50 -- turns of the event loop before + // Wait an arbitrarily large number -- 100 -- turns of the event loop before // declaring that no spell checks will start. - if (waitingForEnded || ++count < 50) { + if (waitingForEnded || ++count < 100) { return; } timer.cancel(); @@ -86,3 +86,22 @@ function onSpellCheck(editableElement, callback) { Ci.nsITimer.TYPE_REPEATING_SLACK ); } + +/** + * Waits until spell checking has stopped on the given element. + * + * @param editableElement The element being spell checked. + * @param callback Called when spell check has completed or enough turns + * of the event loop have passed to determine it has not + * started. + */ +function onSpellCheck(editableElement, callback) { + const { TestUtils } = ChromeUtils.import( + "resource://testing-common/TestUtils.jsm" + ); + + let editor = editableElement.editor; + TestUtils.topicObserved(SPELL_CHECK_ENDED_TOPIC, s => s == editor).then( + callback + ); +} diff --git a/editor/libeditor/crashtests/1444630.html b/editor/libeditor/crashtests/1444630.html index 4c86cf39a66a..a4dc23294cf4 100644 --- a/editor/libeditor/crashtests/1444630.html +++ b/editor/libeditor/crashtests/1444630.html @@ -8,7 +8,7 @@ function load() textarea.focus(); SpecialPowers.Cu.import("resource://reftest/AsyncSpellCheckTestHelper.jsm") - .onSpellCheck(textarea, () => { + .maybeOnSpellCheck(textarea, () => { let isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false); let sc = isc.spellChecker; diff --git a/editor/libeditor/tests/test_undo_after_spellchecker_replaces_word.html b/editor/libeditor/tests/test_undo_after_spellchecker_replaces_word.html index abfa2d1e9d9f..789368758cfd 100644 --- a/editor/libeditor/tests/test_undo_after_spellchecker_replaces_word.html +++ b/editor/libeditor/tests/test_undo_after_spellchecker_replaces_word.html @@ -95,7 +95,7 @@ SimpleTest.waitForFocus(async () => { SpecialPowers.Cu.import( "resource://testing-common/AsyncSpellCheckTestHelper.jsm") - .onSpellCheck(aElement, () => { + .maybeOnSpellCheck(aElement, () => { SimpleTest.executeSoon(() => { aElement.addEventListener("beforeinput", onBeforeInput); aElement.addEventListener("input", onInput); diff --git a/editor/spellchecker/tests/test_async_UpdateCurrentDictionary.html b/editor/spellchecker/tests/test_async_UpdateCurrentDictionary.html index f95e35356988..24c38aae7c84 100644 --- a/editor/spellchecker/tests/test_async_UpdateCurrentDictionary.html +++ b/editor/spellchecker/tests/test_async_UpdateCurrentDictionary.html @@ -30,44 +30,29 @@ function start() { var isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false); ok(isc, "Inline spell checker should exist after focus and spell check"); var sc = isc.spellChecker; - isnot(sc.GetCurrentDictionary(), lang, - "Current dictionary should not be set yet."); - // First, set the lang attribute on the textarea, call Update, and make - // sure the spell checker's language was updated appropriately. - var lang = "en-US"; - textarea.setAttribute("lang", lang); - sc.UpdateCurrentDictionary(function() { - is(sc.GetCurrentDictionary(), lang, - "UpdateCurrentDictionary should set the current dictionary."); + sc.setCurrentDictionaries(["testing-XX"]).then(() => { + is(true, false, "Setting a non-existent dictionary should fail"); + }, () => { + let currentDictionaries = sc.getCurrentDictionaries(); - // Second, make some Update calls, but then do a Set. The Set should - // effectively cancel the Updates, but the Updates' callbacks should be - // called nonetheless. - var numCalls = 3; - for (var i = 0; i < numCalls; i++) { - sc.UpdateCurrentDictionary(function() { - is(sc.GetCurrentDictionary(), "", - "No dictionary should be active after Update."); - if (--numCalls == 0) { - // This will clear the content preferences and reset "spellchecker.dictionary". - sc.SetCurrentDictionary(""); - SimpleTest.finish(); - } + is(currentDictionaries.length, 0, "expected no dictionaries"); + // First, set the lang attribute on the textarea, call Update, and make + // sure the spell checker's language was updated appropriately. + var lang = "en-US"; + textarea.setAttribute("lang", lang); + sc.UpdateCurrentDictionary(function() { + currentDictionaries = sc.getCurrentDictionaries(); + is(currentDictionaries.length, 1, "expected one dictionary"); + is(sc.getCurrentDictionaries()[0], lang, + "UpdateCurrentDictionary should set the current dictionary."); + sc.setCurrentDictionaries([]).then(() => { + SimpleTest.finish(); }); - } - try { - sc.SetCurrentDictionary("testing-XX"); - } catch (err) { - // Set throws NS_ERROR_NOT_AVAILABLE because "testing-XX" isn't really - // an available dictionary. - } - is(sc.GetCurrentDictionary(), "", - "No dictionary should be active after Set."); + }); }); }); } - diff --git a/editor/spellchecker/tests/test_bug1100966.html b/editor/spellchecker/tests/test_bug1100966.html index 4336bf38630f..a2335696f9cd 100644 --- a/editor/spellchecker/tests/test_bug1100966.html +++ b/editor/spellchecker/tests/test_bug1100966.html @@ -23,7 +23,7 @@ fivee sixx
diff --git a/layout/base/tests/bug923376.html b/layout/base/tests/bug923376.html index cab66a260b95..c516cea31d24 100644 --- a/layout/base/tests/bug923376.html +++ b/layout/base/tests/bug923376.html @@ -6,9 +6,9 @@ var div = document.body.firstChild; div.focus(); SpecialPowers.Cu.import( "resource://testing-common/AsyncSpellCheckTestHelper.jsm", window); -onSpellCheck(div, function() { +maybeOnSpellCheck(div, function() { div.innerHTML = 'something missspelled
something elsed#'; - onSpellCheck(div, function() { + maybeOnSpellCheck(div, function() { document.documentElement.removeAttribute("class"); }); }); diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_dictionary_webextension.js b/toolkit/mozapps/extensions/test/xpcshell/test_dictionary_webextension.js index bccb87a65a82..fe7afa321ea5 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_dictionary_webextension.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_dictionary_webextension.js @@ -169,7 +169,7 @@ add_task(async function test_validation() { const WORD = "Flehgragh"; add_task(async function test_registration() { - spellCheck.dictionary = "en-US"; + spellCheck.dictionaries = ["en-US"]; ok(!spellCheck.check(WORD), "Word should not pass check before add-on loads");