diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 08:05:56 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-21 08:05:56 +0000 |
commit | 7ceb9901a12a14227318bb6657f30aa03849e382 (patch) | |
tree | 0f29770b8b3afa6c09b1d28caa03dc281bc69a21 /chrome/renderer/spellchecker | |
parent | 1ff631bed62aee4054d5be3e3f3a506e22121704 (diff) | |
download | chromium_src-7ceb9901a12a14227318bb6657f30aa03849e382.zip chromium_src-7ceb9901a12a14227318bb6657f30aa03849e382.tar.gz chromium_src-7ceb9901a12a14227318bb6657f30aa03849e382.tar.bz2 |
Remove Hunspell on OS X - step 4
Changes:
* Isolate Mac-only functionality into SpellCheckerMessageFilterMac.
* Isolate Spelling related IPC messages only needed on Mac.
* Add some #ifdefs around sending IPC messages, so it's clear which ones are Mac-only.
* Remove 'Platform' specifier from Mac-only IPC messages.
Unit tests:
The tests this CL touches were added as part of http://src.chromium.org/viewvc/chrome?view=rev&revision=75577 which integrated the OS X Grammar checker into Chrome.
* spellcheck_provider_unittest.cc - split into Mac and Hunspell variants and add OVERRIDE where appropriate.
* spellcheck_message_filter_browsertest.cc - This test was Mac-only to begin with, rename it to reflect that.
Future steps (so it's clear where I'm going with this CL):
* Unravel remaining functions in SpellCheckMessageFilter - ideally this class shouldn't be used on Mac.
* Split spellcheck.cc into Hunspell/Mac variants to remove #ifdefs.
BUG=69944
TEST=Spellchecking should continue to work on Mac and Windows.
Review URL: http://codereview.chromium.org/8905004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker')
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck_provider.cc | 21 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc | 83 | ||||
-rw-r--r-- | chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc (renamed from chrome/renderer/spellchecker/spellcheck_provider_unittest.cc) | 55 |
4 files changed, 121 insertions, 46 deletions
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc index 0ed123b..fc4da90 100644 --- a/chrome/renderer/spellchecker/spellcheck.cc +++ b/chrome/renderer/spellchecker/spellcheck.cc @@ -246,8 +246,10 @@ bool SpellCheck::CheckSpelling(const string16& word_to_check, int tag) { bool word_correct = false; if (is_using_platform_spelling_engine_) { - RenderThread::Get()->Send(new SpellCheckHostMsg_PlatformCheckSpelling( +#if defined(OS_MACOSX) + RenderThread::Get()->Send(new SpellCheckHostMsg_CheckSpelling( word_to_check, tag, &word_correct)); +#endif } else { std::string word_to_check_utf8(UTF16ToUTF8(word_to_check)); // Hunspell shouldn't let us exceed its max, but check just in case @@ -271,8 +273,10 @@ void SpellCheck::FillSuggestionList( const string16& wrong_word, std::vector<string16>* optional_suggestions) { if (is_using_platform_spelling_engine_) { - RenderThread::Get()->Send(new SpellCheckHostMsg_PlatformFillSuggestionList( +#if defined(OS_MACOSX) + RenderThread::Get()->Send(new SpellCheckHostMsg_FillSuggestionList( wrong_word, optional_suggestions)); +#endif return; } diff --git a/chrome/renderer/spellchecker/spellcheck_provider.cc b/chrome/renderer/spellchecker/spellcheck_provider.cc index 3fd670e..28050c5 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider.cc @@ -48,21 +48,20 @@ void SpellCheckProvider::RequestTextChecking( const WebString& text, int document_tag, WebTextCheckingCompletion* completion) { +#if defined(OS_MACOSX) // Text check (unified request for grammar and spell check) is only - // available for browser process, so we ask the system sellchecker + // available for browser process, so we ask the system spellchecker // over IPC or return an empty result if the checker is not // available. - if (!is_using_platform_spelling_engine()) { - completion->didFinishCheckingText - (std::vector<WebTextCheckingResult>()); - return; - } - - Send(new SpellCheckHostMsg_PlatformRequestTextCheck( + Send(new SpellCheckHostMsg_RequestTextCheck( routing_id(), text_check_completions_.Add(completion), document_tag, text)); +#else + completion->didFinishCheckingText( + std::vector<WebTextCheckingResult>()); +#endif // !OS_MACOSX } bool SpellCheckProvider::OnMessageReceived(const IPC::Message& message) { @@ -91,7 +90,9 @@ void SpellCheckProvider::FocusedNodeChanged(const WebKit::WebNode& unused) { checked = true; } +#if defined(OS_MACOSX) Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); +#endif } void SpellCheckProvider::spellCheck( @@ -136,7 +137,9 @@ WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { } void SpellCheckProvider::showSpellingUI(bool show) { +#if defined(OS_MACOSX) Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); +#endif } bool SpellCheckProvider::isShowingSpellingUI() { @@ -145,8 +148,10 @@ bool SpellCheckProvider::isShowingSpellingUI() { void SpellCheckProvider::updateSpellingUIWithMisspelledWord( const WebString& word) { +#if defined(OS_MACOSX) Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id(), word)); +#endif } bool SpellCheckProvider::is_using_platform_spelling_engine() const { diff --git a/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc b/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc new file mode 100644 index 0000000..df520bc --- /dev/null +++ b/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2011 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 <vector> + +#include "base/utf_string_conversions.h" +#include "base/stl_util.h" +#include "chrome/common/spellcheck_messages.h" +#include "chrome/renderer/spellchecker/spellcheck_provider.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingCompletion.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" + +// Tests for Hunspell functionality in SpellcheckingProvider + +namespace { + +// Faked test target, which stores sent message for verification, +// and allows manipulate |is_using_platform_spelling_engine| parameter. +class TestingSpellCheckProvider : public SpellCheckProvider { + public: + TestingSpellCheckProvider() + : SpellCheckProvider(NULL, NULL) { + } + + virtual ~TestingSpellCheckProvider() { + STLDeleteContainerPointers(messages_.begin(), messages_.end()); + } + + virtual bool Send(IPC::Message* message) OVERRIDE { + messages_.push_back(message); + return true; + } + + virtual bool is_using_platform_spelling_engine() const OVERRIDE { + return false; + } + + std::vector<IPC::Message*> messages_; +}; + +// A fake completion object for verification. +class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { + public: + FakeTextCheckingCompletion() + : completion_count_(0) { + } + + virtual void didFinishCheckingText( + const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) + OVERRIDE { + ++completion_count_; + last_results_ = results; + } + + size_t completion_count_; + WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; +}; + +class SpellCheckProviderTest : public testing::Test { + public: + SpellCheckProviderTest() { } + virtual ~SpellCheckProviderTest() { } + + protected: + TestingSpellCheckProvider provider_; +}; + +TEST_F(SpellCheckProviderTest, UsingHunspell) { + int document_tag = 123; + FakeTextCheckingCompletion completion; + provider_.RequestTextChecking(WebKit::WebString("hello"), + document_tag, + &completion); + EXPECT_EQ(completion.completion_count_, 1U); + EXPECT_EQ(provider_.messages_.size(), 0U); + EXPECT_EQ(provider_.pending_text_request_size(), 0U); +} + +} // namespace diff --git a/chrome/renderer/spellchecker/spellcheck_provider_unittest.cc b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc index 156a852..d41bf82 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider_unittest.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc @@ -5,6 +5,7 @@ #include <vector> #include "base/utf_string_conversions.h" +#include "base/stl_util.h" #include "chrome/common/spellcheck_messages.h" #include "chrome/renderer/spellchecker/spellcheck_provider.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,29 +21,23 @@ namespace { class TestingSpellCheckProvider : public SpellCheckProvider { public: TestingSpellCheckProvider() - : SpellCheckProvider(NULL, NULL), - is_using_platform_spelling_engine_(true) { + : SpellCheckProvider(NULL, NULL) { } virtual ~TestingSpellCheckProvider() { - for (std::vector<IPC::Message*>::iterator i = messages_.begin(); - i != messages_.end(); - ++i) { - delete *i; - } + STLDeleteContainerPointers(messages_.begin(), messages_.end()); } - virtual bool Send(IPC::Message* message) { + virtual bool Send(IPC::Message* message) OVERRIDE { messages_.push_back(message); return true; } - virtual bool is_using_platform_spelling_engine() const { - return is_using_platform_spelling_engine_; + virtual bool is_using_platform_spelling_engine() const OVERRIDE { + return true; } std::vector<IPC::Message*> messages_; - bool is_using_platform_spelling_engine_; }; // A fake completion object for verification. @@ -53,8 +48,9 @@ class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { } virtual void didFinishCheckingText( - const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) { - completion_count_++; + const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) + OVERRIDE { + ++completion_count_; last_results_ = results; } @@ -62,10 +58,10 @@ class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; }; -class SpellCheckProviderTest : public testing::Test { +class SpellCheckProviderMacTest : public testing::Test { public: - SpellCheckProviderTest() { } - virtual ~SpellCheckProviderTest() { } + SpellCheckProviderMacTest() { } + virtual ~SpellCheckProviderMacTest() { } protected: TestingSpellCheckProvider provider_; @@ -83,9 +79,9 @@ struct MessageParameters { string16 text; }; -MessageParameters ReadPlatformRequestTextCheck(IPC::Message* message) { +MessageParameters ReadRequestTextCheck(IPC::Message* message) { MessageParameters parameters; - bool ok = SpellCheckHostMsg_PlatformRequestTextCheck::Read( + bool ok = SpellCheckHostMsg_RequestTextCheck::Read( message, ¶meters.router_id, ¶meters.request_id, @@ -107,7 +103,7 @@ void FakeMessageArrival(SpellCheckProvider* provider, EXPECT_TRUE(handled); } -TEST_F(SpellCheckProviderTest, SingleRoundtripSuccess) { +TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { FakeTextCheckingCompletion completion; int document_tag = 123; @@ -119,7 +115,7 @@ TEST_F(SpellCheckProviderTest, SingleRoundtripSuccess) { EXPECT_EQ(provider_.pending_text_request_size(), 1U); MessageParameters read_parameters = - ReadPlatformRequestTextCheck(provider_.messages_[0]); + ReadRequestTextCheck(provider_.messages_[0]); EXPECT_EQ(read_parameters.text, UTF8ToUTF16("hello")); FakeMessageArrival(&provider_, read_parameters); @@ -127,7 +123,7 @@ TEST_F(SpellCheckProviderTest, SingleRoundtripSuccess) { EXPECT_EQ(provider_.pending_text_request_size(), 0U); } -TEST_F(SpellCheckProviderTest, TwoRoundtripSuccess) { +TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { int document_tag = 123; FakeTextCheckingCompletion completion1; @@ -145,11 +141,11 @@ TEST_F(SpellCheckProviderTest, TwoRoundtripSuccess) { EXPECT_EQ(provider_.pending_text_request_size(), 2U); MessageParameters read_parameters1 = - ReadPlatformRequestTextCheck(provider_.messages_[0]); + ReadRequestTextCheck(provider_.messages_[0]); EXPECT_EQ(read_parameters1.text, UTF8ToUTF16("hello")); MessageParameters read_parameters2 = - ReadPlatformRequestTextCheck(provider_.messages_[1]); + ReadRequestTextCheck(provider_.messages_[1]); EXPECT_EQ(read_parameters2.text, UTF8ToUTF16("bye")); FakeMessageArrival(&provider_, read_parameters1); @@ -163,17 +159,4 @@ TEST_F(SpellCheckProviderTest, TwoRoundtripSuccess) { EXPECT_EQ(provider_.pending_text_request_size(), 0U); } -TEST_F(SpellCheckProviderTest, PlatformEngineUnavailable) { - provider_.is_using_platform_spelling_engine_ = false; - - int document_tag = 123; - FakeTextCheckingCompletion completion; - provider_.RequestTextChecking(WebKit::WebString("hello"), - document_tag, - &completion); - EXPECT_EQ(completion.completion_count_, 1U); - EXPECT_EQ(provider_.messages_.size(), 0U); - EXPECT_EQ(provider_.pending_text_request_size(), 0U); -} - } // namespace |