Commit f5a23de3 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[Spellcheck] Add tests for Windows hybrid spell checking

Adds tests for the Hunspell fallback logic (Windows hybrid spell checking)
submitted here:
https://chromium-review.googlesource.com/c/chromium/src/+/1918277

- Adds browser tests for SpellCheckHostChromeImpl
- Adds component tests for the new SpellcheckHostMetrics
- Adds component test coverage for the new SpellcheckPlatform methods in the
  Windows platform test
    - Created a bug to track splitting the single test into multiple ones
- Adds component tests for SpellcheckProvider
    - Creates a new FakeSpellCheck class to fake the count of enabled spell
      check locales, which is needed to control when to call into the
      browser spell checker

Bug: 463364, 1035450
Change-Id: Ie3e692c0d5d5970ed2ab7612018198bf42049139
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972573
Auto-Submit: Guillaume Jenkins <gujen@google.com>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726150}
parent f267f07d
......@@ -21,7 +21,14 @@
class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
public:
SpellCheckHostChromeImplWinBrowserTest() {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
feature_list_.InitWithFeatures(
/*enabled_features=*/{spellcheck::kWinUseBrowserSpellChecker,
spellcheck::kWinUseHybridSpellChecker},
/*disabled_features=*/{});
#else
feature_list_.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker);
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
}
void SetUpOnMainThread() override {
......@@ -34,13 +41,21 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
void TearDownOnMainThread() override { renderer_.reset(); }
void LogResult(const std::vector<SpellCheckResult>& result) {
void OnSpellcheckResult(const std::vector<SpellCheckResult>& result) {
received_result_ = true;
result_ = result;
if (quit_)
std::move(quit_).Run();
}
void OnSuggestionResult(
const std::vector<std::vector<::base::string16>>& suggestions) {
received_result_ = true;
suggestion_result_ = suggestions;
if (quit_)
std::move(quit_).Run();
}
void SetLanguageCompletionCallback(bool result) {
received_result_ = true;
if (quit_)
......@@ -65,26 +80,29 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
bool received_result_ = false;
std::vector<SpellCheckResult> result_;
std::vector<std::vector<::base::string16>> suggestion_result_;
base::OnceClosure quit_;
};
// Uses browsertest to setup chrome threads.
IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
SpellCheckReturnMessage) {
if (base::win::GetVersion() < base::win::Version::WIN8)
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
spell_check_host_->RequestTextCheck(
base::UTF8ToUTF16("zz."), 123,
base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::LogResult,
base::Unretained(this)));
base::UTF8ToUTF16("zz."),
/*route_id=*/123,
base::BindOnce(
&SpellCheckHostChromeImplWinBrowserTest::OnSpellcheckResult,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_EQ(1U, result_.size());
......@@ -92,3 +110,100 @@ IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
EXPECT_EQ(result_[0].length, 2);
EXPECT_EQ(result_[0].decoration, SpellCheckResult::SPELLING);
}
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
WithPartialResults) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
// Fake renderer results: "tihs" is misspelled but pretend "wrod" isn't
std::vector<SpellCheckResult> renderer_results;
renderer_results.push_back(
SpellCheckResult(SpellCheckResult::SPELLING, 0, 4));
spell_check_host_->RequestPartialTextCheck(
base::UTF8ToUTF16("tihs is a word wrod."),
/*route_id=*/123, renderer_results,
/*fill_suggestions=*/false,
base::BindOnce(
&SpellCheckHostChromeImplWinBrowserTest::OnSpellcheckResult,
base::Unretained(this)));
RunUntilResultReceived();
// Only "tihs" should be found, since "wrod" was deemed correct by the
// renderer
ASSERT_EQ(1U, result_.size());
EXPECT_EQ(result_[0].location, 0);
EXPECT_EQ(result_[0].length, 4);
EXPECT_EQ(result_[0].decoration, SpellCheckResult::SPELLING);
}
IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
WithoutPartialResults) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
// Empty renderer results
std::vector<SpellCheckResult> renderer_results;
spell_check_host_->RequestPartialTextCheck(
base::UTF8ToUTF16("tihs is a wrod."),
/*route_id=*/123, renderer_results,
/*fill_suggestions=*/true,
base::BindOnce(
&SpellCheckHostChromeImplWinBrowserTest::OnSpellcheckResult,
base::Unretained(this)));
RunUntilResultReceived();
// Both "tihs" and "wrod" should be detected, and should have replacement
// suggestions
ASSERT_EQ(2U, result_.size());
EXPECT_EQ(result_[0].location, 0);
EXPECT_EQ(result_[0].length, 4);
EXPECT_EQ(result_[0].decoration, SpellCheckResult::SPELLING);
EXPECT_GT(result_[0].replacements.size(), 0U);
EXPECT_EQ(result_[1].location, 10);
EXPECT_EQ(result_[1].length, 4);
EXPECT_EQ(result_[1].decoration, SpellCheckResult::SPELLING);
EXPECT_GT(result_[1].replacements.size(), 0U);
}
IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
PerLanguageSuggestions) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
spell_check_host_->GetPerLanguageSuggestions(
base::UTF8ToUTF16("tihs"),
base::BindOnce(
&SpellCheckHostChromeImplWinBrowserTest::OnSuggestionResult,
base::Unretained(this)));
RunUntilResultReceived();
// Should have 1 vector of results, which contains at least 1 suggestion
ASSERT_EQ(1U, suggestion_result_.size());
EXPECT_GT(suggestion_result_[0].size(), 0U);
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
......@@ -102,3 +102,43 @@ TEST_F(SpellcheckHostMetricsTest, RecordSpellingServiceStats) {
histogram_tester2.ExpectBucketCount(kMetricName, 0, 0);
histogram_tester2.ExpectBucketCount(kMetricName, 1, 1);
}
#if defined(OS_WIN)
TEST_F(SpellcheckHostMetricsTest, RecordAcceptLanguageStats) {
const char* const histogram_names[] = {
"Spellcheck.Windows.ChromeLocalesSupport.Both",
"Spellcheck.Windows.ChromeLocalesSupport.HunspellOnly",
"Spellcheck.Windows.ChromeLocalesSupport.NativeOnly",
"Spellcheck.Windows.ChromeLocalesSupport.NoSupport"};
const int expected_counts[] = {1, 2, 3, 4};
base::HistogramTester histogram_tester;
metrics()->RecordAcceptLanguageStats({expected_counts[0], expected_counts[1],
expected_counts[2],
expected_counts[3]});
for (size_t i = 0; i < base::size(histogram_names); ++i) {
histogram_tester.ExpectTotalCount(histogram_names[i], 1);
histogram_tester.ExpectBucketCount(histogram_names[i], expected_counts[i],
1);
}
}
TEST_F(SpellcheckHostMetricsTest, RecordSpellcheckLanguageStats) {
const char* const histogram_names[] = {
"Spellcheck.Windows.SpellcheckLocalesSupport.Both",
"Spellcheck.Windows.SpellcheckLocalesSupport.HunspellOnly",
"Spellcheck.Windows.SpellcheckLocalesSupport.NativeOnly"};
const int expected_counts[] = {1, 2, 3};
base::HistogramTester histogram_tester;
metrics()->RecordSpellcheckLanguageStats(
{expected_counts[0], expected_counts[1], expected_counts[2], 0});
for (size_t i = 0; i < base::size(histogram_names); ++i) {
histogram_tester.ExpectTotalCount(histogram_names[i], 1);
histogram_tester.ExpectBucketCount(histogram_names[i], expected_counts[i],
1);
}
}
#endif // defined(OS_WIN)
......@@ -166,10 +166,12 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>,
mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver);
// Returns the current number of spell check languages.
size_t LanguageCount();
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class).
virtual size_t LanguageCount();
// Returns the current number of spell check languages with enabled engines.
size_t EnabledLanguageCount();
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class).
virtual size_t EnabledLanguageCount();
private:
friend class SpellCheckTest;
......
......@@ -29,10 +29,30 @@ void FakeTextCheckingCompletion::DidCancelCheckingText() {
++result_->cancellation_count_;
}
FakeSpellCheck::FakeSpellCheck(
service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheck(embedder_provider) {}
void FakeSpellCheck::SetFakeLanguageCounts(size_t language_count,
size_t enabled_count) {
use_fake_counts_ = true;
language_count_ = language_count;
enabled_language_count_ = enabled_count;
}
size_t FakeSpellCheck::LanguageCount() {
return use_fake_counts_ ? language_count_ : SpellCheck::LanguageCount();
}
size_t FakeSpellCheck::EnabledLanguageCount() {
return use_fake_counts_ ? enabled_language_count_
: SpellCheck::EnabledLanguageCount();
}
TestingSpellCheckProvider::TestingSpellCheckProvider(
service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheckProvider(nullptr,
new SpellCheck(embedder_provider),
new FakeSpellCheck(embedder_provider),
embedder_provider) {}
TestingSpellCheckProvider::TestingSpellCheckProvider(
......@@ -127,7 +147,8 @@ void TestingSpellCheckProvider::RequestPartialTextCheck(
const std::vector<SpellCheckResult>& partial_results,
bool fill_suggestions,
RequestPartialTextCheckCallback callback) {
NOTREACHED();
partial_text_check_requests_.push_back(
std::make_pair(text, std::move(callback)));
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
......@@ -150,6 +171,24 @@ bool TestingSpellCheckProvider::SatisfyRequestFromCache(
return SpellCheckProvider::SatisfyRequestFromCache(text, completion);
}
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
int TestingSpellCheckProvider::AddCompletionForTest(
std::unique_ptr<FakeTextCheckingCompletion> completion) {
return SpellCheckProvider::text_check_completions_.Add(std::move(completion));
}
void TestingSpellCheckProvider::HybridSpellCheckParagraphComplete(
const base::string16& text,
int request_id,
std::vector<SpellCheckResult> renderer_results) {
if (!receiver_.is_bound())
SetSpellCheckHostForTesting(receiver_.BindNewPipeAndPassRemote());
SpellCheckProvider::HybridSpellCheckParagraphComplete(
text, request_id, std::move(renderer_results));
base::RunLoop().RunUntilIdle();
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
SpellCheckProviderTest::SpellCheckProviderTest()
: provider_(&embedder_provider_) {}
SpellCheckProviderTest::~SpellCheckProviderTest() {}
......@@ -12,6 +12,7 @@
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/spellcheck/renderer/empty_local_interface_provider.h"
#include "components/spellcheck/renderer/spellcheck.h"
#include "components/spellcheck/renderer/spellcheck_provider.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -37,6 +38,28 @@ class FakeTextCheckingCompletion : public blink::WebTextCheckingCompletion {
FakeTextCheckingResult* result_;
};
// A fake SpellCheck object which can fake the number of (enabled) spell check
// languages
class FakeSpellCheck : public SpellCheck {
public:
explicit FakeSpellCheck(
service_manager::LocalInterfaceProvider* embedder_provider);
// Test-only method to set the fake language counts
void SetFakeLanguageCounts(size_t language_count, size_t enabled_count);
// Returns the current number of spell check languages.
size_t LanguageCount() override;
// Returns the current number of spell check languages with enabled engines.
size_t EnabledLanguageCount() override;
private:
bool use_fake_counts_ = false;
size_t language_count_ = 0;
size_t enabled_language_count_ = 0;
};
// Faked test target, which stores sent message for verification.
class TestingSpellCheckProvider : public SpellCheckProvider,
public spellcheck::mojom::SpellCheckHost {
......@@ -58,23 +81,45 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
bool SatisfyRequestFromCache(const base::string16& text,
blink::WebTextCheckingCompletion* completion);
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
int AddCompletionForTest(
std::unique_ptr<FakeTextCheckingCompletion> completion);
void HybridSpellCheckParagraphComplete(
const base::string16& text,
const int request_id,
std::vector<SpellCheckResult> renderer_results);
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#if BUILDFLAG(USE_RENDERER_SPELLCHECKER)
void ResetResult();
// Variables logging CallSpellingService() mojo calls.
base::string16 text_;
size_t spelling_service_call_count_ = 0;
#endif
#endif // BUILDFLAG(USE_RENDERER_SPELLCHECKER)
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Variables logging RequestTextCheck() mojo calls.
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) || \
BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
using RequestTextCheckParams =
std::pair<base::string16, RequestTextCheckCallback>;
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) ||
// BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Variables logging RequestTextCheck() mojo calls.
std::vector<RequestTextCheckParams> text_check_requests_;
#endif
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
// Variables logging RequestPartialTextCheck() mojo calls.
std::vector<RequestTextCheckParams> partial_text_check_requests_;
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
// Returns |spellcheck|.
SpellCheck* spellcheck() { return spellcheck_; }
FakeSpellCheck* spellcheck() {
return static_cast<FakeSpellCheck*>(spellcheck_);
}
private:
// spellcheck::mojom::SpellCheckHost:
......
......@@ -5,6 +5,8 @@
#include "components/spellcheck/renderer/spellcheck_provider_test.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "components/spellcheck/renderer/spellcheck.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_string.h"
......@@ -13,6 +15,16 @@
namespace {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
struct HybridSpellCheckTestCase {
size_t language_count;
size_t enabled_language_count;
size_t result_size;
size_t expected_completion_count;
size_t expected_partial_request_count;
};
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
class SpellCheckProviderCacheTest : public SpellCheckProviderTest {
protected:
void UpdateCustomDictionary() {
......@@ -25,6 +37,21 @@ class SpellCheckProviderCacheTest : public SpellCheckProviderTest {
}
};
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
// Test fixture for the hybrid check callback test cases.
class HybridCheckCallbackTest
: public testing::TestWithParam<HybridSpellCheckTestCase> {
public:
HybridCheckCallbackTest() : provider_(&embedder_provider_) {}
~HybridCheckCallbackTest() override {}
protected:
base::test::SingleThreadTaskEnvironment task_environment_;
spellcheck::EmptyLocalInterfaceProvider embedder_provider_;
TestingSpellCheckProvider provider_;
};
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
TEST_F(SpellCheckProviderCacheTest, SubstringWithoutMisspellings) {
FakeTextCheckingResult result;
FakeTextCheckingCompletion completion(&result);
......@@ -77,4 +104,178 @@ TEST_F(SpellCheckProviderCacheTest, ResetCacheOnCustomDictionaryUpdate) {
EXPECT_EQ(result.completion_count_, 0U);
}
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
// Tests that the SpellCheckProvider does not call into the native spell checker
// on Windows when the native spell checker flags are disabled.
TEST_F(SpellCheckProviderTest, ShouldNotUseBrowserSpellCheck) {
base::test::ScopedFeatureList local_feature;
local_feature.InitAndDisableFeature(spellcheck::kWinUseBrowserSpellChecker);
FakeTextCheckingResult completion;
base::string16 text = base::ASCIIToUTF16("This is a test");
provider_.RequestTextChecking(
text, std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 1U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(completion.completion_count_, 1U);
EXPECT_EQ(completion.cancellation_count_, 0U);
}
// Tests that the SpellCheckProvider calls into the native spell checker when
// the browser spell checker flag is enabled, but the hybrid spell checker flag
// isn't.
TEST_F(SpellCheckProviderTest, ShouldUseBrowserSpellCheck) {
base::test::ScopedFeatureList local_features;
local_features.InitWithFeatures({spellcheck::kWinUseBrowserSpellChecker},
{spellcheck::kWinUseHybridSpellChecker});
FakeTextCheckingResult completion;
base::string16 text = base::ASCIIToUTF16("This is a test");
provider_.RequestTextChecking(
text, std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 1U);
EXPECT_EQ(completion.completion_count_, 0U);
EXPECT_EQ(completion.cancellation_count_, 0U);
}
// Tests that the SpellCheckProvider calls into the native spell checker only
// when needed.
TEST_F(SpellCheckProviderTest, ShouldRequestBrowserCheckWhenNeeded) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
base::test::ScopedFeatureList local_features;
local_features.InitWithFeatures(
/*enabled_features=*/{spellcheck::kWinUseBrowserSpellChecker,
spellcheck::kWinUseHybridSpellChecker},
/*disabled_features=*/{});
FakeTextCheckingResult completion;
// No languages - should go straight to completion
provider_.spellcheck()->SetFakeLanguageCounts(0U, 0U);
provider_.RequestTextChecking(
base::ASCIIToUTF16("First"),
std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(provider_.partial_text_check_requests_.size(), 0U);
EXPECT_EQ(completion.completion_count_, 1U);
EXPECT_EQ(completion.cancellation_count_, 0U);
// Added 1 disabled spell check language - should go to browser
provider_.spellcheck()->SetFakeLanguageCounts(1U, 0U);
provider_.RequestTextChecking(
base::ASCIIToUTF16("Second"),
std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(provider_.partial_text_check_requests_.size(), 1U);
EXPECT_EQ(completion.completion_count_, 1U);
EXPECT_EQ(completion.cancellation_count_, 0U);
// Enabled the only language - should go straight to completion
provider_.spellcheck()->SetFakeLanguageCounts(1U, 1U);
provider_.RequestTextChecking(
base::ASCIIToUTF16("Third"),
std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(provider_.partial_text_check_requests_.size(), 1U);
EXPECT_EQ(completion.completion_count_, 2U);
EXPECT_EQ(completion.cancellation_count_, 0U);
// Added 2 more enabled languages - should go straight to completion
provider_.spellcheck()->SetFakeLanguageCounts(3U, 3U);
provider_.RequestTextChecking(
base::ASCIIToUTF16("Fourth"),
std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(provider_.partial_text_check_requests_.size(), 1U);
EXPECT_EQ(completion.completion_count_, 3U);
EXPECT_EQ(completion.cancellation_count_, 0U);
// Disabled all 3 languages - should go to browser
provider_.spellcheck()->SetFakeLanguageCounts(3U, 0U);
provider_.RequestTextChecking(
base::ASCIIToUTF16("Fifth"),
std::make_unique<FakeTextCheckingCompletion>(&completion));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(provider_.partial_text_check_requests_.size(), 2U);
EXPECT_EQ(completion.completion_count_, 3U);
EXPECT_EQ(completion.cancellation_count_, 0U);
}
// Tests that the HybridSpellCheckParagraphComplete() callback performs the
// browser check only when needed.
INSTANTIATE_TEST_SUITE_P(
SpellCheckProviderHybridCallbackTests,
HybridCheckCallbackTest,
testing::Values(
// No languages, no results - should skip browser
HybridSpellCheckTestCase{0U, 0U, 0U, 1U, 0U},
// 1 disabled language, no results - should go to browser
HybridSpellCheckTestCase{1U, 0U, 0U, 0U, 1U},
// 1 enabled language, no results - should skip browser
// TODO(gujen) Enable this case when b/1034043 is fixed
// HybridSpellCheckTestCase{1U, 1U, 0U, 1U, 0U},
// 2 disabled languages, 1 enabled, no results - should skip the browser
// TODO(gujen) Enable this case when b/1034043 is fixed
// HybridSpellCheckTestCase{3U, 1U, 0U, 1U, 0U},
// 3 enabled languages, no results - should skip browser
HybridSpellCheckTestCase{3U, 3U, 0U, 1U, 0U},
// 3 disabled languages, no results - should go to browser
HybridSpellCheckTestCase{3U, 0U, 0U, 0U, 1U},
// 1 enabled language, some results - should skip browser
HybridSpellCheckTestCase{1U, 1U, 3U, 1U, 0U},
// 3 enabled language, some results - should skip browser
HybridSpellCheckTestCase{3U, 3U, 2U, 1U, 0U},
// 2 disabled languages, 1 enabled, some results - should go to browser
HybridSpellCheckTestCase{3U, 1U, 4U, 0U, 1U}));
TEST_P(HybridCheckCallbackTest,
HybridCallbackShouldRequestBrowserCheckWhenNeeded) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
const auto& test_case = GetParam();
base::test::ScopedFeatureList local_features;
local_features.InitWithFeatures({spellcheck::kWinUseBrowserSpellChecker,
spellcheck::kWinUseHybridSpellChecker},
{});
FakeTextCheckingResult completion;
base::string16 text = base::ASCIIToUTF16("This is a test");
provider_.spellcheck()->SetFakeLanguageCounts(
test_case.language_count, test_case.enabled_language_count);
int check_id = provider_.AddCompletionForTest(
std::make_unique<FakeTextCheckingCompletion>(&completion));
std::vector<SpellCheckResult> results(test_case.result_size,
SpellCheckResult());
provider_.HybridSpellCheckParagraphComplete(std::move(text), check_id,
std::move(results));
EXPECT_EQ(provider_.spelling_service_call_count_, 0U);
EXPECT_EQ(provider_.text_check_requests_.size(), 0U);
EXPECT_EQ(completion.completion_count_, test_case.expected_completion_count);
EXPECT_EQ(provider_.partial_text_check_requests_.size(),
test_case.expected_partial_request_count);
EXPECT_EQ(completion.cancellation_count_, 0U);
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
} // namespace
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