зеркало из https://github.com/mozilla/gecko-dev.git
Backed out 3 changesets (bug 1200533) for test failures in reftests/338427-2.html
Backed out changeset 9f3ca77e2d7b (bug 1200533) Backed out changeset b3ad852a044a (bug 1200533) Backed out changeset 74e6798a38a4 (bug 1200533)
This commit is contained in:
Родитель
39b2543e9a
Коммит
a1008eb382
|
@ -590,8 +590,7 @@ nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary)
|
|||
|
||||
// The purpose of mUpdateDictionaryRunning is to avoid doing all of this if
|
||||
// UpdateCurrentDictionary's helper method DictionaryFetched, which calls us,
|
||||
// is on the stack. In other words: Only do this, if the user manually selected a
|
||||
// dictionary to use.
|
||||
// is on the stack.
|
||||
if (!mUpdateDictionaryRunning) {
|
||||
|
||||
// Ignore pending dictionary fetchers by increasing this number.
|
||||
|
@ -600,36 +599,23 @@ nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary)
|
|||
uint32_t flags = 0;
|
||||
mEditor->GetFlags(&flags);
|
||||
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
||||
if (mPreferredLang.IsEmpty() ||
|
||||
!mPreferredLang.Equals(aDictionary, nsCaseInsensitiveStringComparator())) {
|
||||
if (mPreferredLang.IsEmpty() || !mPreferredLang.Equals(aDictionary)) {
|
||||
// When user sets dictionary manually, we store this value associated
|
||||
// with editor url, if it doesn't match the document language exactly.
|
||||
// For example on "en" sites, we need to store "en-GB", otherwise
|
||||
// the language might jump back to en-US although the user explicitly
|
||||
// chose otherwise.
|
||||
StoreCurrentDictionary(mEditor, aDictionary);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Writing content preferences for |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
#endif
|
||||
} else {
|
||||
// If user sets a dictionary matching the language defined by
|
||||
// document, we consider content pref has been canceled, and we clear it.
|
||||
ClearCurrentDictionary(mEditor);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Clearing content preferences for |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Also store it in as a preference, so we can use it as a fallback.
|
||||
// We don't want this for mail composer because it uses
|
||||
// "spellchecker.dictionary" as a preference.
|
||||
// Also store it in as a preference. It will be used as a default value
|
||||
// when everything else fails but we don't want this for mail composer
|
||||
// because it has spellchecked dictionary settings in Preferences.
|
||||
Preferences::SetString("spellchecker.dictionary", aDictionary);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Storing spellchecker.dictionary |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(aDictionary).get());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return mSpellChecker->SetCurrentDictionary(aDictionary);
|
||||
|
@ -737,44 +723,6 @@ nsEditorSpellCheck::UpdateCurrentDictionary(nsIEditorSpellCheckCallback* aCallba
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Helper function that iterates over the list of dictionaries and sets the one
|
||||
// that matches based on a given comparison type.
|
||||
nsresult
|
||||
nsEditorSpellCheck::TryDictionary(nsAutoString aDictName,
|
||||
nsTArray<nsString>& aDictList,
|
||||
enum dictCompare aCompareType)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
for (uint32_t i = 0; i < aDictList.Length(); i++) {
|
||||
nsAutoString dictStr(aDictList.ElementAt(i));
|
||||
bool equals = false;
|
||||
switch (aCompareType) {
|
||||
case DICT_NORMAL_COMPARE:
|
||||
equals = aDictName.Equals(dictStr);
|
||||
break;
|
||||
case DICT_COMPARE_CASE_INSENSITIVE:
|
||||
equals = aDictName.Equals(dictStr, nsCaseInsensitiveStringComparator());
|
||||
break;
|
||||
case DICT_COMPARE_DASHMATCH:
|
||||
equals = nsStyleUtil::DashMatchCompare(dictStr, aDictName, nsCaseInsensitiveStringComparator());
|
||||
break;
|
||||
}
|
||||
if (equals) {
|
||||
rv = SetCurrentDictionary(dictStr);
|
||||
#ifdef DEBUG_DICT
|
||||
if (NS_SUCCEEDED(rv))
|
||||
printf("***** Set |%s|.\n", NS_ConvertUTF16toUTF8(dictStr).get());
|
||||
#endif
|
||||
// We always break here. We tried to set the dictionary to an existing
|
||||
// dictionary from the list. This must work, if it doesn't, there is
|
||||
// no point trying another one.
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
||||
{
|
||||
|
@ -792,47 +740,8 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* We try to derive the dictionary to use based on the following priorities:
|
||||
* 1) Content preference, so the language the user set for the site before.
|
||||
* (Introduced in bug 678842 and corrected in bug 717433.)
|
||||
* 2) Language set by the website, or any other dictionary that partly
|
||||
* matches that. (Introduced in bug 338427.)
|
||||
* Eg. if the website is "en-GB", a user who only has "en-US" will get
|
||||
* that. If the website is generic "en", the user will get one of the
|
||||
* "en-*" installed, (almost) at random.
|
||||
* However, we prefer what is stored in "spellchecker.dictionary",
|
||||
* so if the user chose "en-AU" before, they will get "en-AU" on a plain
|
||||
* "en" site. (Introduced in bug 682564.)
|
||||
* 3) The value of "spellchecker.dictionary" which reflects a previous
|
||||
* language choice of the user (on another site).
|
||||
* (This was the original behaviour before the aforementioned bugs
|
||||
* landed).
|
||||
* 4) The user's locale.
|
||||
* 5) Use the current dictionary that is currently set.
|
||||
* 6) The content of the "LANG" environment variable (if set).
|
||||
* 7) The first spell check dictionary installed.
|
||||
*/
|
||||
|
||||
// Get the language from the element or its closest parent according to:
|
||||
// https://html.spec.whatwg.org/#attr-lang
|
||||
// This is used in SetCurrentDictionary.
|
||||
mPreferredLang.Assign(aFetcher->mRootContentLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** mPreferredLang (element) |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
||||
#endif
|
||||
|
||||
// If no luck, try the "Content-Language" header.
|
||||
if (mPreferredLang.IsEmpty()) {
|
||||
mPreferredLang.Assign(aFetcher->mRootDocContentLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** mPreferredLang (content-language) |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(mPreferredLang).get());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Priority 1:
|
||||
// If we successfully fetched a dictionary from content prefs, do not go
|
||||
// further. Use this exact dictionary.
|
||||
// Don't use content preferences for editor with eEditorMailMask flag.
|
||||
|
@ -842,60 +751,51 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
|||
if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
|
||||
dictName.Assign(aFetcher->mDictionary);
|
||||
if (!dictName.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(SetCurrentDictionary(dictName))) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Assigned from content preferences |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
#endif
|
||||
|
||||
// We take an early exit here, so let's not forget to clear the word
|
||||
// list.
|
||||
DeleteSuggestedWordList();
|
||||
return NS_OK;
|
||||
}
|
||||
if (NS_FAILED(SetCurrentDictionary(dictName))) {
|
||||
// May be dictionary was uninstalled ?
|
||||
// Clear the content preference and continue.
|
||||
ClearCurrentDictionary(mEditor);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 2:
|
||||
// After checking the content preferences, we use the language of the element
|
||||
// or document.
|
||||
if (mPreferredLang.IsEmpty()) {
|
||||
mPreferredLang.Assign(aFetcher->mRootDocContentLang);
|
||||
}
|
||||
|
||||
// Then, try to use language computed from element
|
||||
if (!mPreferredLang.IsEmpty()) {
|
||||
dictName.Assign(mPreferredLang);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Assigned from element/doc |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Auxiliary status.
|
||||
nsresult rv2;
|
||||
// otherwise, get language from preferences
|
||||
nsAutoString preferedDict(Preferences::GetLocalizedString("spellchecker.dictionary"));
|
||||
if (dictName.IsEmpty()) {
|
||||
dictName.Assign(preferedDict);
|
||||
}
|
||||
|
||||
// We obtain a list of available dictionaries.
|
||||
nsTArray<nsString> dictList;
|
||||
rv2 = mSpellChecker->GetDictionaryList(&dictList);
|
||||
NS_ENSURE_SUCCESS(rv2, rv2);
|
||||
nsresult rv = NS_OK;
|
||||
if (dictName.IsEmpty()) {
|
||||
// Prefs didn't give us a dictionary name, so just get the current
|
||||
// locale and use that as the default dictionary name!
|
||||
|
||||
// Get the preference value.
|
||||
nsAutoString preferredDict;
|
||||
preferredDict = Preferences::GetLocalizedString("spellchecker.dictionary");
|
||||
nsCOMPtr<nsIXULChromeRegistry> packageRegistry =
|
||||
mozilla::services::GetXULChromeRegistryService();
|
||||
|
||||
// The following will be driven by this status. Once we were able to set a
|
||||
// dictionary successfully, we're done. So we start with a "failed" status.
|
||||
nsresult rv = NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!dictName.IsEmpty()) {
|
||||
// RFC 5646 explicitly states that matches should be case-insensitive.
|
||||
rv = TryDictionary (dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
||||
if (packageRegistry) {
|
||||
nsAutoCString utf8DictName;
|
||||
rv = packageRegistry->GetSelectedLocale(NS_LITERAL_CSTRING("global"),
|
||||
utf8DictName);
|
||||
AppendUTF8toUTF16(utf8DictName, dictName);
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !dictName.IsEmpty()) {
|
||||
rv = SetCurrentDictionary(dictName);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Setting of |%s| failed (or it wasn't available)\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
#endif
|
||||
// required dictionary was not available. Try to get a dictionary
|
||||
// matching at least language part of dictName:
|
||||
|
||||
// Required dictionary was not available. Try to get a dictionary
|
||||
// matching at least language part of dictName.
|
||||
nsAutoString langCode;
|
||||
int32_t dashIdx = dictName.FindChar('-');
|
||||
if (dashIdx != -1) {
|
||||
|
@ -904,112 +804,80 @@ nsEditorSpellCheck::DictionaryFetched(DictionaryFetcher* aFetcher)
|
|||
langCode.Assign(dictName);
|
||||
}
|
||||
|
||||
// Try dictionary.spellchecker preference, if it starts with langCode,
|
||||
// so we don't just get any random dictionary matching the language.
|
||||
if (!preferredDict.IsEmpty() &&
|
||||
nsStyleUtil::DashMatchCompare(preferredDict, langCode, nsDefaultStringComparator())) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying preference value |%s| since it matches language code\n",
|
||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
||||
#endif
|
||||
rv = TryDictionary (preferredDict, dictList,
|
||||
DICT_COMPARE_CASE_INSENSITIVE);
|
||||
nsDefaultStringComparator comparator;
|
||||
|
||||
// try dictionary.spellchecker preference if it starts with langCode (and
|
||||
// if we haven't tried it already)
|
||||
if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) &&
|
||||
nsStyleUtil::DashMatchCompare(preferedDict, langCode, comparator)) {
|
||||
rv = SetCurrentDictionary(preferedDict);
|
||||
}
|
||||
|
||||
// Otherwise, try langCode (if we haven't tried it already)
|
||||
if (NS_FAILED(rv)) {
|
||||
// Use any dictionary with the required language.
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying to find match for language code |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(langCode).get());
|
||||
#endif
|
||||
rv = TryDictionary (langCode, dictList, DICT_COMPARE_DASHMATCH);
|
||||
}
|
||||
if (!dictName.Equals(langCode) && !preferedDict.Equals(langCode)) {
|
||||
rv = SetCurrentDictionary(langCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3:
|
||||
// If the document didn't supply a dictionary or the setting failed,
|
||||
// try the user preference next.
|
||||
// Otherwise, try any available dictionary aa-XX
|
||||
if (NS_FAILED(rv)) {
|
||||
if (!preferredDict.IsEmpty()) {
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying preference value |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(preferredDict).get());
|
||||
#endif
|
||||
rv = TryDictionary (preferredDict, dictList, DICT_NORMAL_COMPARE);
|
||||
// loop over avaible dictionaries; if we find one with required
|
||||
// language, use it
|
||||
nsTArray<nsString> dictList;
|
||||
rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
int32_t i, count = dictList.Length();
|
||||
for (i = 0; i < count; i++) {
|
||||
nsAutoString dictStr(dictList.ElementAt(i));
|
||||
|
||||
if (dictStr.Equals(dictName) ||
|
||||
dictStr.Equals(preferedDict) ||
|
||||
dictStr.Equals(langCode)) {
|
||||
// We have already tried it
|
||||
continue;
|
||||
}
|
||||
if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
|
||||
NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 4:
|
||||
// As next fallback, try the current locale.
|
||||
if (NS_FAILED(rv)) {
|
||||
nsCOMPtr<nsIXULChromeRegistry> packageRegistry =
|
||||
mozilla::services::GetXULChromeRegistryService();
|
||||
|
||||
if (packageRegistry) {
|
||||
nsAutoCString utf8DictName;
|
||||
rv2 = packageRegistry->GetSelectedLocale(NS_LITERAL_CSTRING("global"),
|
||||
utf8DictName);
|
||||
dictName.Assign(EmptyString());
|
||||
AppendUTF8toUTF16(utf8DictName, dictName);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying locale |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictName).get());
|
||||
#endif
|
||||
rv = TryDictionary (dictName, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
// Still no success.
|
||||
|
||||
// Priority 5:
|
||||
// If we have a current dictionary, don't try anything else.
|
||||
// If we have not set dictionary, and the editable element doesn't have a
|
||||
// lang attribute, we try to get a dictionary. First try LANG environment variable,
|
||||
// then en-US. If it does not work, pick the first one.
|
||||
if (mPreferredLang.IsEmpty()) {
|
||||
nsAutoString currentDictionary;
|
||||
rv2 = GetCurrentDictionary(currentDictionary);
|
||||
#ifdef DEBUG_DICT
|
||||
if (NS_SUCCEEDED(rv2))
|
||||
printf("***** Retrieved current dict |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(currentDictionary).get());
|
||||
#endif
|
||||
|
||||
if (NS_FAILED(rv2) || currentDictionary.IsEmpty()) {
|
||||
// Priority 6:
|
||||
// Try to get current dictionary from environment variable LANG.
|
||||
// LANG = language[_territory][.charset]
|
||||
rv = GetCurrentDictionary(currentDictionary);
|
||||
if (NS_FAILED(rv) || currentDictionary.IsEmpty()) {
|
||||
// Try to get current dictionary from environment variable LANG
|
||||
char* env_lang = getenv("LANG");
|
||||
if (env_lang != nullptr) {
|
||||
nsString lang = NS_ConvertUTF8toUTF16(env_lang);
|
||||
// Strip trailing charset, if there is any.
|
||||
// Strip trailing charset if there is any
|
||||
int32_t dot_pos = lang.FindChar('.');
|
||||
if (dot_pos != -1) {
|
||||
lang = Substring(lang, 0, dot_pos);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
int32_t underScore = lang.FindChar('_');
|
||||
if (underScore != -1) {
|
||||
lang.Replace(underScore, 1, '-');
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying LANG from environment |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(lang).get());
|
||||
#endif
|
||||
nsAutoString lang2;
|
||||
lang2.Assign(lang);
|
||||
rv = TryDictionary(lang2, dictList, DICT_COMPARE_CASE_INSENSITIVE);
|
||||
rv = SetCurrentDictionary(lang);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 7:
|
||||
// If it does not work, pick the first one.
|
||||
if (NS_FAILED(rv)) {
|
||||
if (dictList.Length() > 0) {
|
||||
rv = SetCurrentDictionary(dictList[0]);
|
||||
#ifdef DEBUG_DICT
|
||||
printf("***** Trying first of list |%s|\n",
|
||||
NS_ConvertUTF16toUTF8(dictList[0]).get());
|
||||
if (NS_SUCCEEDED(rv))
|
||||
printf ("***** Setting worked.\n");
|
||||
#endif
|
||||
rv = SetCurrentDictionary(NS_LITERAL_STRING("en-US"));
|
||||
if (NS_FAILED(rv)) {
|
||||
nsTArray<nsString> dictList;
|
||||
rv = mSpellChecker->GetDictionaryList(&dictList);
|
||||
if (NS_SUCCEEDED(rv) && dictList.Length() > 0) {
|
||||
SetCurrentDictionary(dictList[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,6 @@ class nsITextServicesFilter;
|
|||
|
||||
class DictionaryFetcher;
|
||||
|
||||
enum dictCompare {
|
||||
DICT_NORMAL_COMPARE,
|
||||
DICT_COMPARE_CASE_INSENSITIVE,
|
||||
DICT_COMPARE_DASHMATCH
|
||||
};
|
||||
|
||||
class nsEditorSpellCheck final : public nsIEditorSpellCheck
|
||||
{
|
||||
friend class DictionaryFetcher;
|
||||
|
@ -70,9 +64,6 @@ protected:
|
|||
|
||||
bool mUpdateDictionaryRunning;
|
||||
|
||||
nsresult TryDictionary(nsAutoString aDictName, nsTArray<nsString>& aDictList,
|
||||
enum dictCompare aCompareType);
|
||||
|
||||
nsresult DictionaryFetched(DictionaryFetcher* aFetchState);
|
||||
|
||||
public:
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-US">
|
||||
</head>
|
||||
<body>
|
||||
<textarea id="none">root en-US</textarea>
|
||||
<textarea id="en-GB" lang="en-GB">root en-US, but element en-GB</textarea>
|
||||
<textarea id="en-gb" lang="en-gb">root en-US, but element en-gb (lower case)</textarea>
|
||||
<textarea id="en-ZA-not-avail" lang="en-ZA">root en-US, but element en-ZA (which is not installed)</textarea>
|
||||
<textarea id="en-generic" lang="en">root en-US, but element en</textarea>
|
||||
<textarea id="ko-not-avail" lang="ko">root en-US, but element ko (which is not installed)</textarea>
|
||||
</body>
|
||||
</html>
|
|
@ -6,4 +6,3 @@ skip-if = buildapp == 'b2g' || os == 'android'
|
|||
[test_bug434998.xul]
|
||||
[test_bug678842.html]
|
||||
[test_bug717433.html]
|
||||
[test_bug1200533.html]
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
# Affix file for German English dictionary
|
||||
# Fake file, nothing here.
|
|
@ -1,4 +0,0 @@
|
|||
3
|
||||
Mary
|
||||
Paul
|
||||
Peter
|
|
@ -1,2 +0,0 @@
|
|||
# Affix file for British English dictionary
|
||||
# Fake file, nothing here.
|
|
@ -1,4 +0,0 @@
|
|||
3
|
||||
Mary
|
||||
Paul
|
||||
Peter
|
|
@ -3,13 +3,8 @@ skip-if = buildapp == 'b2g' || buildapp == 'mulet'
|
|||
support-files =
|
||||
bug678842_subframe.html
|
||||
bug717433_subframe.html
|
||||
bug1200533_subframe.html
|
||||
en-GB/en_GB.dic
|
||||
en-GB/en_GB.aff
|
||||
en-AU/en_AU.dic
|
||||
en-AU/en_AU.aff
|
||||
de-DE/de_DE.dic
|
||||
de-DE/de_DE.aff
|
||||
|
||||
[test_bug348497.html]
|
||||
[test_bug384147.html]
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1200533
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 1200533</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200533">Mozilla Bug 1200533</a>
|
||||
<p id="display"></p>
|
||||
<iframe id="content"></iframe>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" ttype="application/javascript">
|
||||
|
||||
/** Test for Bug 1200533 **/
|
||||
/** Visit the elements defined above and check the dictionary we got **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
var content = document.getElementById('content');
|
||||
|
||||
var tests = [
|
||||
// text area, value of spellchecker.dictionary, result.
|
||||
// Result: Document language.
|
||||
[ "none", "", "en-US" ],
|
||||
// Result: Element language.
|
||||
[ "en-GB", "", "en-GB" ],
|
||||
[ "en-gb", "", "en-GB" ],
|
||||
// Result: Random en-*.
|
||||
[ "en-ZA-not-avail", "", "*" ],
|
||||
[ "en-generic", "", "*" ],
|
||||
// Result: Locale.
|
||||
[ "ko-not-avail", "", "en-US" ],
|
||||
|
||||
// Result: Preference value in all cases.
|
||||
[ "en-ZA-not-avail", "en-AU", "en-AU" ],
|
||||
[ "en-generic", "en-AU", "en-AU" ],
|
||||
[ "ko-not-avail", "en-AU", "en-AU" ],
|
||||
|
||||
// Result: Random en-*.
|
||||
[ "en-ZA-not-avail", "de-DE", "*" ],
|
||||
[ "en-generic", "de-DE", "*" ],
|
||||
// Result: Preference value.
|
||||
[ "ko-not-avail", "de-DE", "de-DE" ],
|
||||
];
|
||||
|
||||
var loadCount = 0;
|
||||
var en_GB;
|
||||
var en_AU;
|
||||
var en_DE;
|
||||
var hunspell;
|
||||
|
||||
var loadListener = function(evt) {
|
||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
if (loadCount == 0) {
|
||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties)
|
||||
.get("CurWorkD", Components.interfaces.nsIFile);
|
||||
dir.append("tests");
|
||||
dir.append("editor");
|
||||
dir.append("composer");
|
||||
dir.append("test");
|
||||
|
||||
hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
|
||||
.getService(Components.interfaces.mozISpellCheckingEngine);
|
||||
|
||||
// Install en-GB, en-AU and de-DE dictionaries.
|
||||
en_GB = dir.clone();
|
||||
en_AU = dir.clone();
|
||||
de_DE = dir.clone();
|
||||
en_GB.append("en-GB");
|
||||
en_AU.append("en-AU");
|
||||
de_DE.append("de-DE");
|
||||
is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
|
||||
is(en_AU.exists(), true, "true expected (en-AU directory should exist)");
|
||||
is(de_DE.exists(), true, "true expected (de-DE directory should exist)");
|
||||
hunspell.addDirectory(en_GB);
|
||||
hunspell.addDirectory(en_AU);
|
||||
hunspell.addDirectory(de_DE);
|
||||
}
|
||||
|
||||
Services.prefs.setCharPref("spellchecker.dictionary", tests[loadCount][1]);
|
||||
|
||||
var doc = evt.target.contentDocument;
|
||||
var elem = doc.getElementById(tests[loadCount][0]);
|
||||
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||
editor.setSpellcheckUserOverride(true);
|
||||
var inlineSpellChecker = editor.getInlineSpellChecker(true);
|
||||
|
||||
onSpellCheck(elem, function () {
|
||||
var spellchecker = inlineSpellChecker.spellChecker;
|
||||
try {
|
||||
var dict = spellchecker.GetCurrentDictionary();
|
||||
} catch(e) {}
|
||||
|
||||
if (tests[loadCount][2] != "*") {
|
||||
is (dict, tests[loadCount][2], "expected " + tests[loadCount][2]);
|
||||
} else {
|
||||
var gotEn = (dict == "en-GB" || dict == "en-AU" || dict == "en-US");
|
||||
is (gotEn, true, "expected en-AU or en-GB or en-US");
|
||||
}
|
||||
|
||||
loadCount++;
|
||||
if (loadCount < tests.length) {
|
||||
// Load the iframe again.
|
||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=false';
|
||||
} else {
|
||||
// Remove the fake dictionaries again, since it's otherwise picked up by later tests.
|
||||
hunspell.removeDirectory(en_GB);
|
||||
hunspell.removeDirectory(en_AU);
|
||||
hunspell.removeDirectory(de_DE);
|
||||
|
||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
content.addEventListener('load', loadListener, false);
|
||||
|
||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug1200533_subframe.html?firstload=true';
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=678842
|
|||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=678842">Mozilla Bug 678842</a>
|
||||
<p id="display"></p>
|
||||
<iframe id="content"></iframe>
|
||||
|
@ -26,32 +25,9 @@ var content = document.getElementById('content');
|
|||
// loads.
|
||||
|
||||
var firstLoad = true;
|
||||
var en_GB;
|
||||
var hunspell;
|
||||
|
||||
var loadListener = function(evt) {
|
||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
if (firstLoad) {
|
||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties)
|
||||
.get("CurWorkD", Components.interfaces.nsIFile);
|
||||
dir.append("tests");
|
||||
dir.append("editor");
|
||||
dir.append("composer");
|
||||
dir.append("test");
|
||||
|
||||
hunspell = Components.classes["@mozilla.org/spellchecker/engine;1"]
|
||||
.getService(Components.interfaces.mozISpellCheckingEngine);
|
||||
|
||||
// Install en-GB dictionary.
|
||||
en_GB = dir.clone();
|
||||
en_GB.append("en-GB");
|
||||
is(en_GB.exists(), true, "true expected (en-GB directory should exist)");
|
||||
hunspell.addDirectory(en_GB);
|
||||
}
|
||||
|
||||
var doc = evt.target.contentDocument;
|
||||
var elem = doc.getElementById('textarea');
|
||||
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||
|
@ -70,23 +46,11 @@ var loadListener = function(evt) {
|
|||
|
||||
if (firstLoad) {
|
||||
firstLoad = false;
|
||||
|
||||
// First time around, the dictionary defaults to the locale.
|
||||
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
|
||||
|
||||
// Select en-GB.
|
||||
spellchecker.SetCurrentDictionary("en-GB");
|
||||
|
||||
is (currentDictonary, "", "unexpected lang " + currentDictonary);
|
||||
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
|
||||
} else {
|
||||
is (currentDictonary, "en-GB", "unexpected lang " + currentDictonary + " instead of en-GB");
|
||||
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
|
||||
content.removeEventListener('load', loadListener, false);
|
||||
|
||||
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
||||
hunspell.removeDirectory(en_GB);
|
||||
|
||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717433
|
|||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717433">Mozilla Bug 717433</a>
|
||||
<p id="display"></p>
|
||||
<iframe id="content"></iframe>
|
||||
|
@ -32,7 +31,6 @@ var hunspell;
|
|||
|
||||
var loadListener = function(evt) {
|
||||
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
if (firstLoad) {
|
||||
var dir = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
|
@ -85,9 +83,6 @@ var loadListener = function(evt) {
|
|||
|
||||
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
||||
hunspell.removeDirectory(en_GB);
|
||||
|
||||
// Reset the preference, so the last value we set doesn't collide with the next test.
|
||||
Services.prefs.setCharPref("spellchecker.dictionary", "");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче