| Index: chrome/browser/spellchecker/spellcheck_host_impl_unittest.cc
|
| diff --git a/chrome/browser/spellchecker/spellcheck_host_impl_unittest.cc b/chrome/browser/spellchecker/spellcheck_host_impl_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..060c79f973a2980e606faf81dd62d340face697f
|
| --- /dev/null
|
| +++ b/chrome/browser/spellchecker/spellcheck_host_impl_unittest.cc
|
| @@ -0,0 +1,89 @@
|
| +// Copyright (c) 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/spellchecker/spellcheck_host_impl.h"
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/spellchecker/spellcheck_factory.h"
|
| +#include "chrome/browser/spellchecker/spellcheck_service.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "components/spellcheck/common/spellcheck_result.h"
|
| +#include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|
| +#error !BUILDFLAG(USE_BROWSER_SPELLCHECKER) is required for these unit tests.
|
| +#endif
|
| +
|
| +class TestSpellCheckHostImpl {
|
| + public:
|
| + TestSpellCheckHostImpl()
|
| + : spellcheck_(base::MakeUnique<SpellcheckService>(&testing_profile_)) {}
|
| +
|
| + SpellcheckCustomDictionary& GetCustomDictionary() const {
|
| + EXPECT_NE(nullptr, spellcheck_.get());
|
| + SpellcheckCustomDictionary* custom_dictionary =
|
| + spellcheck_->GetCustomDictionary();
|
| + return *custom_dictionary;
|
| + }
|
| +
|
| + std::vector<SpellCheckResult> FilterCustomWordResults(
|
| + const std::string& text,
|
| + const std::vector<SpellCheckResult>& service_results) const {
|
| + return SpellCheckHostImpl::FilterCustomWordResults(
|
| + text, GetCustomDictionary(), service_results);
|
| + }
|
| +
|
| + private:
|
| + content::TestBrowserThreadBundle thread_bundle_;
|
| + TestingProfile testing_profile_;
|
| + std::unique_ptr<SpellcheckService> spellcheck_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestSpellCheckHostImpl);
|
| +};
|
| +
|
| +// Spelling corrections of custom dictionary words should be removed from the
|
| +// results returned by the remote Spelling service.
|
| +TEST(SpellCheckHostFilterTest, SpellingServiceCustomResults) {
|
| + std::vector<SpellCheckResult> service_results;
|
| + service_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 0, 6,
|
| + base::ASCIIToUTF16("Hello")));
|
| + service_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 7, 5,
|
| + base::ASCIIToUTF16("World")));
|
| + TestSpellCheckHostImpl spellcheck_host;
|
| + spellcheck_host.GetCustomDictionary().AddWord("Helllo");
|
| + std::vector<SpellCheckResult> results =
|
| + spellcheck_host.FilterCustomWordResults("Helllo Warld", service_results);
|
| + EXPECT_EQ(1u, results.size());
|
| +
|
| + EXPECT_EQ(service_results[1].decoration, results[0].decoration);
|
| + EXPECT_EQ(service_results[1].location, results[0].location);
|
| + EXPECT_EQ(service_results[1].length, results[0].length);
|
| + EXPECT_EQ(service_results[1].replacement, results[0].replacement);
|
| +}
|
| +
|
| +// Spelling corrections of words that are not in the custom dictionary should
|
| +// be retained in the results returned by the remote Spelling service.
|
| +TEST(SpellCheckHostFilterTest, SpellingServiceResults) {
|
| + std::vector<SpellCheckResult> service_results;
|
| + service_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 0, 6,
|
| + base::ASCIIToUTF16("Hello")));
|
| + service_results.push_back(SpellCheckResult(SpellCheckResult::SPELLING, 7, 5,
|
| + base::ASCIIToUTF16("World")));
|
| + TestSpellCheckHostImpl spellcheck_host;
|
| + spellcheck_host.GetCustomDictionary().AddWord("Halo");
|
| + std::vector<SpellCheckResult> results =
|
| + spellcheck_host.FilterCustomWordResults("Helllo Warld", service_results);
|
| + EXPECT_EQ(2u, results.size());
|
| +
|
| + for (size_t i = 0; i < results.size(); ++i) {
|
| + EXPECT_EQ(service_results[i].decoration, results[i].decoration);
|
| + EXPECT_EQ(service_results[i].location, results[i].location);
|
| + EXPECT_EQ(service_results[i].length, results[i].length);
|
| + EXPECT_EQ(service_results[i].replacement, results[i].replacement);
|
| + }
|
| +}
|
|
|