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

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: 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 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. The class also replaces the current client
66 // and will reset the client back to the original one upon destruction.
67 class BrowserClientForTextInputClientMac : public ChromeContentBrowserClient {
68 public:
69 BrowserClientForTextInputClientMac()
70 : old_client_(content::SetBrowserClientForTesting(this)) {}
71 ~BrowserClientForTextInputClientMac() override {
72 content::SetBrowserClientForTesting(old_client_);
73 }
74
75 // ContentBrowserClient overrides.
76 void RenderProcessWillLaunch(
77 content::RenderProcessHost* process_host) override {
78 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host);
79 filters_.push_back(
80 new content::TestTextInputClientMessageFilter(process_host));
81 }
82
83 // Retrieves the registered filter for the given RenderProcessHost. It will
84 // return false if the RenderProcessHost was initialized while a different
85 // instance of ContentBrowserClient was in action.
86 scoped_refptr<content::TestTextInputClientMessageFilter>
87 GetTextInputClientMessageFilterForProcess(
88 content::RenderProcessHost* process_host) const {
89 for (auto filter : filters_) {
90 if (filter->process() == process_host)
91 return filter;
92 }
93 return nullptr;
94 }
95
96 private:
97 content::ContentBrowserClient* old_client_;
98 std::vector<scoped_refptr<content::TestTextInputClientMessageFilter>>
99 filters_;
100
101 DISALLOW_COPY_AND_ASSIGN(BrowserClientForTextInputClientMac);
102 };
103 #endif // OS_MACOSX
104
59 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest { 105 class WebViewInteractiveTestBase : public extensions::PlatformAppBrowserTest {
60 public: 106 public:
61 WebViewInteractiveTestBase() 107 WebViewInteractiveTestBase()
62 : guest_web_contents_(NULL), 108 : guest_web_contents_(NULL),
63 embedder_web_contents_(NULL), 109 embedder_web_contents_(NULL),
64 corner_(gfx::Point()), 110 corner_(gfx::Point()),
65 mouse_click_result_(false), 111 mouse_click_result_(false),
66 first_click_(true) { 112 first_click_(true) {
67 GuestViewManager::set_factory_for_testing(&factory_); 113 GuestViewManager::set_factory_for_testing(&factory_);
68 } 114 }
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1355 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied()); 1401 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied());
1356 1402
1357 // Now verify that the selection text propagates properly to RWHV. 1403 // Now verify that the selection text propagates properly to RWHV.
1358 content::RenderWidgetHostView* guest_rwhv = 1404 content::RenderWidgetHostView* guest_rwhv =
1359 guest_web_contents()->GetRenderWidgetHostView(); 1405 guest_web_contents()->GetRenderWidgetHostView();
1360 ASSERT_TRUE(guest_rwhv); 1406 ASSERT_TRUE(guest_rwhv);
1361 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); 1407 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1362 ASSERT_TRUE(selected_text.size() >= 10u); 1408 ASSERT_TRUE(selected_text.size() >= 10u);
1363 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); 1409 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1364 } 1410 }
1411
1412 // Verifies that asking for a word lookup from a guest will lead to a returned
1413 // IPC from the renderer containing the right selected word.
1414 IN_PROC_BROWSER_TEST_P(WebViewInteractiveTest, WordLookup) {
1415 // BrowserClientForTextInputClientMac needs to replace the
1416 // ChromeContentBrowserClient after most things are initialized but before the
1417 // WebContents is created.
1418 BrowserClientForTextInputClientMac browser_client;
1419
1420 SetupTest("web_view/text_selection",
1421 "/extensions/platform_apps/web_view/text_selection/guest.html");
1422 ASSERT_TRUE(guest_web_contents());
1423 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
1424
1425 auto guest_message_filter =
1426 browser_client.GetTextInputClientMessageFilterForProcess(
1427 guest_web_contents()->GetRenderProcessHost());
1428 ASSERT_TRUE(guest_message_filter);
1429
1430 // Lookup some string through context menu.
1431 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP);
1432 // Simulating a mouse click at a position to highlight text in guest and
1433 // showing the context menu.
1434 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost()->GetWidget(),
1435 blink::WebMouseEvent::Button::kRight, 20, 20);
1436 // Wait for the response form the guest renderer.
1437 guest_message_filter->WaitForStringFromRange();
1438
1439 // Sanity check.
1440 ASSERT_EQ("AAAA", guest_message_filter->string_from_range().substr(0, 4));
1441 }
1365 #endif 1442 #endif
1366 1443
1367 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) { 1444 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) {
1368 ASSERT_TRUE(StartEmbeddedTestServer()); 1445 ASSERT_TRUE(StartEmbeddedTestServer());
1369 LoadAndLaunchPlatformApp("web_view/focus_visibility", 1446 LoadAndLaunchPlatformApp("web_view/focus_visibility",
1370 "WebViewInteractiveTest.LOADED"); 1447 "WebViewInteractiveTest.LOADED");
1371 ExtensionTestMessageListener test_init_listener( 1448 ExtensionTestMessageListener test_init_listener(
1372 "WebViewInteractiveTest.WebViewInitialized", false); 1449 "WebViewInteractiveTest.WebViewInitialized", false);
1373 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init"); 1450 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init");
1374 test_init_listener.WaitUntilSatisfied(); 1451 test_init_listener.WaitUntilSatisfied();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 // Get the input value from the guest. 1666 // Get the input value from the guest.
1590 value.clear(); 1667 value.clear();
1591 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, 1668 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents,
1592 "window.domAutomationController." 1669 "window.domAutomationController."
1593 "send(document.querySelector('" 1670 "send(document.querySelector('"
1594 "input').value)", 1671 "input').value)",
1595 &value)); 1672 &value));
1596 EXPECT_EQ("A B C D", value); 1673 EXPECT_EQ("A B C D", value);
1597 } 1674 }
1598 #endif // OS_MACOSX 1675 #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