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

Unified Diff: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc

Issue 2817673003: Making Mac Dictionary better for OOPIFs and <webview> (Closed)
Patch Set: Remove ScopedBrowserClient Created 3 years, 8 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 | « no previous file | content/browser/frame_host/render_widget_host_view_child_frame.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4b334756950b7d472989455a1558a1956dbc15a8 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"
@@ -56,6 +57,51 @@ using guest_view::GuestViewManager;
using guest_view::TestGuestViewManager;
using guest_view::TestGuestViewManagerFactory;
+#if defined(OS_MACOSX)
+// 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. The class also replaces the current client
+// and will reset the client back to the original one upon destruction.
+class BrowserClientForTextInputClientMac : public ChromeContentBrowserClient {
+ public:
+ BrowserClientForTextInputClientMac()
+ : old_client_(content::SetBrowserClientForTesting(this)) {}
+ ~BrowserClientForTextInputClientMac() override {
+ content::SetBrowserClientForTesting(old_client_);
+ }
+
+ // 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:
+ content::ContentBrowserClient* old_client_;
+ std::vector<scoped_refptr<content::TestTextInputClientMessageFilter>>
+ filters_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserClientForTextInputClientMac);
+};
+#endif // OS_MACOSX
+
class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest {
public:
WebViewInteractiveTestBase()
@@ -1362,6 +1408,37 @@ IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, TextSelection) {
ASSERT_TRUE(selected_text.size() >= 10u);
ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
}
+
+// Verifies that asking for a word lookup from a guest will lead to a returned
+// IPC from the renderer containing the right selected word.
+IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, WordLookup) {
+ // BrowserClientForTextInputClientMac needs to replace the
+ // ChromeContentBrowserClient after most things are initialized but before the
+ // WebContents is created.
+ BrowserClientForTextInputClientMac 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());
+ ASSERT_TRUE(guest_message_filter);
+
+ // Lookup some string through context menu.
+ ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP);
+ // Simulating a mouse click at a position to highlight text in guest and
+ // showing the context menu.
+ 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));
+}
#endif
IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) {
« no previous file with comments | « no previous file | content/browser/frame_host/render_widget_host_view_child_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698