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

Unified Diff: chrome/browser/chrome_site_per_process_browsertest.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
Index: chrome/browser/chrome_site_per_process_browsertest.cc
diff --git a/chrome/browser/chrome_site_per_process_browsertest.cc b/chrome/browser/chrome_site_per_process_browsertest.cc
index e426d21c644152fa4ed9302e5ff29542197f9a13..7ff93310dd52398e78a28a3ccb7beafa2a8d0c7d 100644
--- a/chrome/browser/chrome_site_per_process_browsertest.cc
+++ b/chrome/browser/chrome_site_per_process_browsertest.cc
@@ -38,7 +38,9 @@
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_SPELLCHECK)
+#include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/common/spellcheck_messages.h"
+#include "services/service_manager/public/cpp/bind_source_info.h"
#endif
class ChromeSitePerProcessTest : public InProcessBrowserTest {
@@ -518,57 +520,87 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest,
}
#if BUILDFLAG(ENABLE_SPELLCHECK)
-// Class to sniff incoming IPCs for spell check messages.
-class TestSpellCheckMessageFilter : public content::BrowserMessageFilter {
+// Class to sniff incoming spellcheck IPC / Mojo SpellCheckHost messages.
+class TestSpellCheckMessageFilter : public content::BrowserMessageFilter,
+ spellcheck::mojom::SpellCheckHost {
public:
explicit TestSpellCheckMessageFilter(content::RenderProcessHost* process_host)
: content::BrowserMessageFilter(SpellCheckMsgStart),
process_host_(process_host),
text_received_(false),
- message_loop_runner_(base::MakeShared<content::MessageLoopRunner>()) {}
+ message_loop_runner_(base::MakeShared<content::MessageLoopRunner>()),
+ binding_(this) {}
+
+ content::RenderProcessHost* process() const { return process_host_; }
+
+ const base::string16& text() const { return text_; }
+
+ void Wait() {
+ if (!text_received_)
+ message_loop_runner_->Run();
+ }
bool OnMessageReceived(const IPC::Message& message) override {
+#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
IPC_BEGIN_MESSAGE_MAP(TestSpellCheckMessageFilter, message)
-#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
- IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, HandleMessage)
-#else
+ // TODO(crbug.com/714480): convert the RequestTextCheck IPC to mojo.
IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestTextCheck, HandleMessage)
-#endif
IPC_END_MESSAGE_MAP()
+#endif
return false;
}
- base::string16 last_text() const { return last_text_; }
-
- void Wait() {
- if (!text_received_)
- message_loop_runner_->Run();
+#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+ void ShellCheckHostRequest(const service_manager::BindSourceInfo& source_info,
+ spellcheck::mojom::SpellCheckHostRequest request) {
+ EXPECT_FALSE(binding_.is_bound());
+ binding_.Bind(std::move(request));
}
-
- content::RenderProcessHost* process() const { return process_host_; }
+#endif
private:
~TestSpellCheckMessageFilter() override {}
+#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void HandleMessage(int, int, const base::string16& text) {
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
- base::BindOnce(&TestSpellCheckMessageFilter::HandleMessageOnUI, this,
- text));
+ base::BindOnce(&TestSpellCheckMessageFilter::HandleMessageOnUIThread,
+ this, text));
}
+#endif
- void HandleMessageOnUI(const base::string16& text) {
- last_text_ = text;
+ void HandleMessageOnUIThread(const base::string16& text) {
if (!text_received_) {
text_received_ = true;
+ text_ = text;
message_loop_runner_->Quit();
+ } else {
+ NOTREACHED();
}
}
+ // spellcheck::mojom::SpellCheckHost:
+ void RequestDictionary() override {}
+
+ void NotifyChecked(const base::string16& word, bool misspelled) override {}
+
+ void CallSpellingService(
+ const base::string16& text,
+ const CallSpellingServiceCallback& callback) override {
+#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ callback.Run(true, std::vector<SpellCheckResult>());
+ binding_.Close();
+ HandleMessageOnUIThread(text);
+#endif
+ }
+
content::RenderProcessHost* process_host_;
bool text_received_;
- base::string16 last_text_;
+ base::string16 text_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+ mojo::Binding<spellcheck::mojom::SpellCheckHost> binding_;
DISALLOW_COPY_AND_ASSIGN(TestSpellCheckMessageFilter);
};
@@ -586,6 +618,28 @@ class TestBrowserClientForSpellCheck : public ChromeContentBrowserClient {
ChromeContentBrowserClient::RenderProcessWillLaunch(process_host);
}
+#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+ void ExposeInterfacesToRenderer(
+ service_manager::BinderRegistry* registry,
+ content::AssociatedInterfaceRegistry* associated_registry,
+ content::RenderProcessHost* render_process_host) override {
+ // Expose the default interfaces.
+ ChromeContentBrowserClient::ExposeInterfacesToRenderer(
+ registry, associated_registry, render_process_host);
+
+ scoped_refptr<TestSpellCheckMessageFilter> filter =
+ GetSpellCheckMessageFilterForProcess(render_process_host);
+ CHECK(filter);
+
+ // Override the default SpellCheckHost interface.
+ auto ui_task_runner = content::BrowserThread::GetTaskRunnerForThread(
+ content::BrowserThread::UI);
+ registry->AddInterface(
+ base::Bind(&TestSpellCheckMessageFilter::ShellCheckHostRequest, filter),
+ ui_task_runner);
+ }
+#endif // !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+
// Retrieves the registered filter for the given RenderProcessHost. It will
// return nullptr if the RenderProcessHost was initialized while a different
// instance of ContentBrowserClient was in action.
@@ -618,14 +672,15 @@ IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, OOPIFSpellCheckTest) {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
- content::RenderFrameHost* subframe =
+ content::RenderFrameHost* cross_site_subframe =
ChildFrameAt(web_contents->GetMainFrame(), 0);
+
scoped_refptr<TestSpellCheckMessageFilter> filter =
browser_client.GetSpellCheckMessageFilterForProcess(
- subframe->GetProcess());
+ cross_site_subframe->GetProcess());
filter->Wait();
- EXPECT_EQ(base::ASCIIToUTF16("zz."), filter->last_text());
+ EXPECT_EQ(base::ASCIIToUTF16("zz."), filter->text());
content::SetBrowserClientForTesting(old_browser_client);
}
« no previous file with comments | « chrome/browser/chrome_content_browser_manifest_overlay.json ('k') | chrome/browser/spellchecker/spellcheck_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698