Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Unified Diff: components/spellcheck/renderer/spellcheck_provider_test.cc

Issue 2857353002: Convert Spellcheck host MessageFilter IPC to mojo (Closed)
Patch Set: Use MakeUnique for the MessageLoop in TestingSpellCheckProvider. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/spellcheck/renderer/spellcheck_provider_test.h ('k') | components/typemaps.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/spellcheck/renderer/spellcheck_provider_test.cc
diff --git a/components/spellcheck/renderer/spellcheck_provider_test.cc b/components/spellcheck/renderer/spellcheck_provider_test.cc
index ffba9d14b0c2f6713aa7bc66180b68c53a499225..76d48ae86297b2d6c7dfd458b6dd47247cf58220 100644
--- a/components/spellcheck/renderer/spellcheck_provider_test.cc
+++ b/components/spellcheck/renderer/spellcheck_provider_test.cc
@@ -5,19 +5,16 @@
#include "components/spellcheck/renderer/spellcheck_provider_test.h"
#include "base/memory/ptr_util.h"
-#include "base/stl_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/common/spellcheck_messages.h"
+#include "components/spellcheck/common/spellcheck_result.h"
#include "components/spellcheck/renderer/spellcheck.h"
#include "components/spellcheck/spellcheck_build_features.h"
-#include "ipc/ipc_message_macros.h"
-
-class MockSpellcheck: public SpellCheck {
-};
FakeTextCheckingCompletion::FakeTextCheckingCompletion()
-: completion_count_(0),
- cancellation_count_(0) {
-}
+ : completion_count_(0), cancellation_count_(0) {}
FakeTextCheckingCompletion::~FakeTextCheckingCompletion() {}
@@ -32,62 +29,76 @@ void FakeTextCheckingCompletion::DidCancelCheckingText() {
}
TestingSpellCheckProvider::TestingSpellCheckProvider()
- : SpellCheckProvider(NULL, new MockSpellcheck),
- spelling_service_call_count_(0) {
-}
+ : SpellCheckProvider(nullptr, new SpellCheck),
+ spelling_service_call_count_(0),
+ binding_(this) {}
-TestingSpellCheckProvider::TestingSpellCheckProvider(
- SpellCheck* spellcheck)
+TestingSpellCheckProvider::TestingSpellCheckProvider(SpellCheck* spellcheck)
: SpellCheckProvider(nullptr, spellcheck),
- spelling_service_call_count_(0) {
-}
+ spelling_service_call_count_(0),
+ binding_(this) {}
TestingSpellCheckProvider::~TestingSpellCheckProvider() {
+ binding_.Close();
delete spellcheck_;
}
-bool TestingSpellCheckProvider::Send(IPC::Message* message) {
+void TestingSpellCheckProvider::RequestTextChecking(
+ const base::string16& text,
+ blink::WebTextCheckingCompletion* completion) {
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
- // 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;
- }
+ if (!loop_ && !base::MessageLoop::current())
+ loop_ = base::MakeUnique<base::MessageLoop>();
+ if (!binding_.is_bound())
+ SetSpellCheckHostForTesting(binding_.CreateInterfacePtrAndBind());
+ SpellCheckProvider::RequestTextChecking(text, completion);
+ base::RunLoop().RunUntilIdle();
+#else
+ SpellCheckProvider::RequestTextChecking(text, completion);
#endif
+}
+bool TestingSpellCheckProvider::Send(IPC::Message* message) {
messages_.push_back(base::WrapUnique<IPC::Message>(message));
return true;
}
+void TestingSpellCheckProvider::RequestDictionary() {}
+
+void TestingSpellCheckProvider::NotifyChecked(const base::string16& word,
+ bool misspelled) {}
+
+void TestingSpellCheckProvider::CallSpellingService(
+ const base::string16& text,
+ const CallSpellingServiceCallback& callback) {
+#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+ OnCallSpellingService(text);
+ callback.Run(true, std::vector<SpellCheckResult>());
+#else
+ NOTREACHED();
+#endif
+}
+
void TestingSpellCheckProvider::OnCallSpellingService(
- int route_id,
- int identifier,
const base::string16& text) {
-#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
- NOTREACHED();
-#else
+#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
++spelling_service_call_count_;
blink::WebTextCheckingCompletion* completion =
- text_check_completions_.Lookup(identifier);
+ text_check_completions_.Lookup(last_identifier_);
if (!completion) {
ResetResult();
return;
}
text_.assign(text);
- text_check_completions_.Remove(identifier);
+ text_check_completions_.Remove(last_identifier_);
std::vector<blink::WebTextCheckingResult> results;
results.push_back(blink::WebTextCheckingResult(
blink::kWebTextDecorationTypeSpelling, 0, 5, blink::WebString("hello")));
completion->DidFinishCheckingText(results);
last_request_ = text;
last_results_ = results;
+#else
+ NOTREACHED();
#endif
}
« no previous file with comments | « components/spellcheck/renderer/spellcheck_provider_test.h ('k') | components/typemaps.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698