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 @@
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 {
......@@ -41,21 +34,13 @@ class SpellCheckHostChromeImplWinBrowserTest : public InProcessBrowserTest {
void TearDownOnMainThread() override { renderer_.reset(); }
void OnSpellcheckResult(const std::vector<SpellCheckResult>& result) {
void LogResult(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_)
......@@ -80,29 +65,26 @@ 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 (!spellcheck::WindowsVersionSupportsSpellchecker()) {
if (base::win::GetVersion() < base::win::Version::WIN8)
return;
}
spellcheck_platform::SetLanguage(
"en-US", base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::
SetLanguageCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
spell_check_host_->RequestTextCheck(
base::UTF8ToUTF16("zz."),
/*route_id=*/123,
base::BindOnce(
&SpellCheckHostChromeImplWinBrowserTest::OnSpellcheckResult,
base::Unretained(this)));
base::UTF8ToUTF16("zz."), 123,
base::BindOnce(&SpellCheckHostChromeImplWinBrowserTest::LogResult,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_EQ(1U, result_.size());
......@@ -110,100 +92,3 @@ 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,43 +102,3 @@ 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)
......@@ -50,14 +50,6 @@ class SpellcheckPlatformWinTest : public testing::Test {
std::move(quit_).Run();
}
void GetSuggestionsCompletionCallback(
const spellcheck::PerLanguageSuggestions& suggestions) {
callback_finished_ = true;
spell_check_suggestions_ = suggestions;
if (quit_)
std::move(quit_).Run();
}
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void RetrieveSupportedWindowsPreferredLanguagesCallback(
const std::vector<std::string>& preferred_languages) {
......@@ -73,169 +65,11 @@ class SpellcheckPlatformWinTest : public testing::Test {
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
// TODO(crbug.com/1035044) Make these methods actual tests. See the
// task_environment_ comment below.
void RequestTextCheckTests() {
static const struct {
const char* text_to_check;
const char* expected_suggestion;
} kTestCases[] = {
{"absense", "absence"}, {"becomeing", "becoming"},
{"cieling", "ceiling"}, {"definate", "definite"},
{"eigth", "eight"}, {"exellent", "excellent"},
{"finaly", "finally"}, {"garantee", "guarantee"},
{"humerous", "humorous"}, {"imediately", "immediately"},
{"jellous", "jealous"}, {"knowlege", "knowledge"},
{"lenght", "length"}, {"manuever", "maneuver"},
{"naturaly", "naturally"}, {"ommision", "omission"},
};
for (size_t i = 0; i < base::size(kTestCases); ++i) {
const auto& test_case = kTestCases[i];
const base::string16 word(base::ASCIIToUTF16(test_case.text_to_check));
// Check if the suggested words occur.
spellcheck_platform::RequestTextCheck(
1, word,
base::BindOnce(
&SpellcheckPlatformWinTest::TextCheckCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_EQ(1u, spell_check_results_.size())
<< "RequestTextCheckTests case " << i << ": Wrong number of results";
const std::vector<base::string16>& suggestions =
spell_check_results_.front().replacements;
const base::string16 suggested_word(
base::ASCIIToUTF16(test_case.expected_suggestion));
auto position =
std::find_if(suggestions.begin(), suggestions.end(),
[&](const base::string16& suggestion) {
return suggestion.compare(suggested_word) == 0;
});
ASSERT_NE(suggestions.end(), position)
<< "RequestTextCheckTests case " << i
<< ": Expected suggestion not found";
}
}
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void RetrieveSupportedWindowsPreferredLanguagesTests() {
spellcheck_platform::RetrieveSupportedWindowsPreferredLanguages(
base::BindOnce(&SpellcheckPlatformWinTest::
RetrieveSupportedWindowsPreferredLanguagesCallback,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_LE(1u, preferred_languages_.size());
ASSERT_NE(preferred_languages_.end(),
std::find(preferred_languages_.begin(),
preferred_languages_.end(), "en-US"));
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
void HybridRequestTextCheckTests() {
static const struct {
const char* text_to_check;
std::vector<SpellCheckResult> fake_renderer_results;
bool fill_suggestions;
size_t expected_result_count;
} kHybridTestCases[] = {
// Should find no mistakes.
{"This has no spelling mistakes", {}, false, 0u},
// Should find all 3 mistakes.
{"Tihs has some speling mitsakes", {}, false, 3u},
// Should find all 3 mistakes and return some spelling suggestions.
{"Tihs has some speling mitsakes", {}, true, 3u},
// Should find no mistakes because all words are correct on the browser
// side, so mistakes from the renderer should be ignored.
{"This has no spelling mistakes",
{
SpellCheckResult(SpellCheckResult::SPELLING, 5, 3),
SpellCheckResult(SpellCheckResult::SPELLING, 9, 2),
},
false,
0u},
// Should find no mistakes because all words were marked correct by
// either
// the renderer or the browser.
{"Tihs has some speling mitsakes",
{
SpellCheckResult(SpellCheckResult::SPELLING, 5, 3),
SpellCheckResult(SpellCheckResult::SPELLING, 9, 2),
},
false,
0u},
// Should find a single mistake, "speling", because that's the only word
// marked as misspelled by both the renderer and the browser.
{"Tihs has some speling mitsakes",
{
SpellCheckResult(SpellCheckResult::SPELLING, 5, 3),
SpellCheckResult(SpellCheckResult::SPELLING, 14, 7),
},
false,
1u},
// Should find all 3 mistakes because they were marked as misspelled by
// both the renderer and the browser.
{"Tihs has some speling mitsakes",
{
SpellCheckResult(SpellCheckResult::SPELLING, 0, 4),
SpellCheckResult(SpellCheckResult::SPELLING, 14, 7),
SpellCheckResult(SpellCheckResult::SPELLING, 22, 8),
},
false,
3u},
// Should find 3 mistakes. The 2 extra renderer mistakes should be
// ignored
// because the browser didn't mark them as misspelled.
{"Tihs has some speling mitsakes",
{
SpellCheckResult(SpellCheckResult::SPELLING, 0, 4),
SpellCheckResult(SpellCheckResult::SPELLING, 5, 3),
SpellCheckResult(SpellCheckResult::SPELLING, 9, 2),
SpellCheckResult(SpellCheckResult::SPELLING, 14, 7),
SpellCheckResult(SpellCheckResult::SPELLING, 22, 8),
},
false,
3u},
};
for (size_t i = 0; i < base::size(kHybridTestCases); ++i) {
const auto& test_case = kHybridTestCases[i];
const base::string16 text(base::ASCIIToUTF16(test_case.text_to_check));
// Check if the suggested words occur.
spellcheck_platform::RequestTextCheck(
1, text, test_case.fake_renderer_results, test_case.fill_suggestions,
base::BindOnce(
&SpellcheckPlatformWinTest::TextCheckCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_EQ(test_case.expected_result_count, spell_check_results_.size())
<< "HybridRequestTextCheckTests case " << i
<< ": Wrong number of results";
if (spell_check_results_.size() > 0u) {
ASSERT_EQ(spell_check_results_[0].replacements.size() > 0,
test_case.fill_suggestions)
<< "HybridRequestTextCheckTests case " << i
<< ": Wrong number of suggestions";
}
}
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
protected:
bool callback_finished_ = false;
bool set_language_result_;
std::vector<SpellCheckResult> spell_check_results_;
spellcheck::PerLanguageSuggestions spell_check_suggestions_;
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
std::vector<std::string> preferred_languages_;
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
......@@ -253,13 +87,23 @@ class SpellcheckPlatformWinTest : public testing::Test {
base::test::TaskEnvironment::MainThreadType::UI};
};
// TODO(crbug.com/1035044) Split this test into multiple tests instead of
// individual methods. See the task_environment_
// comment in the SpellcheckPlatformWinTest class.
TEST_F(SpellcheckPlatformWinTest, SpellCheckAsyncMethods) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
static const struct {
const char* input; // A string to be tested.
const char* suggested_word; // A suggested word that should occur.
} kTestCases[] = {
{"absense", "absence"}, {"becomeing", "becoming"},
{"cieling", "ceiling"}, {"definate", "definite"},
{"eigth", "eight"}, {"exellent", "excellent"},
{"finaly", "finally"}, {"garantee", "guarantee"},
{"humerous", "humorous"}, {"imediately", "immediately"},
{"jellous", "jealous"}, {"knowlege", "knowledge"},
{"lenght", "length"}, {"manuever", "maneuver"},
{"naturaly", "naturally"}, {"ommision", "omission"},
};
if (base::win::GetVersion() < base::win::Version::WIN8)
return;
}
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker);
......@@ -273,15 +117,44 @@ TEST_F(SpellcheckPlatformWinTest, SpellCheckAsyncMethods) {
ASSERT_TRUE(set_language_result_);
RequestTextCheckTests();
for (const auto& test_case : kTestCases) {
const base::string16 word(base::ASCIIToUTF16(test_case.input));
// Check if the suggested words occur.
spellcheck_platform::RequestTextCheck(
1, word,
base::BindOnce(&SpellcheckPlatformWinTest::TextCheckCompletionCallback,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_EQ(1u, spell_check_results_.size());
const std::vector<base::string16>& suggestions =
spell_check_results_.front().replacements;
const base::string16 suggested_word(
base::ASCIIToUTF16(test_case.suggested_word));
auto position =
std::find_if(suggestions.begin(), suggestions.end(),
[&](const base::string16& suggestion) {
return suggestion.compare(suggested_word) == 0;
});
ASSERT_NE(suggestions.end(), position);
}
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
RetrieveSupportedWindowsPreferredLanguagesTests();
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
spellcheck_platform::RetrieveSupportedWindowsPreferredLanguages(
base::BindOnce(&SpellcheckPlatformWinTest::
RetrieveSupportedWindowsPreferredLanguagesCallback,
base::Unretained(this)));
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
HybridRequestTextCheckTests();
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
RunUntilResultReceived();
ASSERT_LE(1u, preferred_languages_.size());
ASSERT_NE(preferred_languages_.end(),
std::find(preferred_languages_.begin(), preferred_languages_.end(),
"en-US"));
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
}
} // namespace
......@@ -166,12 +166,10 @@ class SpellCheck : public base::SupportsWeakPtr<SpellCheck>,
mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver);
// Returns the current number of spell check languages.
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class).
virtual size_t LanguageCount();
size_t LanguageCount();
// Returns the current number of spell check languages with enabled engines.
// Overriden by tests in spellcheck_provider_test.cc (FakeSpellCheck class).
virtual size_t EnabledLanguageCount();
size_t EnabledLanguageCount();
private:
friend class SpellCheckTest;
......
......@@ -29,30 +29,10 @@ 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 FakeSpellCheck(embedder_provider),
new SpellCheck(embedder_provider),
embedder_provider) {}
TestingSpellCheckProvider::TestingSpellCheckProvider(
......@@ -147,8 +127,7 @@ void TestingSpellCheckProvider::RequestPartialTextCheck(
const std::vector<SpellCheckResult>& partial_results,
bool fill_suggestions,
RequestPartialTextCheckCallback callback) {
partial_text_check_requests_.push_back(
std::make_pair(text, std::move(callback)));
NOTREACHED();
}
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
......@@ -171,24 +150,6 @@ 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,7 +12,6 @@
#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"
......@@ -38,28 +37,6 @@ 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 {
......@@ -81,45 +58,23 @@ 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 // BUILDFLAG(USE_RENDERER_SPELLCHECKER)
#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)
#endif
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Variables logging RequestTextCheck() mojo calls.
using RequestTextCheckParams =
std::pair<base::string16, RequestTextCheckCallback>;
std::vector<RequestTextCheckParams> text_check_requests_;
#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)
#endif
// Returns |spellcheck|.
FakeSpellCheck* spellcheck() {
return static_cast<FakeSpellCheck*>(spellcheck_);
}
SpellCheck* spellcheck() { return spellcheck_; }
private:
// spellcheck::mojom::SpellCheckHost:
......
......@@ -5,8 +5,6 @@
#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"
......@@ -15,16 +13,6 @@
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() {
......@@ -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) {
FakeTextCheckingResult result;
FakeTextCheckingCompletion completion(&result);
......@@ -104,178 +77,4 @@ 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