Bug 1200533 - Fix spellchecker dictionary logic (new test). r=smaug
authorJorg K <mozilla@jorgk.com>
Fri, 04 Sep 2015 15:24:00 +0200
changeset 294133 631002821280ceca2286d5d7f111169beb2f53d2
parent 294132 d1d9d161eacd79b8e6d678ef588ed17cf6a2347f
child 294134 08cd638ca00de2c777cf96e5a849ff5e08c8a83c
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1200533
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1200533 - Fix spellchecker dictionary logic (new test). r=smaug
editor/composer/test/bug1200533_subframe.html
editor/composer/test/chrome.ini
editor/composer/test/de-DE/de_DE.aff
editor/composer/test/de-DE/de_DE.dic
editor/composer/test/en-AU/en_AU.aff
editor/composer/test/en-AU/en_AU.dic
editor/composer/test/mochitest.ini
editor/composer/test/test_bug1200533.html
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/bug1200533_subframe.html
@@ -0,0 +1,14 @@
+<!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>
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,8 +1,9 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_async_UpdateCurrentDictionary.html]
 [test_bug338427.html]
 [test_bug434998.xul]
 [test_bug678842.html]
 [test_bug717433.html]
+[test_bug1200533.html]
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/de-DE/de_DE.aff
@@ -0,0 +1,2 @@
+# Affix file for German English dictionary
+# Fake file, nothing here.
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/de-DE/de_DE.dic
@@ -0,0 +1,4 @@
+3
+Mary
+Paul
+Peter
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/en-AU/en_AU.aff
@@ -0,0 +1,2 @@
+# Affix file for British English dictionary
+# Fake file, nothing here.
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/en-AU/en_AU.dic
@@ -0,0 +1,4 @@
+3
+Mary
+Paul
+Peter
--- a/editor/composer/test/mochitest.ini
+++ b/editor/composer/test/mochitest.ini
@@ -1,14 +1,19 @@
 [DEFAULT]
 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]
 [test_bug389350.html]
 skip-if = toolkit == 'android'
 [test_bug519928.html]
 [test_bug738440.html]
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/test_bug1200533.html
@@ -0,0 +1,134 @@
+<!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>