chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
// 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.
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.
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);
  MessageLoop::current()->RunUntilIdle();
}
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 = " \n " ; file_util :: WriteFile ( dictionary_path , content . c_str ( ) , content . length ( ) ) ; custom_dictionary -> LoadDictionaryIntoCustomWordList ( & loaded_custom_words ) ; expected . push_back ( " " ) ; expected . push_back ( " " ) ; EXPECT_EQ ( expected , loaded_custom_words ) ; custom_dictionary -> WriteWordToCustomDictionary ( " " ) ; content . clear ( ) ; file_util :: ReadFileToString ( dictionary_path , & content ) ; content . append ( " " ) ; file_util :: WriteFile ( dictionary_path , content . c_str ( ) , content . length ( ) ) ; custom_dictionary -> LoadDictionaryIntoCustomWordList ( & loaded_custom_words ) ; EXPECT_EQ ( expected , loaded_custom_words ) ; MessageLoop :: current ( ) -> RunUntilIdle ( ) ; }
Write to dicitonary should backup previous version and write the word to the
end of the dictionary.
Write to dicitonary should backup previous version and write the word to the end of the dictionary .
// Flush the loop now to prevent service init tasks from being run during // TearDown();