Commit eb5fc7e6 authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Revert "[Spellcheck] Add tests for Windows hybrid spell checking"

This reverts commit f5a23de3.

Reason for revert: SpellCheckProviderTest.ShouldUseBrowserSpellCheck consistently fails on Win7 bots:
https://ci.chromium.org/p/chromium/builders/ci/Win7%20Tests%20%28dbg%29%281%29/80740
https://ci.chromium.org/p/chromium/builders/ci/Win%207%20Tests%20x64%20%281%29/62540
https://ci.chromium.org/p/chromium/builders/ci/Win7%20Tests%20%281%29/98097

Original change's description:
> [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: Rouslan Solomakhin <rouslan@chromium.org>
> Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#726150}

TBR=rouslan@chromium.org,gujen@google.com

Change-Id: I95a76a62a57a520699c01aa207c9046edbc4592a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 463364, 1035450
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975370Reviewed-by: default avatarKunihiko Sakamoto <ksakamoto@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726248}
parent 0b287621
...@@ -21,14 +21,7 @@ ...@@ -21,14 +21,7 @@
class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
public: public:
SpellCheckHostChromeImplWinBrowserTest() { SpellCheckHostChromeImplWinBrowserTest() {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
feature_list_.InitWithFeatures(
/*enabled_features=*/{spellcheck::kWinUseBrowserSpellChecker,
spellcheck::kWinUseHybridSpellChecker},
/*disabled_features=*/{});
#else
feature_list_.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker); feature_list_.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker);
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
...@@ -41,21 +34,13 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { ...@@ -41,21 +34,13 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
void TearDownOnMainThread() override { renderer_.reset(); } void TearDownOnMainThread() override { renderer_.reset(); }
void OnSpellcheckResult(const std::vector<SpellCheckResult>& result) { void LogResult(const std::vector<SpellCheckResult>& result) {
received_result_ = true; received_result_ = true;
result_ = result; result_ = result;
if (quit_) if (quit_)
std::move(quit_).Run(); 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) { void SetLanguageCompletionCallback(bool result) {
received_result_ = true; received_result_ = true;
if (quit_) if (quit_)
...@@ -80,29 +65,26 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest { ...@@ -80,29 +65,26 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
bool received_result_ = false; bool received_result_ = false;
std::vector<SpellCheckResult> result_; std::vector<SpellCheckResult> result_;
std::vector<std::vector<::base::string16>> suggestion_result_;
base::OnceClosure quit_; base::OnceClosure quit_;
}; };
// Uses browsertest to setup chrome threads. // Uses browsertest to setup chrome threads.
IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest, IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
SpellCheckReturnMessage) { SpellCheckReturnMessage) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) { if (base::win::GetVersion() < base::win::Version::WIN8)
return; return;
}
spellcheck_platform::SetLanguage( spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest:: "en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback, SetLanguageCompletionCallback,
base::Unretained(this))); base::Unretained(this)));
RunUntilResultReceived(); RunUntilResultReceived();
spell_check_host_->RequestTextCheck( spell_check_host_->RequestTextCheck(
base::UTF8ToUTF16("zz."), base::UTF8ToUTF16("zz."), 123,
/*route_id=*/123, base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::LogResult,
base::BindOnce( base::Unretained(this)));
&SpellCheckHostChromeImplWinBrowserTest::OnSpellcheckResult,
base::Unretained(this)));
RunUntilResultReceived(); RunUntilResultReceived();
ASSERT_EQ(1U, result_.size()); ASSERT_EQ(1U, result_.size());
...@@ -110,100 +92,3 @@ IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest, ...@@ -110,100 +92,3 @@ IN_PROC_BROWSER_TEST_F(SpellCheckHostChromeImplWinBrowserTest,
EXPECT_EQ(result_[0].length, 2); EXPECT_EQ(result_[0].length, 2);
EXPECT_EQ(result_[0].decoration, SpellCheckResult::SPELLING); 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,43 +102,3 @@ TEST_F(SpellcheckHostMetricsTest, RecordSpellingServiceStats) { ...@@ -102,43 +102,3 @@ TEST_F(SpellcheckHostMetricsTest, RecordSpellingServiceStats) {
histogram_tester2.ExpectBucketCount(kMetricName, 0, 0); histogram_tester2.ExpectBucketCount(kMetricName, 0, 0);
histogram_tester2.ExpectBucketCount(kMetricName, 1, 1); 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,12 +166,10 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>, ...@@ -166,12 +166,10 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>,
mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver); mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver);
// Returns the current number of spell check languages. // Returns the current number of spell check languages.
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class). size_t LanguageCount();
virtual size_t LanguageCount();
// Returns the current number of spell check languages with enabled engines. // Returns the current number of spell check languages with enabled engines.
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class). size_t EnabledLanguageCount();
virtual size_t EnabledLanguageCount();
private: private:
friend class SpellCheckTest; friend class SpellCheckTest;
......
...@@ -29,30 +29,10 @@ void FakeTextCheckingCompletion::DidCancelCheckingText() { ...@@ -29,30 +29,10 @@ void FakeTextCheckingCompletion::DidCancelCheckingText() {
++result_->cancellation_count_; ++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( TestingSpellCheckProvider::TestingSpellCheckProvider(
service_manager::LocalInterfaceProvider* embedder_provider) service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheckProvider(nullptr, : SpellCheckProvider(nullptr,
new FakeSpellCheck(embedder_provider), new SpellCheck(embedder_provider),
embedder_provider) {} embedder_provider) {}
TestingSpellCheckProvider::TestingSpellCheckProvider( TestingSpellCheckProvider::TestingSpellCheckProvider(
...@@ -147,8 +127,7 @@ void TestingSpellCheckProvider::RequestPartialTextCheck( ...@@ -147,8 +127,7 @@ void TestingSpellCheckProvider::RequestPartialTextCheck(
const std::vector<SpellCheckResult>& partial_results, const std::vector<SpellCheckResult>& partial_results,
bool fill_suggestions, bool fill_suggestions,
RequestPartialTextCheckCallback callback) { RequestPartialTextCheckCallback callback) {
partial_text_check_requests_.push_back( NOTREACHED();
std::make_pair(text, std::move(callback)));
} }
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
...@@ -171,24 +150,6 @@ bool TestingSpellCheckProvider::SatisfyRequestFromCache( ...@@ -171,24 +150,6 @@ bool TestingSpellCheckProvider::SatisfyRequestFromCache(
return SpellCheckProvider::SatisfyRequestFromCache(text, completion); 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() SpellCheckProviderTest::SpellCheckProviderTest()
: provider_(&embedder_provider_) {} : provider_(&embedder_provider_) {}
SpellCheckProviderTest::~SpellCheckProviderTest() {} SpellCheckProviderTest::~SpellCheckProviderTest() {}
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/spellcheck/renderer/empty_local_interface_provider.h" #include "components/spellcheck/renderer/empty_local_interface_provider.h"
#include "components/spellcheck/renderer/spellcheck.h"
#include "components/spellcheck/renderer/spellcheck_provider.h" #include "components/spellcheck/renderer/spellcheck_provider.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -38,28 +37,6 @@ class FakeTextCheckingCompletion : public blink::WebTextCheckingCompletion { ...@@ -38,28 +37,6 @@ class FakeTextCheckingCompletion : public blink::WebTextCheckingCompletion {
FakeTextCheckingResult* result_; 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. // Faked test target, which stores sent message for verification.
class TestingSpellCheckProvider : public SpellCheckProvider, class TestingSpellCheckProvider : public SpellCheckProvider,
public spellcheck::mojom::SpellCheckHost { public spellcheck::mojom::SpellCheckHost {
...@@ -81,45 +58,23 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -81,45 +58,23 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
bool SatisfyRequestFromCache(const base::string16& text, bool SatisfyRequestFromCache(const base::string16& text,
blink::WebTextCheckingCompletion* completion); 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) #if BUILDFLAG(USE_RENDERER_SPELLCHECKER)
void ResetResult(); void ResetResult();
// Variables logging CallSpellingService() mojo calls. // Variables logging CallSpellingService() mojo calls.
base::string16 text_; base::string16 text_;
size_t spelling_service_call_count_ = 0; size_t spelling_service_call_count_ = 0;
#endif // BUILDFLAG(USE_RENDERER_SPELLCHECKER) #endif
#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) #if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Variables logging RequestTextCheck() mojo calls. // Variables logging RequestTextCheck() mojo calls.
using RequestTextCheckParams =
std::pair<base::string16, RequestTextCheckCallback>;
std::vector<RequestTextCheckParams> text_check_requests_; std::vector<RequestTextCheckParams> text_check_requests_;
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) #endif
#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|. // Returns |spellcheck|.
FakeSpellCheck* spellcheck() { SpellCheck* spellcheck() { return spellcheck_; }
return static_cast<FakeSpellCheck*>(spellcheck_);
}
private: private:
// spellcheck::mojom::SpellCheckHost: // spellcheck::mojom::SpellCheckHost:
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "components/spellcheck/renderer/spellcheck_provider_test.h" #include "components/spellcheck/renderer/spellcheck_provider_test.h"
#include "base/strings/utf_string_conversions.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 "components/spellcheck/renderer/spellcheck.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
...@@ -15,16 +13,6 @@ ...@@ -15,16 +13,6 @@
namespace { 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 { class SpellCheckProviderCacheTest : public SpellCheckProviderTest {
protected: protected:
void UpdateCustomDictionary() { void UpdateCustomDictionary() {
...@@ -37,21 +25,6 @@ class SpellCheckProviderCacheTest : public SpellCheckProviderTest { ...@@ -37,21 +25,6 @@ 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) { TEST_F(SpellCheckProviderCacheTest, SubstringWithoutMisspellings) {
FakeTextCheckingResult result; FakeTextCheckingResult result;
FakeTextCheckingCompletion completion(&result); FakeTextCheckingCompletion completion(&result);
...@@ -104,178 +77,4 @@ TEST_F(SpellCheckProviderCacheTest, ResetCacheOnCustomDictionaryUpdate) { ...@@ -104,178 +77,4 @@ TEST_F(SpellCheckProviderCacheTest, ResetCacheOnCustomDictionaryUpdate) {
EXPECT_EQ(result.completion_count_, 0U); 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 } // 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