Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc

Issue 11414282: Improve reliability of custom spelling dictionary file. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_custom_dictionary.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
index 1073440e3fa73bf8c75ab05ce0d1493e56f66ebd..c890afcaa654000c8bbbc5d2976d013fce33c5bf 100644
--- a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
@@ -4,9 +4,11 @@
#include <vector>
+#include "base/file_util.h"
#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
+#include "chrome/common/chrome_constants.h"
#include "chrome/common/spellcheck_common.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
@@ -164,3 +166,105 @@ TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
// TearDown();
MessageLoop::current()->RunUntilIdle();
}
+
+// Legacy empty dictionary should be converted to new format empty dicitonary.
+TEST_F(SpellcheckCustomDictionaryTest, LegacyEmptyDictionaryShouldBeConverted) {
+ FilePath dictionary_path(
+ profile_->GetPath().Append(chrome::kCustomDictionaryFileName));
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ WordList loaded_custom_words;
+
+ std::string content;
+ file_util::WriteFile(dictionary_path, content.c_str(), content.length());
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ EXPECT_TRUE(loaded_custom_words.empty());
+
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
+
+// Legacy dictionary with two words should be converted to new format dictionary
+// with two words.
+TEST_F(SpellcheckCustomDictionaryTest,
+ LegacyDictionaryWithTwoWordsShouldBeConverted) {
+ FilePath dictionary_path(
+ profile_->GetPath().Append(chrome::kCustomDictionaryFileName));
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ WordList loaded_custom_words;
+ WordList expected;
+
+ std::string content = "foo\nbar";
+ file_util::WriteFile(dictionary_path, content.c_str(), content.length());
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ expected.push_back("bar");
+ expected.push_back("foo");
+ EXPECT_EQ(expected, loaded_custom_words);
+
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
+
+// Words with spaces are illegal and should be removed.
+TEST_F(SpellcheckCustomDictionaryTest,
+ IllegalWordsShouldBeRemovedFromDictionary) {
+ FilePath dictionary_path(
+ profile_->GetPath().Append(chrome::kCustomDictionaryFileName));
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ WordList loaded_custom_words;
+ WordList expected;
+
+ std::string content = "foo\nfoo bar\nbar\nfoo bar";
+ file_util::WriteFile(dictionary_path, content.c_str(), content.length());
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ expected.push_back("bar");
+ expected.push_back("foo");
+ EXPECT_EQ(expected, loaded_custom_words);
+
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
+
+// Write to dicitonary should backup previous version and write the word to the
+// end of the dictionary. If the dictionary file is corrupted on disk, the
+// previous version should be reloaded.
+TEST_F(SpellcheckCustomDictionaryTest, CorruptedWriteShouldBeRecovered) {
+ FilePath dictionary_path(
+ profile_->GetPath().Append(chrome::kCustomDictionaryFileName));
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ WordList loaded_custom_words;
+ WordList expected;
+
+ std::string content = "foo\nbar";
+ file_util::WriteFile(dictionary_path, content.c_str(), content.length());
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ expected.push_back("bar");
+ expected.push_back("foo");
+ EXPECT_EQ(expected, loaded_custom_words);
+
+ custom_dictionary->WriteWordToCustomDictionary("baz");
+ content.clear();
+ file_util::ReadFileToString(dictionary_path, &content);
+ content.append("corruption");
+ file_util::WriteFile(dictionary_path, content.c_str(), content.length());
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ EXPECT_EQ(expected, loaded_custom_words);
+
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_custom_dictionary.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698