diff options
author | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 18:57:51 +0000 |
---|---|---|
committer | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-24 18:57:51 +0000 |
commit | fe48c31f944eb20d58245c5c3981615993240c3e (patch) | |
tree | 3ed17492e9299d38060fddb9e17486369551bfec | |
parent | 7d432e240fba393b53a65623df7e649eeb508653 (diff) | |
download | chromium_src-fe48c31f944eb20d58245c5c3981615993240c3e.zip chromium_src-fe48c31f944eb20d58245c5c3981615993240c3e.tar.gz chromium_src-fe48c31f944eb20d58245c5c3981615993240c3e.tar.bz2 |
[Spellcheck] Factored out common testing code.
R=rlp@chromium.org
TBR=jhawkins@chromium.org
BUG=none
Review URL: https://chromiumcodereview.appspot.com/11230017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163878 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 158 insertions, 144 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 4e5263c..2071d69 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2159,6 +2159,8 @@ 'renderer/safe_browsing/scorer_unittest.cc', 'renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc', 'renderer/spellchecker/spellcheck_provider_mac_unittest.cc', + 'renderer/spellchecker/spellcheck_provider_test.cc', + 'renderer/spellchecker/spellcheck_provider_test.h', 'renderer/spellchecker/spellcheck_unittest.cc', 'renderer/spellchecker/spellcheck_worditerator_unittest.cc', 'service/cloud_print/cloud_print_helpers_unittest.cc', diff --git a/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc b/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc index fb7fa26..09fc141 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc @@ -7,106 +7,14 @@ #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 "chrome/renderer/spellchecker/spellcheck_provider_test.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 -// Faked test target, which stores sent message for verification. -class TestingSpellCheckProvider : public SpellCheckProvider { - public: - TestingSpellCheckProvider() - : SpellCheckProvider(NULL, NULL), - offset_(-1) { - } - - virtual ~TestingSpellCheckProvider() { - STLDeleteContainerPointers(messages_.begin(), messages_.end()); - } - - virtual bool Send(IPC::Message* message) OVERRIDE { - // Call our mock message handlers. - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message) - IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, - OnCallSpellingService) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - if (handled) { - delete message; - return true; - } - messages_.push_back(message); - return true; - } - - void OnCallSpellingService(int route_id, - int identifier, - int offset, - const string16& text) { - WebKit::WebTextCheckingCompletion* completion = - text_check_completions_.Lookup(identifier); - if (!completion) { - ResetResult(); - return; - } - offset_ = offset; - text_.assign(text); - text_check_completions_.Remove(identifier); - completion->didFinishCheckingText( - std::vector<WebKit::WebTextCheckingResult>()); - last_request_ = text; - } - - void ResetResult() { - offset_ = -1; - text_.clear(); - } - - int offset_; - string16 text_; - std::vector<IPC::Message*> messages_; -}; namespace { -// A fake completion object for verification. -class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { - public: - FakeTextCheckingCompletion() - : completion_count_(0), - cancellation_count_(0) { - } - - virtual void didFinishCheckingText( - const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) - OVERRIDE { - ++completion_count_; - last_results_ = results; - } - - virtual void didCancelCheckingText() OVERRIDE { - ++completion_count_; - ++cancellation_count_; - } - - size_t completion_count_; - size_t cancellation_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; diff --git a/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc index 257851d..28305f8 100644 --- a/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc +++ b/chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc @@ -5,64 +5,15 @@ #include <vector> #include "base/utf_string_conversions.h" -#include "base/stl_util.h" #include "chrome/common/spellcheck_messages.h" #include "chrome/common/spellcheck_result.h" -#include "chrome/renderer/spellchecker/spellcheck_provider.h" +#include "chrome/renderer/spellchecker/spellcheck_provider_test.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" 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; - } - - 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 SpellCheckProviderMacTest : public testing::Test { - public: - SpellCheckProviderMacTest() { } - virtual ~SpellCheckProviderMacTest() { } - - protected: - TestingSpellCheckProvider provider_; -}; +class SpellCheckProviderMacTest : public SpellCheckProviderTest {}; struct MessageParameters { MessageParameters() diff --git a/chrome/renderer/spellchecker/spellcheck_provider_test.cc b/chrome/renderer/spellchecker/spellcheck_provider_test.cc new file mode 100644 index 0000000..0762899 --- /dev/null +++ b/chrome/renderer/spellchecker/spellcheck_provider_test.cc @@ -0,0 +1,88 @@ +// Copyright (c) 2012 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/renderer/spellchecker/spellcheck_provider_test.h" + +#include "base/stl_util.h" +#include "chrome/common/spellcheck_messages.h" +#include "ipc/ipc_message_macros.h" + +FakeTextCheckingCompletion::FakeTextCheckingCompletion() +: completion_count_(0), + cancellation_count_(0) { +} + +FakeTextCheckingCompletion::~FakeTextCheckingCompletion() {} + +void FakeTextCheckingCompletion::didFinishCheckingText( + const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) { + ++completion_count_; + last_results_ = results; +} + +void FakeTextCheckingCompletion::didCancelCheckingText() { + ++completion_count_; + ++cancellation_count_; +} + +TestingSpellCheckProvider::TestingSpellCheckProvider() + : SpellCheckProvider(NULL, NULL), + offset_(-1) { +} + +TestingSpellCheckProvider::~TestingSpellCheckProvider() { + STLDeleteContainerPointers(messages_.begin(), messages_.end()); +} + +bool TestingSpellCheckProvider::Send(IPC::Message* message) { + // Call our mock message handlers. + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(TestingSpellCheckProvider, *message) +#if !defined(OS_MACOSX) + IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, + OnCallSpellingService) +#endif + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + if (handled) { + delete message; + return true; + } + + messages_.push_back(message); + return true; +} + +void TestingSpellCheckProvider::OnCallSpellingService(int route_id, + int identifier, + int offset, + const string16& text) { +#if defined (OS_MACOSX) + NOTREACHED(); +#else + WebKit::WebTextCheckingCompletion* completion = + text_check_completions_.Lookup(identifier); + if (!completion) { + ResetResult(); + return; + } + offset_ = offset; + text_.assign(text); + text_check_completions_.Remove(identifier); + completion->didFinishCheckingText( + std::vector<WebKit::WebTextCheckingResult>()); + last_request_ = text; +#endif +} + +void TestingSpellCheckProvider::ResetResult() { + offset_ = -1; + text_.clear(); +} + +SpellCheckProviderTest::SpellCheckProviderTest() {} +SpellCheckProviderTest::~SpellCheckProviderTest() {} + + diff --git a/chrome/renderer/spellchecker/spellcheck_provider_test.h b/chrome/renderer/spellchecker/spellcheck_provider_test.h new file mode 100644 index 0000000..198edaf --- /dev/null +++ b/chrome/renderer/spellchecker/spellcheck_provider_test.h @@ -0,0 +1,65 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_TEST_H_ +#define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_TEST_H_ + +#include <vector> + +#include "base/string16.h" +#include "chrome/renderer/spellchecker/spellcheck_provider.h" +#include "testing/gtest/include/gtest/gtest.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" + +namespace IPC { + class Message; +} + +// A fake completion object for verification. +class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { + public: + FakeTextCheckingCompletion(); + ~FakeTextCheckingCompletion(); + + virtual void didFinishCheckingText( + const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) OVERRIDE; + virtual void didCancelCheckingText() OVERRIDE; + + + size_t completion_count_; + size_t cancellation_count_; + WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; +}; + +// Faked test target, which stores sent message for verification. +class TestingSpellCheckProvider : public SpellCheckProvider { + public: + TestingSpellCheckProvider(); + + virtual ~TestingSpellCheckProvider(); + virtual bool Send(IPC::Message* message) OVERRIDE; + void OnCallSpellingService(int route_id, + int identifier, + int offset, + const string16& text); + void ResetResult(); + + int offset_; + string16 text_; + std::vector<IPC::Message*> messages_; +}; + +// SpellCheckProvider test fixture. +class SpellCheckProviderTest : public testing::Test { + public: + SpellCheckProviderTest(); + virtual ~SpellCheckProviderTest(); + + protected: + TestingSpellCheckProvider provider_; +}; + +#endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_TEST_H_ |