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

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: Fixed a comment 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..17cdb418bfa3ed43d16549ac82413c5523fcecb1 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,76 @@ 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 {
lazyboy 2017/04/13 16:40:45 nit: rename class too less generic and more specif
EhsanK 2017/04/13 17:56:15 Done.
+ 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.
lazyboy 2017/04/13 16:40:45 I couldn't figure out which part is checking the p
EhsanK 2017/04/13 17:56:15 Yes sorry about the bad comment. That is what the
+IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, WordLookUp) {
lazyboy 2017/04/13 16:40:45 nit: WordLookup (small u) or LookUpWord
EhsanK 2017/04/13 17:56:15 Done.
+ // TestBrowserClient needs to replace the ChromeContentBrowserClient after
+ // most things are initialized but before the WebContents is created.
+ 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);
lazyboy 2017/04/13 16:40:45 Since we need this to be non-null in line 1429, we
EhsanK 2017/04/13 17:56:15 Done. Thanks!
+
+ // Lookup some string through context menu.
+ ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP);
+ SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost()->GetWidget(),
lazyboy 2017/04/13 16:40:45 Can you add a quick note about what the significan
EhsanK 2017/04/13 17:56:15 Sure. I guess that is where the text is (to be hig
+ 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);
lazyboy 2017/04/13 16:40:45 It's better to use a separate class that sets the
EhsanK 2017/04/13 17:56:15 Thanks for the suggestion. I implemented something
+}
#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