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

[Spellcheck] Move Windows Spell Checker component tests to own file

Now that the WindowsSpellChecker class is in its own file, the component
tests that were testing its methods should also move to a
corresponding windows_spell_checker_unittest.cc file.

The tests were initially testing the methods inside the
spellcheck_platform namespace, but those methods were simple
pass-throughs to the WindowsSpellChecker class, so it made sense to
simply reuse those tests for WindowsSpellChecker directly.

#Squeegee

Bug: 463364, 1035044
Change-Id: I11a46e67d5529063a8f63e7e55de62013ba8627e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2023466Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Cr-Commit-Position: refs/heads/master@{#735941}
parent fe5cb8b0
...@@ -64,9 +64,12 @@ source_set("unit_tests") { ...@@ -64,9 +64,12 @@ source_set("unit_tests") {
sources = [ sources = [
"spellcheck_host_metrics_unittest.cc", "spellcheck_host_metrics_unittest.cc",
"spellcheck_platform_mac_unittest.cc", "spellcheck_platform_mac_unittest.cc",
"spellcheck_platform_win_unittest.cc",
] ]
if (is_win) {
sources += [ "windows_spell_checker_unittest.cc" ]
}
deps = [ deps = [
":browser", ":browser",
"//base", "//base",
......
...@@ -7,15 +7,19 @@ ...@@ -7,15 +7,19 @@
#include <stddef.h> #include <stddef.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/no_destructor.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/spellcheck/browser/windows_spell_checker.h"
#include "components/spellcheck/common/spellcheck_features.h" #include "components/spellcheck/common/spellcheck_features.h"
#include "components/spellcheck/common/spellcheck_result.h" #include "components/spellcheck/common/spellcheck_result.h"
#include "components/spellcheck/spellcheck_buildflags.h" #include "components/spellcheck/spellcheck_buildflags.h"
...@@ -24,8 +28,20 @@ ...@@ -24,8 +28,20 @@
namespace { namespace {
class SpellcheckPlatformWinTest : public testing::Test { class WindowsSpellCheckerTest : public testing::Test {
public: public:
WindowsSpellCheckerTest() {
if (spellcheck::WindowsVersionSupportsSpellchecker()) {
win_spell_checker_ = std::make_unique<WindowsSpellChecker>(
base::ThreadTaskRunnerHandle::Get(),
base::CreateCOMSTATaskRunner({base::ThreadPool(), base::MayBlock()}));
}
}
WindowsSpellChecker* GetWindowsSpellChecker() {
return win_spell_checker_.get();
}
void RunUntilResultReceived() { void RunUntilResultReceived() {
if (callback_finished_) if (callback_finished_)
return; return;
...@@ -77,8 +93,8 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -77,8 +93,8 @@ class SpellcheckPlatformWinTest : public testing::Test {
} }
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK #endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
// TODO(crbug.com/1035044) Make these methods actual tests. See the // TODO(gujen) Make these methods actual tests. See the task_environment_
// task_environment_ comment below. // comment below.
void RequestTextCheckTests() { void RequestTextCheckTests() {
static const struct { static const struct {
const char* text_to_check; const char* text_to_check;
...@@ -99,11 +115,10 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -99,11 +115,10 @@ class SpellcheckPlatformWinTest : public testing::Test {
const base::string16 word(base::ASCIIToUTF16(test_case.text_to_check)); const base::string16 word(base::ASCIIToUTF16(test_case.text_to_check));
// Check if the suggested words occur. // Check if the suggested words occur.
spellcheck_platform::RequestTextCheck( GetWindowsSpellChecker()->RequestTextCheckForAllLanguages(
1, word, 1, word,
base::BindOnce( base::BindOnce(&WindowsSpellCheckerTest::TextCheckCompletionCallback,
&SpellcheckPlatformWinTest::TextCheckCompletionCallback, base::Unretained(this)));
base::Unretained(this)));
RunUntilResultReceived(); RunUntilResultReceived();
ASSERT_EQ(1u, spell_check_results_.size()) ASSERT_EQ(1u, spell_check_results_.size())
...@@ -127,8 +142,8 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -127,8 +142,8 @@ class SpellcheckPlatformWinTest : public testing::Test {
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK) #if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void RetrieveSupportedWindowsPreferredLanguagesTests() { void RetrieveSupportedWindowsPreferredLanguagesTests() {
spellcheck_platform::RetrieveSupportedWindowsPreferredLanguages( GetWindowsSpellChecker()->RetrieveSupportedWindowsPreferredLanguages(
base::BindOnce(&SpellcheckPlatformWinTest:: base::BindOnce(&WindowsSpellCheckerTest::
RetrieveSupportedWindowsPreferredLanguagesCallback, RetrieveSupportedWindowsPreferredLanguagesCallback,
base::Unretained(this))); base::Unretained(this)));
...@@ -143,11 +158,11 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -143,11 +158,11 @@ class SpellcheckPlatformWinTest : public testing::Test {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
void PerLanguageSuggestionsTests() { void PerLanguageSuggestionsTests() {
spellcheck_platform::GetPerLanguageSuggestions( GetWindowsSpellChecker()->GetPerLanguageSuggestions(
base::ASCIIToUTF16("tihs"), base::ASCIIToUTF16("tihs"),
base::BindOnce(&SpellcheckPlatformWinTest:: base::BindOnce(
PerLanguageSuggestionsCompletionCallback, &WindowsSpellCheckerTest::PerLanguageSuggestionsCompletionCallback,
base::Unretained(this))); base::Unretained(this)));
RunUntilResultReceived(); RunUntilResultReceived();
ASSERT_EQ(per_language_suggestions_.size(), 1u); ASSERT_EQ(per_language_suggestions_.size(), 1u);
...@@ -156,7 +171,10 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -156,7 +171,10 @@ class SpellcheckPlatformWinTest : public testing::Test {
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
protected: protected:
std::unique_ptr<WindowsSpellChecker> win_spell_checker_;
bool callback_finished_ = false; bool callback_finished_ = false;
base::OnceClosure quit_;
bool set_language_result_; bool set_language_result_;
std::vector<SpellCheckResult> spell_check_results_; std::vector<SpellCheckResult> spell_check_results_;
...@@ -166,24 +184,23 @@ class SpellcheckPlatformWinTest : public testing::Test { ...@@ -166,24 +184,23 @@ class SpellcheckPlatformWinTest : public testing::Test {
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK) #if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
std::vector<std::string> preferred_languages_; std::vector<std::string> preferred_languages_;
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK #endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
base::OnceClosure quit_;
// The WindowsSpellChecker class is instantiated with static storage using // TODO(gujen) (crbug.com/1035044) The WindowsSpellChecker class is
// base::NoDestructor (see GetWindowsSpellChecker) and creates its own task // instantiated with static storage using base::NoDestructor (see
// runner. The thread pool is destroyed together with TaskEnvironment when the // GetWindowsSpellChecker) and creates its own task runner. The thread pool is
// test fixture object is destroyed. Therefore without some elaborate // destroyed together with TaskEnvironment when the test fixture object is
// test-only code added to the WindowsSpellChecker class or a means to keep // destroyed. Therefore without some elaborate test-only code added to the
// the TaskEnvironment alive (which would set off leak detection), easiest // WindowsSpellChecker class or a means to keep the TaskEnvironment alive
// approach for now is to add all test coverage for Windows spellchecking to // (which would set off leak detection), easiest approach for now is to add
// a single test. // all test coverage for Windows spellchecking to a single test.
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::MainThreadType::UI}; base::test::TaskEnvironment::MainThreadType::UI};
}; };
// TODO(crbug.com/1035044) Split this test into multiple tests instead of // TODO(gujen) Split this test into multiple tests instead of individual
// individual methods. See the task_environment_ // methods. See the task_environment_ comment in the
// comment in the SpellcheckPlatformWinTest class. // WindowsSpellCheckerTest class.
TEST_F(SpellcheckPlatformWinTest, SpellCheckAsyncMethods) { TEST_F(WindowsSpellCheckerTest, SpellCheckAsyncMethods) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) { if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return; return;
} }
...@@ -191,9 +208,9 @@ TEST_F(SpellcheckPlatformWinTest, SpellCheckAsyncMethods) { ...@@ -191,9 +208,9 @@ TEST_F(SpellcheckPlatformWinTest, SpellCheckAsyncMethods) {
base::test::ScopedFeatureList feature_list; base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker); feature_list.InitAndEnableFeature(spellcheck::kWinUseBrowserSpellChecker);
spellcheck_platform::SetLanguage( GetWindowsSpellChecker()->CreateSpellChecker(
"en-US", "en-US",
base::BindOnce(&SpellcheckPlatformWinTest::SetLanguageCompletionCallback, base::BindOnce(&WindowsSpellCheckerTest::SetLanguageCompletionCallback,
base::Unretained(this))); base::Unretained(this)));
RunUntilResultReceived(); RunUntilResultReceived();
......
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