Chromium Code Reviews| Index: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
| diff --git a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
| index 2a7094e3c82898e2e33b0e7db4cb8c9f83352e14..3cc2547a8ef7863a0d6b54d4788c99fc967e815c 100644 |
| --- a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
| +++ b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/single_thread_task_runner.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/test/test_timeouts.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "build/build_config.h" |
| #include "chrome/app/chrome_command_ids.h" |
| @@ -1362,6 +1363,81 @@ IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, TextSelection) { |
| ASSERT_TRUE(selected_text.size() >= 10u); |
| ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
| } |
| + |
| +// The original TextInputClientMessageFilter is added during the initialization |
| +// phase of RenderProcessHost. The only chance we have to add the test filter |
| +// (so that it can receive the TextInputClientMac incoming IPC messages) is |
| +// during the call to RenderProcessWillLaunch() on ContentBrowserClient. This |
| +// class provides that for testing. |
| +class TestBrowserClient : public ChromeContentBrowserClient { |
| + public: |
| + TestBrowserClient() {} |
| + ~TestBrowserClient() override {} |
| + |
| + // ContentBrowserClient overrides. |
| + void RenderProcessWillLaunch( |
| + content::RenderProcessHost* process_host) override { |
| + ChromeContentBrowserClient::RenderProcessWillLaunch(process_host); |
| + filters_.push_back( |
| + new content::TestTextInputClientMessageFilter(process_host)); |
| + } |
| + |
| + // Retrieves the registered filter for the given RenderProcessHost. It will |
| + // return false if the RenderProcessHost was initialized while a different |
| + // instance of ContentBrowserClient was in action. |
| + scoped_refptr<content::TestTextInputClientMessageFilter> |
| + GetTextInputClientMessageFilterForProcess( |
| + content::RenderProcessHost* process_host) const { |
| + for (auto filter : filters_) { |
| + if (filter->process() == process_host) |
| + return filter; |
| + } |
| + return nullptr; |
| + } |
| + |
| + private: |
| + std::vector<scoped_refptr<content::TestTextInputClientMessageFilter>> |
| + filters_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestBrowserClient); |
| +}; |
| + |
| +// Verifies that asking for a word lookup from a guest's RWHV will open the |
| +// dictionary popup window. |
| +IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, WordLookUp) { |
| + // TestBrowserClient needs to replace the ChromeContenBrowserClient after most |
|
Avi (use Gerrit)
2017/04/13 14:48:53
typo: ChromeContentBrowserClient
EhsanK
2017/04/13 15:13:07
Thanks. Deleted most of the comment since we do no
|
| + // things are initialized but before the WebContents is created. Here we make |
| + // that happen by creating a new WebContents in a new tab. But before the test |
| + // exits, we must destroy the contents and replace the old |
| + // ContentBrowserClient because the original WebContents and the new one have |
| + // been initialized with the original ContentBrowserClient and the new |
| + // TestBrowserClient, respectively. |
| + TestBrowserClient browser_client; |
| + content::ContentBrowserClient* old_browser_client = |
| + content::SetBrowserClientForTesting(&browser_client); |
| + |
| + SetupTest("web_view/text_selection", |
| + "/extensions/platform_apps/web_view/text_selection/guest.html"); |
| + ASSERT_TRUE(guest_web_contents()); |
| + ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); |
| + |
| + auto guest_message_filter = |
| + browser_client.GetTextInputClientMessageFilterForProcess( |
| + guest_web_contents()->GetRenderProcessHost()); |
| + EXPECT_TRUE(guest_message_filter); |
| + |
| + // Lookup some string through context menu. |
| + ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP); |
| + SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost()->GetWidget(), |
| + blink::WebMouseEvent::Button::kRight, 20, 20); |
| + // Wait for the response form the guest renderer. |
| + guest_message_filter->WaitForStringFromRange(); |
| + |
| + // Sanity check. |
| + ASSERT_EQ("AAAA", guest_message_filter->string_from_range().substr(0, 4)); |
| + |
| + content::SetBrowserClientForTesting(old_browser_client); |
| +} |
| #endif |
| IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) { |