Commit e7f35a93 authored by Konstantin Ganenko's avatar Konstantin Ganenko Committed by Commit Bot

Fix first word spellcheck.

Do not process pending request if initialize call is come with not inited
 dictionaries.

R=groby@chromium.org

Bug: 850424
Change-Id: I0dd7213f9865b2c5949fd6367c524edfd09febf1
Reviewed-on: https://chromium-review.googlesource.com/1085449
Commit-Queue: Rachel Blum <groby@chromium.org>
Reviewed-by: default avatarRachel Blum <groby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585283}
parent 4a7b10c2
......@@ -216,7 +216,8 @@ void SpellCheck::Initialize(
custom_dictionary_.Init(
std::set<std::string>(custom_words.begin(), custom_words.end()));
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
PostDelayedSpellCheckTask(pending_request_param_.release());
if (!InitializeIfNeeded())
PostDelayedSpellCheckTask(pending_request_param_.release());
#endif
spellcheck_enabled_ = enable;
......
......@@ -56,7 +56,7 @@ class SpellCheckTest : public testing::Test {
void ReinitializeSpellCheck(const std::string& language) {
UninitializeSpellCheck();
InitializeSpellCheck(language);
InitializeSpellCheck({language});
}
void UninitializeSpellCheck() {
......@@ -66,24 +66,40 @@ class SpellCheckTest : public testing::Test {
bool InitializeIfNeeded() {
return spell_check()->InitializeIfNeeded();
}
void InitializeSpellCheck(const std::string& language) {
base::FilePath hunspell_directory = GetHunspellDirectory();
EXPECT_FALSE(hunspell_directory.empty());
base::File file(
spellcheck::GetVersionedFileName(language, hunspell_directory),
base::File::FLAG_OPEN | base::File::FLAG_READ);
#if defined(OS_MACOSX)
void InitializeSpellCheck(const std::vector<std::string>& languages) {
// TODO(groby): Forcing spellcheck to use hunspell, even on OSX.
// Instead, tests should exercise individual spelling engines.
spell_check_->languages_.push_back(
std::make_unique<SpellcheckLanguage>(&embedder_provider_));
spell_check_->languages_.front()->platform_spelling_engine_ =
std::make_unique<HunspellEngine>(&embedder_provider_);
spell_check_->languages_.front()->Init(std::move(file), language);
for (const auto& language : languages) {
spell_check_->languages_.push_back(
std::make_unique<SpellcheckLanguage>(&embedder_provider_));
spell_check_->languages_.front()->platform_spelling_engine_ =
std::make_unique<HunspellEngine>(&embedder_provider_);
spell_check_->languages_.front()->Init(GetDictionaryFile(language),
language);
}
}
#else
spell_check_->AddSpellcheckLanguage(std::move(file), language);
void InitializeSpellCheck(const std::vector<std::string>& languages) {
std::vector<spellcheck::mojom::SpellCheckBDictLanguagePtr> dictionaries;
for (const auto& language : languages) {
dictionaries.push_back(spellcheck::mojom::SpellCheckBDictLanguage::New(
GetDictionaryFile(language), language));
}
spell_check_->Initialize(std::move(dictionaries), {}, true);
}
#endif
void InitializeSpellCheckWithNoDictionaries() {
spell_check_->Initialize({}, {}, true);
}
base::File GetDictionaryFile(const std::string& language) const {
base::FilePath hunspell_directory = GetHunspellDirectory();
EXPECT_FALSE(hunspell_directory.empty());
return base::File(
spellcheck::GetVersionedFileName(language, hunspell_directory),
base::File::FLAG_OPEN | base::File::FLAG_READ);
}
~SpellCheckTest() override {}
......@@ -1100,12 +1116,14 @@ TEST_F(SpellCheckTest, RequestSpellCheckMultipleTimesWithoutInitialization) {
EXPECT_EQ(completion[i].completion_count_, 1U);
EXPECT_EQ(completion[2].completion_count_, 0U);
// Checks the last request is processed after initialization.
InitializeSpellCheck("en-US");
// Last request without dictionaries will not process.
InitializeSpellCheckWithNoDictionaries();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(completion[2].completion_count_, 0U);
// Last request is processed after initialization with valid dictionaries.
InitializeSpellCheck({"en-US"});
// Calls PostDelayedSpellCheckTask instead of OnInit here for simplicity.
spell_check()->PostDelayedSpellCheckTask(
spell_check()->pending_request_param_.release());
base::RunLoop().RunUntilIdle();
for (int i = 0; i < 3; ++i)
EXPECT_EQ(completion[i].completion_count_, 1U);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment