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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc

Issue 2817673003: Making Mac Dictionary better for OOPIFs and <webview> (Closed)
Patch Set: Addressing lazyboy@'s comments 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/test_timeouts.h"
12 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/apps/app_browsertest_util.h" 16 #include "chrome/browser/apps/app_browsertest_util.h"
16 #include "chrome/browser/chrome_content_browser_client.h" 17 #include "chrome/browser/chrome_content_browser_client.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
19 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
20 #include "chrome/test/base/interactive_test_utils.h" 21 #include "chrome/test/base/interactive_test_utils.h"
21 #include "chrome/test/base/test_launcher_utils.h" 22 #include "chrome/test/base/test_launcher_utils.h"
(...skipping 27 matching lines...) Expand all
49 #include "ui/events/keycodes/keyboard_codes.h" 50 #include "ui/events/keycodes/keyboard_codes.h"
50 #include "ui/gfx/range/range.h" 51 #include "ui/gfx/range/range.h"
51 52
52 using extensions::AppWindow; 53 using extensions::AppWindow;
53 using extensions::ExtensionsAPIClient; 54 using extensions::ExtensionsAPIClient;
54 using guest_view::GuestViewBase; 55 using guest_view::GuestViewBase;
55 using guest_view::GuestViewManager; 56 using guest_view::GuestViewManager;
56 using guest_view::TestGuestViewManager; 57 using guest_view::TestGuestViewManager;
57 using guest_view::TestGuestViewManagerFactory; 58 using guest_view::TestGuestViewManagerFactory;
58 59
60 #if defined(OS_MACOSX)
61 // The original TextInputClientMessageFilter is added during the initialization
62 // phase of RenderProcessHost. The only chance we have to add the test filter
63 // (so that it can receive the TextInputClientMac incoming IPC messages) is
64 // during the call to RenderProcessWillLaunch() on ContentBrowserClient. This
65 // class provides that for testing.
66 class BrowserClientForTextInputClientMac : public ChromeContentBrowserClient {
67 public:
68 BrowserClientForTextInputClientMac() {}
69 ~BrowserClientForTextInputClientMac() override {}
70
71 // ContentBrowserClient overrides.
72 void RenderProcessWillLaunch(
73 content::RenderProcessHost* process_host) override {
74 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host);
75 filters_.push_back(
76 new content::TestTextInputClientMessageFilter(process_host));
77 }
78
79 // Retrieves the registered filter for the given RenderProcessHost. It will
80 // return false if the RenderProcessHost was initialized while a different
81 // instance of ContentBrowserClient was in action.
82 scoped_refptr<content::TestTextInputClientMessageFilter>
83 GetTextInputClientMessageFilterForProcess(
84 content::RenderProcessHost* process_host) const {
85 for (auto filter : filters_) {
86 if (filter->process() == process_host)
87 return filter;
88 }
89 return nullptr;
90 }
91
92 private:
93 std::vector<scoped_refptr<content::TestTextInputClientMessageFilter>>
94 filters_;
95
96 DISALLOW_COPY_AND_ASSIGN(BrowserClientForTextInputClientMac);
97 };
98
99 // Helper class to temporarily replace the ContentBrowserClient with the one
100 // provided.
101 class ScopedBrowserClient {
102 public:
103 explicit ScopedBrowserClient(content::ContentBrowserClient* client)
104 : old_client_(content::SetBrowserClientForTesting(client)) {}
105 ~ScopedBrowserClient() { content::SetBrowserClientForTesting(old_client_); }
106
107 private:
108 content::ContentBrowserClient* old_client_;
109
110 DISALLOW_COPY_AND_ASSIGN(ScopedBrowserClient);
111 };
112 #endif // OS_MACOSX
113
59 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest { 114 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest {
60 public: 115 public:
61 WebViewInteractiveTestBase() 116 WebViewInteractiveTestBase()
62 : guest_web_contents_(NULL), 117 : guest_web_contents_(NULL),
63 embedder_web_contents_(NULL), 118 embedder_web_contents_(NULL),
64 corner_(gfx::Point()), 119 corner_(gfx::Point()),
65 mouse_click_result_(false), 120 mouse_click_result_(false),
66 first_click_(true) { 121 first_click_(true) {
67 GuestViewManager::set_factory_for_testing(&factory_); 122 GuestViewManager::set_factory_for_testing(&factory_);
68 } 123 }
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied()); 1410 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied());
1356 1411
1357 // Now verify that the selection text propagates properly to RWHV. 1412 // Now verify that the selection text propagates properly to RWHV.
1358 content::RenderWidgetHostView* guest_rwhv = 1413 content::RenderWidgetHostView* guest_rwhv =
1359 guest_web_contents()->GetRenderWidgetHostView(); 1414 guest_web_contents()->GetRenderWidgetHostView();
1360 ASSERT_TRUE(guest_rwhv); 1415 ASSERT_TRUE(guest_rwhv);
1361 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); 1416 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1362 ASSERT_TRUE(selected_text.size() >= 10u); 1417 ASSERT_TRUE(selected_text.size() >= 10u);
1363 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); 1418 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1364 } 1419 }
1420
1421 // Verifies that asking for a word lookup from a guest will lead to a returned
1422 // IPC from the renderer containing the right selected word.
1423 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, WordLookup) {
1424 // BrowserClientForTextInputClientMac needs to replace the
1425 // ChromeContentBrowserClient after most things are initialized but before the
1426 // WebContents is created.
1427 BrowserClientForTextInputClientMac browser_client;
lazyboy 2017/04/13 18:08:18 optional: You could actually put the scoping logic
1428 ScopedBrowserClient scoped_client(&browser_client);
1429
1430 SetupTest("web_view/text_selection",
1431 "/extensions/platform_apps/web_view/text_selection/guest.html");
1432 ASSERT_TRUE(guest_web_contents());
1433 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
1434
1435 auto guest_message_filter =
1436 browser_client.GetTextInputClientMessageFilterForProcess(
1437 guest_web_contents()->GetRenderProcessHost());
1438 ASSERT_TRUE(guest_message_filter);
1439
1440 // Lookup some string through context menu.
1441 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP);
1442 // Simulating a mouse click at a position to highlight text in guest and
1443 // showing the context menu.
1444 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost()->GetWidget(),
1445 blink::WebMouseEvent::Button::kRight, 20, 20);
1446 // Wait for the response form the guest renderer.
1447 guest_message_filter->WaitForStringFromRange();
1448
1449 // Sanity check.
1450 ASSERT_EQ("AAAA", guest_message_filter->string_from_range().substr(0, 4));
1451 }
1365 #endif 1452 #endif
1366 1453
1367 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) { 1454 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) {
1368 ASSERT_TRUE(StartEmbeddedTestServer()); 1455 ASSERT_TRUE(StartEmbeddedTestServer());
1369 LoadAndLaunchPlatformApp("web_view/focus_visibility", 1456 LoadAndLaunchPlatformApp("web_view/focus_visibility",
1370 "WebViewInteractiveTest.LOADED"); 1457 "WebViewInteractiveTest.LOADED");
1371 ExtensionTestMessageListener test_init_listener( 1458 ExtensionTestMessageListener test_init_listener(
1372 "WebViewInteractiveTest.WebViewInitialized", false); 1459 "WebViewInteractiveTest.WebViewInitialized", false);
1373 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init"); 1460 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init");
1374 test_init_listener.WaitUntilSatisfied(); 1461 test_init_listener.WaitUntilSatisfied();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 // Get the input value from the guest. 1676 // Get the input value from the guest.
1590 value.clear(); 1677 value.clear();
1591 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, 1678 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents,
1592 "window.domAutomationController." 1679 "window.domAutomationController."
1593 "send(document.querySelector('" 1680 "send(document.querySelector('"
1594 "input').value)", 1681 "input').value)",
1595 &value)); 1682 &value));
1596 EXPECT_EQ("A B C D", value); 1683 EXPECT_EQ("A B C D", value);
1597 } 1684 }
1598 #endif // OS_MACOSX 1685 #endif // OS_MACOSX
OLDNEW
« 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