1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include <optional>
#include <ostream>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/supports_user_data.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/testing_pref_service.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/spellcheck/browser/spellcheck_platform.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
struct TestCase {
TestCase(
const std::string& accept_languages,
const std::vector<std::string>& spellcheck_dictionaries,
const std::vector<std::string>& expected_languages,
const std::vector<std::string>& expected_languages_used_for_spellcheck)
: accept_languages(accept_languages),
spellcheck_dictionaries(spellcheck_dictionaries) {
SpellcheckService::Dictionary dictionary;
for (const auto& language : expected_languages) {
if (!language.empty()) {
dictionary.language = language;
dictionary.used_for_spellcheck =
base::Contains(expected_languages_used_for_spellcheck, language);
expected_dictionaries.push_back(dictionary);
}
}
}
~TestCase() = default;
std::string accept_languages;
std::vector<std::string> spellcheck_dictionaries;
std::vector<SpellcheckService::Dictionary> expected_dictionaries;
};
bool operator==(const SpellcheckService::Dictionary& lhs,
const SpellcheckService::Dictionary& rhs) {
return lhs.language == rhs.language &&
lhs.used_for_spellcheck == rhs.used_for_spellcheck;
}
std::ostream& operator<<(std::ostream& out,
const SpellcheckService::Dictionary& dictionary) {
out << "{\"" << dictionary.language << "\", used_for_spellcheck="
<< (dictionary.used_for_spellcheck ? "true " : "false") << "}";
return out;
}
std::ostream& operator<<(std::ostream& out, const TestCase& test_case) {
out << "language::prefs::kAcceptLanguages=[" << test_case.accept_languages
<< "], prefs::kSpellCheckDictionaries=["
<< base::JoinString(test_case.spellcheck_dictionaries, ",")
<< "], expected=[";
for (const auto& dictionary : test_case.expected_dictionaries) {
out << dictionary << ",";
}
out << "]";
return out;
}
static std::unique_ptr<KeyedService> BuildSpellcheckService(
content::BrowserContext* profile) {
return std::make_unique<SpellcheckService>(static_cast<Profile*>(profile));
}
class SpellcheckServiceUnitTestBase : public testing::Test {
public:
SpellcheckServiceUnitTestBase() = default;
SpellcheckServiceUnitTestBase(const SpellcheckServiceUnitTestBase&) = delete;
SpellcheckServiceUnitTestBase& operator=(
const SpellcheckServiceUnitTestBase&) = delete;
~SpellcheckServiceUnitTestBase() override = default;
content::BrowserContext* browser_context() { return &profile_; }
PrefService* prefs() { return profile_.GetPrefs(); }
protected:
void SetUp() override {
// Use SetTestingFactoryAndUse to force creation and initialization.
SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildSpellcheckService));
}
content::BrowserTaskEnvironment task_environment_;
TestingProfile profile_;
};
class SpellcheckServiceUnitTest : public SpellcheckServiceUnitTestBase,
public testing::WithParamInterface<TestCase> {
private:
#if BUILDFLAG(IS_WIN)
// Tests were designed assuming Hunspell dictionary used and may fail when
// Windows spellcheck is enabled by default.
spellcheck::ScopedDisableBrowserSpellCheckerForTesting
disable_browser_spell_checker_;
#endif // BUILDFLAG(IS_WIN)
};
INSTANTIATE_TEST_SUITE_P(
TestCases,
SpellcheckServiceUnitTest,
testing::Values(
TestCase("en-JP,aa", {"aa"}, {}, {}),
TestCase("en,aa", {"aa"}, {"en"}, {}),
TestCase("en,en-JP,fr,aa", {"fr"}, {"en", "fr"}, {"fr"}),
TestCase("en,en-JP,fr,zz,en-US", {"fr"}, {"en", "fr", "en-US"}, {"fr"}),
TestCase("en,en-US,en-GB",
{"en-GB"},
{"en", "en-US", "en-GB"},
{"en-GB"}),
TestCase("en,en-US,en-AU",
{"en-AU"},
{"en", "en-US", "en-AU"},
{"en-AU"}),
TestCase("en,en-US,en-AU",
{"en-US"},
{"en", "en-US", "en-AU"},
{"en-US"}),
TestCase("en,en-US", {"en-US"}, {"en", "en-US"}, {"en-US"}),
TestCase("en,en-US,fr", {"en-US"}, {"en", "en-US", "fr"}, {"en-US"}),
TestCase("en,fr,en-US,en-AU",
{"en-US", "fr"},
{"en", "fr", "en-US", "en-AU"},
{"fr", "en-US"}),
TestCase("en-US,en", {"en-US"}, {"en-US", "en"}, {"en-US"}),
#if BUILDFLAG(IS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Scenario where user disabled the Windows spellcheck feature with some
// non-Hunspell languages set in preferences.
TestCase("fr,eu,en-US,ar",
{"fr", "eu", "en-US", "ar"},
{"fr", "en-US"},
{"fr", "en-US"}),
#endif // BUILDFLAG(IS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
TestCase("hu-HU,hr-HR", {"hr"}, {"hu", "hr"}, {"hr"})));
TEST_P(SpellcheckServiceUnitTest, GetDictionaries) {
prefs()->SetString(language::prefs::kAcceptLanguages,
GetParam().accept_languages);
base::Value::List spellcheck_dictionaries;
for (const std::string& dictionary : GetParam().spellcheck_dictionaries) {
spellcheck_dictionaries.Append(dictionary);
}
prefs()->SetList(spellcheck::prefs::kSpellCheckDictionaries,
std::move(spellcheck_dictionaries));
std::vector<SpellcheckService::Dictionary> dictionaries;
SpellcheckService::GetDictionaries(browser_context(), &dictionaries);
EXPECT_EQ(GetParam().expected_dictionaries, dictionaries);
}
#if BUILDFLAG(IS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
class SpellcheckServiceHybridUnitTestBase
: public SpellcheckServiceUnitTestBase {
public:
SpellcheckServiceHybridUnitTestBase() = default;
protected:
void SetUp() override {
InitFeatures();
// Use SetTestingFactoryAndUse to force creation and initialization.
SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildSpellcheckService));
}
virtual void InitFeatures() {}
virtual void InitializeSpellcheckService(
const std::vector<std::string>& spellcheck_languages_for_testing) {
// Fake the presence of Windows spellcheck dictionaries.
spellcheck_service_ =
SpellcheckServiceFactory::GetInstance()->GetForContext(
browser_context());
spellcheck_service_->InitWindowsDictionaryLanguages(
spellcheck_languages_for_testing);
ASSERT_TRUE(spellcheck_service_->dictionaries_loaded());
}
void RunGetDictionariesTest(
const std::string accept_languages,
const std::vector<std::string> spellcheck_dictionaries,
const std::vector<SpellcheckService::Dictionary> expected_dictionaries);
void RunDictionaryMappingTest(
const std::string full_tag,
const std::string expected_accept_language,
const std::string expected_tag_passed_to_spellcheck,
const std::string expected_accept_language_generic,
const std::string expected_tag_passed_to_spellcheck_generic);
// Used for faking the presence of Windows spellcheck dictionaries.
static const std::vector<std::string>
windows_spellcheck_languages_for_testing_;
base::test::ScopedFeatureList feature_list_;
raw_ptr<SpellcheckService> spellcheck_service_;
};
void SpellcheckServiceHybridUnitTestBase::RunGetDictionariesTest(
const std::string accept_languages,
const std::vector<std::string> spellcheck_dictionaries,
const std::vector<SpellcheckService::Dictionary> expected_dictionaries) {
prefs()->SetString(language::prefs::kAcceptLanguages, accept_languages);
base::Value::List spellcheck_dictionaries_list;
for (std::string dict : spellcheck_dictionaries) {
spellcheck_dictionaries_list.Append(dict);
}
prefs()->SetList(spellcheck::prefs::kSpellCheckDictionaries,
std::move(spellcheck_dictionaries_list));
// Simulate first-run scenario (method is normally called during browser
// start-up). If the primary accept language has no dictionary support, it is
// expected that spellchecking will be disabled for that language.
SpellcheckService::EnableFirstUserLanguageForSpellcheck(prefs());
InitializeSpellcheckService(windows_spellcheck_languages_for_testing_);
std::vector<SpellcheckService::Dictionary> dictionaries;
SpellcheckService::GetDictionaries(browser_context(), &dictionaries);
EXPECT_EQ(expected_dictionaries, dictionaries);
}
void SpellcheckServiceHybridUnitTestBase::RunDictionaryMappingTest(
const std::string full_tag,
const std::string expected_accept_language,
const std::string expected_tag_passed_to_spellcheck,
const std::string expected_accept_language_generic,
const std::string expected_tag_passed_to_spellcheck_generic) {
InitializeSpellcheckService({full_tag});
std::string supported_dictionary;
if (!expected_accept_language.empty()) {
supported_dictionary =
spellcheck_service_->GetSupportedWindowsDictionaryLanguage(
expected_accept_language);
EXPECT_FALSE(supported_dictionary.empty());
EXPECT_EQ(full_tag, supported_dictionary);
EXPECT_EQ(expected_tag_passed_to_spellcheck,
SpellcheckService::GetTagToPassToWindowsSpellchecker(
expected_accept_language, full_tag));
// Special case for Serbian. The "sr" accept language is interpreted as
// using Cyrillic script. There should be an extra entry in the windows
// dictionary map if Cyrillic windows dictionary is installed.
if (base::EqualsCaseInsensitiveASCII(
"sr-Cyrl", SpellcheckService::GetLanguageAndScriptTag(
full_tag,
/* include_script_tag= */ true))) {
EXPECT_EQ(
full_tag,
spellcheck_service_->GetSupportedWindowsDictionaryLanguage("sr"));
} else {
EXPECT_TRUE(
spellcheck_service_->GetSupportedWindowsDictionaryLanguage("sr")
.empty());
}
if (!expected_accept_language_generic.empty()) {
supported_dictionary =
spellcheck_service_->GetSupportedWindowsDictionaryLanguage(
expected_accept_language_generic);
EXPECT_FALSE(supported_dictionary.empty());
EXPECT_EQ(expected_accept_language_generic, supported_dictionary);
EXPECT_EQ(expected_tag_passed_to_spellcheck_generic,
SpellcheckService::GetTagToPassToWindowsSpellchecker(
expected_accept_language_generic, supported_dictionary));
} else {
// Should only be one entry in the map.
EXPECT_EQ(1u,
spellcheck_service_->windows_spellcheck_dictionary_map_.size());
}
} else {
// Unsupported language--should not be in map.
EXPECT_TRUE(
spellcheck_service_->windows_spellcheck_dictionary_map_.empty());
}
}
// static
const std::vector<std::string> SpellcheckServiceHybridUnitTestBase::
windows_spellcheck_languages_for_testing_ = {
"fr-FR", // Has both Windows and Hunspell support.
"es-MX", // Has both Windows and Hunspell support, but for Hunspell
// maps to es-ES.
"gl-ES", // (Galician) Has only Windows support, no Hunspell
// dictionary.
"fi-FI", // (Finnish) Has only Windows support, no Hunspell
// dictionary.
"it-IT", // Has both Windows and Hunspell support.
"pt-BR", // Has both Windows and Hunspell support.
"haw-US", // (Hawaiian) No Hunspell dictionary. Note that first two
// letters of language code are "ha," the same as Hausa.
"ast", // (Asturian) Has only Windows support, no Hunspell
// dictionary. Note that last two letters of language
// code are "st," the same as Sesotho.
"kok-Deva-IN", // Konkani (Devanagari, India)--note presence of
// script subtag.
"sr-Cyrl-ME", // Serbian (Cyrillic, Montenegro)--note presence of
// script subtag.
"sr-Latn-ME", // Serbian (Latin, Montenegro)--note presence of
// script subtag.
"ja-Latn-JP-x-ext", // Japanese with Latin script--note presence of
// private use subtag. Ignore private use
// dictionaries.
};
class GetDictionariesHybridUnitTestNoDelayInit
: public SpellcheckServiceHybridUnitTestBase,
public testing::WithParamInterface<TestCase> {
protected:
void InitFeatures() override {
// Disable kWinDelaySpellcheckServiceInit, as the case where it's enabled
// is tested in SpellcheckServiceWindowsDictionaryMappingUnitTestDelayInit.
feature_list_.InitAndDisableFeature(
spellcheck::kWinDelaySpellcheckServiceInit);
}
};
static const TestCase kHybridGetDictionariesParams[] = {
// Galician (gl) has only Windows support, no Hunspell dictionary. Croatian
// (hr) has only Hunspell support, no local Windows dictionary. First
// language is supported by windows and should be spellchecked.
TestCase("gl", {}, {"gl"}, {"gl"}),
TestCase("gl", {"gl"}, {"gl"}, {"gl"}),
TestCase("gl,hr", {}, {"gl", "hr"}, {"gl"}),
TestCase("gl,hr", {"gl"}, {"gl", "hr"}, {"gl"}),
TestCase("gl,hr", {"hr"}, {"gl", "hr"}, {"gl", "hr"}),
TestCase("gl,hr", {"gl", "hr"}, {"gl", "hr"}, {"gl", "hr"}),
TestCase("hr", {}, {"hr"}, {"hr"}),
TestCase("hr", {"hr"}, {"hr"}, {"hr"}),
TestCase("hr,gl", {"hr"}, {"hr", "gl"}, {"hr"}),
// Cebuano (ceb) is a language with neither Windows or Hunspell support,
// should be unset if was enabled during simulated "first run" scenario.
TestCase("ceb", {}, {}, {}),
TestCase("ceb,gl,hr", {"gl", "hr"}, {"gl", "hr"}, {"gl", "hr"}),
// Finnish has only "fi" in hard-coded list of accept languages.
TestCase("fi-FI,fi,en-US,en",
{"en-US"},
{"fi", "en-US", "en"},
{"fi", "en-US"}),
// First language is supported by Windows but private use dictionaries
// are ignored.
TestCase("ja,gl", {"gl"}, {"gl"}, {"gl"}),
// (Basque) No Hunspell support, has Windows support but
// language pack not present.
TestCase("eu", {"eu"}, {}, {}),
TestCase("es-419,es-MX",
{"es-419", "es-MX"},
{"es-419", "es-MX"},
{"es-419", "es-MX"}),
TestCase("fr-FR,es-MX,gl,pt-BR,hr,it",
{"fr-FR", "gl", "pt-BR", "it"},
{"fr-FR", "es-MX", "gl", "pt-BR", "hr", "it"},
{"fr-FR", "gl", "pt-BR", "it"}),
// Hausa with Hawaiian language pack (ha/haw string in string).
TestCase("ha", {"ha"}, {}, {}),
// Sesotho with Asturian language pack (st/ast string in string).
TestCase("st", {"st"}, {}, {}),
// User chose generic Serbian in languages preferences (which uses
// Cyrillic script).
TestCase("sr,sr-Latn-RS", {"sr", "sr-Latn-RS"}, {"sr"}, {"sr"}),
// If there is platform spellcheck support for a regional variation of
// a language, the generic version should also be toggleable in spellcheck
// settings. There is no Hunspell dictionary for generic Portuguese (pt);
// there is Hunspell support for generic Italian (it) but the platform
// dictionary should be used instead.
TestCase("pt,pt-BR", {"pt", "pt-BR"}, {"pt", "pt-BR"}, {"pt", "pt-BR"}),
TestCase("it,it-IT", {"it", "it-IT"}, {"it", "it-IT"}, {"it", "it-IT"}),
};
INSTANTIATE_TEST_SUITE_P(TestCases,
GetDictionariesHybridUnitTestNoDelayInit,
testing::ValuesIn(kHybridGetDictionariesParams));
TEST_P(GetDictionariesHybridUnitTestNoDelayInit, GetDictionaries) {
RunGetDictionariesTest(GetParam().accept_languages,
GetParam().spellcheck_dictionaries,
GetParam().expected_dictionaries);
}
struct DictionaryMappingTestCase {
std::string full_tag;
std::string expected_accept_language;
std::string expected_tag_passed_to_spellcheck;
std::string expected_accept_language_generic;
std::string expected_tag_passed_to_spellcheck_generic;
};
std::ostream& operator<<(std::ostream& out,
const DictionaryMappingTestCase& test_case) {
out << "full_tag=" << test_case.full_tag
<< ", expected_accept_language=" << test_case.expected_accept_language
<< ", expected_tag_passed_to_spellcheck="
<< test_case.expected_tag_passed_to_spellcheck
<< ", expected_accept_language_generic="
<< test_case.expected_accept_language_generic
<< ", expected_tag_passed_to_spellcheck_generic="
<< test_case.expected_tag_passed_to_spellcheck_generic;
return out;
}
class SpellcheckServiceWindowsDictionaryMappingUnitTest
: public SpellcheckServiceHybridUnitTestBase,
public testing::WithParamInterface<DictionaryMappingTestCase> {
protected:
void InitFeatures() override {
// Disable kWinDelaySpellcheckServiceInit, as the case where it's enabled
// is tested in SpellcheckServiceWindowsDictionaryMappingUnitTestDelayInit.
feature_list_.InitAndDisableFeature(
spellcheck::kWinDelaySpellcheckServiceInit);
}
};
static const DictionaryMappingTestCase kHybridDictionaryMappingsParams[] = {
DictionaryMappingTestCase({"en-CA", "en-CA", "en-CA", "en", "en"}),
DictionaryMappingTestCase({"en-PH", "en", "en", "", ""}),
DictionaryMappingTestCase({"es-MX", "es-MX", "es-MX", "es", "es"}),
DictionaryMappingTestCase({"ar-SA", "ar", "ar", "", ""}),
DictionaryMappingTestCase({"kok-Deva-IN", "kok", "kok-Deva", "", ""}),
DictionaryMappingTestCase({"sr-Cyrl-RS", "sr", "sr-Cyrl", "", ""}),
DictionaryMappingTestCase({"sr-Cyrl-ME", "sr", "sr-Cyrl", "", ""}),
// Only sr with Cyrillic implied supported in Chromium.
DictionaryMappingTestCase({"sr-Latn-RS", "", "sr-Latn", "", ""}),
DictionaryMappingTestCase({"sr-Latn-ME", "", "sr-Latn", "", ""}),
DictionaryMappingTestCase({"ca-ES", "ca", "ca", "", ""}),
DictionaryMappingTestCase({"ca-ES-valencia", "ca", "ca", "", ""}),
// If there is platform spellcheck support for a regional variation of
// a language, the generic version should also be toggleable in spellcheck
// settings. There is no Hunspell dictionary for generic Portuguese (pt);
// there is Hunspell support for generic Italian (it) but the platform
// dictionary should be used instead.
DictionaryMappingTestCase({"it-IT", "it-IT", "it-IT", "it", "it"}),
DictionaryMappingTestCase({"pt-BR", "pt-BR", "pt-BR", "pt", "pt"}),
};
INSTANTIATE_TEST_SUITE_P(TestCases,
SpellcheckServiceWindowsDictionaryMappingUnitTest,
testing::ValuesIn(kHybridDictionaryMappingsParams));
TEST_P(SpellcheckServiceWindowsDictionaryMappingUnitTest, CheckMappings) {
RunDictionaryMappingTest(
GetParam().full_tag, GetParam().expected_accept_language,
GetParam().expected_tag_passed_to_spellcheck,
GetParam().expected_accept_language_generic,
GetParam().expected_tag_passed_to_spellcheck_generic);
}
class SpellcheckServiceHybridUnitTestDelayInitBase
: public SpellcheckServiceHybridUnitTestBase {
public:
SpellcheckServiceHybridUnitTestDelayInitBase() = default;
void OnDictionariesInitialized() {
dictionaries_initialized_received_ = true;
if (quit_)
std::move(quit_).Run();
}
protected:
void InitFeatures() override {
// Don't initialize the SpellcheckService on browser launch.
feature_list_.InitAndEnableFeature(
spellcheck::kWinDelaySpellcheckServiceInit);
}
void InitializeSpellcheckService(
const std::vector<std::string>& spellcheck_languages_for_testing)
override {
// Fake the presence of Windows spellcheck dictionaries.
spellcheck_service_ =
SpellcheckServiceFactory::GetInstance()->GetForContext(
browser_context());
spellcheck_service_->AddSpellcheckLanguagesForTesting(
spellcheck_languages_for_testing);
// Asynchronously load the dictionaries.
ASSERT_FALSE(spellcheck_service_->dictionaries_loaded());
spellcheck_service_->InitializeDictionaries(
base::BindOnce(&SpellcheckServiceHybridUnitTestDelayInitBase::
OnDictionariesInitialized,
base::Unretained(this)));
RunUntilCallbackReceived();
ASSERT_TRUE(spellcheck_service_->dictionaries_loaded());
}
void RunUntilCallbackReceived() {
if (dictionaries_initialized_received_)
return;
base::RunLoop run_loop;
quit_ = run_loop.QuitClosure();
run_loop.Run();
// reset status.
dictionaries_initialized_received_ = false;
}
private:
bool dictionaries_initialized_received_ = false;
// Quits the RunLoop on receiving the callback from InitializeDictionaries.
base::OnceClosure quit_;
};
class SpellcheckServiceHybridUnitTestDelayInit
: public SpellcheckServiceHybridUnitTestDelayInitBase,
public testing::WithParamInterface<TestCase> {};
INSTANTIATE_TEST_SUITE_P(TestCases,
SpellcheckServiceHybridUnitTestDelayInit,
testing::ValuesIn(kHybridGetDictionariesParams));
TEST_P(SpellcheckServiceHybridUnitTestDelayInit, GetDictionaries) {
RunGetDictionariesTest(GetParam().accept_languages,
GetParam().spellcheck_dictionaries,
GetParam().expected_dictionaries);
}
class SpellcheckServiceWindowsDictionaryMappingUnitTestDelayInit
: public SpellcheckServiceHybridUnitTestDelayInitBase,
public testing::WithParamInterface<DictionaryMappingTestCase> {};
INSTANTIATE_TEST_SUITE_P(
TestCases,
SpellcheckServiceWindowsDictionaryMappingUnitTestDelayInit,
testing::ValuesIn(kHybridDictionaryMappingsParams));
TEST_P(SpellcheckServiceWindowsDictionaryMappingUnitTestDelayInit,
CheckMappings) {
RunDictionaryMappingTest(
GetParam().full_tag, GetParam().expected_accept_language,
GetParam().expected_tag_passed_to_spellcheck,
GetParam().expected_accept_language_generic,
GetParam().expected_tag_passed_to_spellcheck_generic);
}
#endif // BUILDFLAG(IS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|