Bug 1200533 - Fix spellchecker dictionary logic (test changes). r=smaug
☠☠ backed out by 2bb231870f2d ☠ ☠
authorJorg K <mozilla@jorgk.com>
Fri, 04 Sep 2015 11:29:00 +0200
changeset 261222 74e6798a38a4de824660363017f3d83f9c91401a
parent 261221 ee49a5d7058cfe381655fafa39f290e0f6a07cd5
child 261223 b3ad852a044adc38cdb1ac4b1da8d8768ad14498
push id64693
push usercbook@mozilla.com
push dateTue, 08 Sep 2015 06:59:40 +0000
treeherdermozilla-inbound@9f3ca77e2d7b [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 (test changes). r=smaug
editor/composer/test/test_bug678842.html
editor/composer/test/test_bug717433.html
--- a/editor/composer/test/test_bug678842.html
+++ b/editor/composer/test/test_bug678842.html
@@ -3,16 +3,17 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=678842
 -->
 <head>
   <title>Test for Bug 678842</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=678842">Mozilla Bug 678842</a>
 <p id="display"></p>
 <iframe id="content"></iframe>
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
@@ -20,19 +21,42 @@ https://bugzilla.mozilla.org/show_bug.cg
 SimpleTest.waitForExplicitFinish();
 var content = document.getElementById('content');
 // load a subframe containing an editor with a defined unknown lang. At first
 // load, it will set dictionary to en-US. At second load, it will return current
 // dictionary. So, we can check, dictionary is correctly remembered between
 // 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;
   editor.setSpellcheckUserOverride(true);
   var inlineSpellChecker = editor.getInlineSpellChecker(true);
 
   onSpellCheck(elem, function () {
     var spellchecker = inlineSpellChecker.spellChecker;
@@ -41,21 +65,33 @@ var loadListener = function(evt) {
     } catch(e) {}
 
     if (!currentDictonary) {
       spellchecker.SetCurrentDictionary('en-US');
     }
 
     if (firstLoad) {
       firstLoad = false;
-      is (currentDictonary, "", "unexpected lang " + currentDictonary);
+
+       // 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");
+
       content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
     } else {
-      is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
+      is (currentDictonary, "en-GB", "unexpected lang " + currentDictonary + " instead of en-GB");
       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();
     }
   });
 }
 
 content.addEventListener('load', loadListener, false);
 
 content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=true';
--- a/editor/composer/test/test_bug717433.html
+++ b/editor/composer/test/test_bug717433.html
@@ -3,16 +3,17 @@
 <!--
 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>
+<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>
 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
@@ -26,16 +27,17 @@ var content = document.getElementById('c
 
 var firstLoad = true;
 var expected = "";
 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");
@@ -78,16 +80,19 @@ var loadListener = function(evt) {
       }
       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);
+
+      // 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/bug717433_subframe.html?firstload=true';