Bug 1204540 - Fix up spell checker tests so no content preferences are left behind. r=roc
authorJorg K <mozilla@jorgk.com>
Tue, 15 Sep 2015 10:34:00 +0200
changeset 263761 20624d683ef63e0deae95a81b9ba70ac674f4f4f
parent 263760 c6212d71ed933f894be4e6406a51baf35363d5f2
child 263762 71e6964ff7c4550417ef2d1b7d102393fc08ada2
push id15307
push userkwierso@gmail.com
push dateTue, 22 Sep 2015 23:48:18 +0000
treeherderfx-team@0f7d12dd7252 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1204540
milestone44.0a1
Bug 1204540 - Fix up spell checker tests so no content preferences are left behind. r=roc
editor/composer/nsEditorSpellCheck.cpp
editor/composer/test/chrome.ini
editor/composer/test/test_abug697981.html
editor/composer/test/test_async_UpdateCurrentDictionary.html
editor/composer/test/test_bug338427.html
editor/composer/test/test_bug678842.html
editor/composer/test/test_bug697981.html
editor/composer/test/test_bug717433.html
--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -595,18 +595,19 @@ nsEditorSpellCheck::SetCurrentDictionary
   if (!mUpdateDictionaryRunning) {
 
     // Ignore pending dictionary fetchers by increasing this number.
     mDictionaryFetcherGroup++;
 
     uint32_t flags = 0;
     mEditor->GetFlags(&flags);
     if (!(flags & nsIPlaintextEditor::eEditorMailMask)) {
-      if (mPreferredLang.IsEmpty() ||
-          !mPreferredLang.Equals(aDictionary, nsCaseInsensitiveStringComparator())) {
+      if (!aDictionary.IsEmpty() && (mPreferredLang.IsEmpty() ||
+          !mPreferredLang.Equals(aDictionary,
+                                 nsCaseInsensitiveStringComparator()))) {
         // 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",
--- a/editor/composer/test/chrome.ini
+++ b/editor/composer/test/chrome.ini
@@ -1,11 +1,11 @@
 [DEFAULT]
 skip-if = buildapp == 'b2g' || os == 'android'
 
 [test_async_UpdateCurrentDictionary.html]
 [test_bug338427.html]
 [test_bug434998.xul]
 [test_bug678842.html]
-[test_abug697981.html]
+[test_bug697981.html]
 [test_bug717433.html]
 [test_bug1204147.html]
 [test_bug1200533.html]
--- a/editor/composer/test/test_async_UpdateCurrentDictionary.html
+++ b/editor/composer/test/test_async_UpdateCurrentDictionary.html
@@ -43,18 +43,21 @@ function start() {
       // 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)
+          if (--numCalls == 0) {
+            // This will clear the content preferences and reset "spellchecker.dictionary".
+            sc.SetCurrentDictionary("");
             SimpleTest.finish();
+          }
         });
       }
       try {
         sc.SetCurrentDictionary("testing-XX");
       }
       catch (err) {
         // Set throws NS_ERROR_NOT_AVAILABLE because "testing-XX" isn't really
         // an available dictionary.
--- a/editor/composer/test/test_bug338427.html
+++ b/editor/composer/test/test_bug338427.html
@@ -37,16 +37,19 @@ function init() {
         spellchecker.spellChecker.SetCurrentDictionary(lang);
 
         onSpellCheck(textarea, function () {
             try {
                 var dictionary =
                     spellchecker.spellChecker.GetCurrentDictionary();
             } catch(e) {}
             is(dictionary, lang, "Unexpected spell check dictionary");
+
+            // This will clear the content preferences and reset "spellchecker.dictionary".
+            spellchecker.spellChecker.SetCurrentDictionary("");
             SimpleTest.finish();
         });
     });
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(init);
 
--- a/editor/composer/test/test_bug678842.html
+++ b/editor/composer/test/test_bug678842.html
@@ -80,18 +80,18 @@ var loadListener = function(evt) {
       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");
       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", "");
+      // This will clear the content preferences and reset "spellchecker.dictionary".
+      spellchecker.SetCurrentDictionary("");
       SimpleTest.finish();
     }
   });
 }
 
 content.addEventListener('load', loadListener, false);
 
 content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=true';
rename from editor/composer/test/test_abug697981.html
rename to editor/composer/test/test_bug697981.html
--- a/editor/composer/test/test_abug697981.html
+++ b/editor/composer/test/test_bug697981.html
@@ -24,21 +24,16 @@ function getMisspelledWords(editor) {
 }
 
 var elem_de;
 var editor_de;
 var de_DE;
 var hunspell;
 
 /** Test for Bug 697981 **/
-/*
- * Note the hack: This test fails of there are content preferences left behind from previous tests.
- * That's why this test resides in a file "test_abug697981.html" so it runs first.
- * We will fix this later.
- */
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(function() {
   Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
 
   var dir = Components.classes["@mozilla.org/file/directory_service;1"]
                       .getService(Components.interfaces.nsIProperties)
                       .get("CurWorkD", Components.interfaces.nsIFile);
   dir.append("tests");
--- a/editor/composer/test/test_bug717433.html
+++ b/editor/composer/test/test_bug717433.html
@@ -27,17 +27,16 @@ 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");
@@ -81,18 +80,18 @@ 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", "");
+      // This will clear the content preferences and reset "spellchecker.dictionary".
+      spellchecker.SetCurrentDictionary("");
       SimpleTest.finish();
     }
   });
 }
 
 content.addEventListener('load', loadListener, false);
 
 content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug717433_subframe.html?firstload=true';