Bug 717433 - Make selected language stick, regardless of whether it partly matches (test). r=roc
authorJorg K <mozilla@jorgk.com>
Wed, 02 Sep 2015 14:39:00 +0200
changeset 260694 3ecb75931636a5eaf85dd6a3b220de9b826684ff
parent 260671 5a7b3500d6d3f8c55d565ed63d1ae61ea276a609
child 260695 5f784cd4caa261031bfe31ceb3e3a6635bbcd9dc
push id15031
push userkwierso@gmail.com
push dateThu, 03 Sep 2015 21:12:32 +0000
treeherderfx-team@13f7a6cb96c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs717433
milestone43.0a1
Bug 717433 - Make selected language stick, regardless of whether it partly matches (test). r=roc
editor/composer/test/bug717433_subframe.html
editor/composer/test/chrome.ini
editor/composer/test/en-GB/en_GB.aff
editor/composer/test/en-GB/en_GB.dic
editor/composer/test/mochitest.ini
editor/composer/test/test_bug717433.html
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/bug717433_subframe.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+<textarea id="textarea" lang="en"></textarea>
+</body>
+</html>
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_async_UpdateCurrentDictionary.html]
 [test_bug338427.html]
 [test_bug434998.xul]
 [test_bug678842.html]
+[test_bug717433.html]
new file mode 100644
--- /dev/null
+++ b/editor/composer/test/en-GB/en_GB.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-GB/en_GB.dic
@@ -0,0 +1,4 @@
+3
+Mary
+Paul
+Peter
--- a/editor/composer/test/mochitest.ini
+++ b/editor/composer/test/mochitest.ini
@@ -1,10 +1,14 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || buildapp == 'mulet'
-support-files = bug678842_subframe.html
+support-files =
+  bug678842_subframe.html
+  bug717433_subframe.html
+  en-GB/en_GB.dic
+  en-GB/en_GB.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_bug717433.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=717433
+-->
+<head>
+  <title>Test for Bug 717433</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>
+<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>
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 717433 **/
+SimpleTest.waitForExplicitFinish();
+var content = document.getElementById('content');
+// Load a subframe containing an editor with language "en". At first
+// load, it will set the dictionary to en-GB or en-US. We set the other one.
+// At second load, it will return the current dictionary. We can check that the
+// dictionary is correctly remembered between loads.
+
+var firstLoad = true;
+var expected = "";
+var en_GB;
+var hunspell;
+
+var loadListener = function(evt) {
+  Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.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;
+  editor.setSpellcheckUserOverride(true);
+  var inlineSpellChecker = editor.getInlineSpellChecker(true);
+
+  onSpellCheck(elem, function () {
+    var spellchecker = inlineSpellChecker.spellChecker;
+    try {
+      var currentDictonary = spellchecker.GetCurrentDictionary();
+    } catch(e) {}
+
+    if (firstLoad) {
+      firstLoad = false;
+
+      // First time around, we get a random dictionary based on the language "en".
+      if (currentDictonary == "en-GB") {
+        spellchecker.SetCurrentDictionary("en-US");
+        expected = "en-US";
+      } else if (currentDictonary == "en-US") {
+        spellchecker.SetCurrentDictionary("en-GB");
+        expected = "en-GB";
+      } else {
+        is(true, false, "Neither en-US nor en-GB are current");
+      }
+      content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug717433_subframe.html?firstload=false';
+    } else {
+      is(currentDictonary, expected, expected + " expected");
+      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);
+      SimpleTest.finish();
+    }
+  });
+}
+
+content.addEventListener('load', loadListener, false);
+
+content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug717433_subframe.html?firstload=true';
+
+</script>
+</pre>
+</body>
+</html>