Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1355 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied()); | 1356 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied()); |
| 1356 | 1357 |
| 1357 // Now verify that the selection text propagates properly to RWHV. | 1358 // Now verify that the selection text propagates properly to RWHV. |
| 1358 content::RenderWidgetHostView* guest_rwhv = | 1359 content::RenderWidgetHostView* guest_rwhv = |
| 1359 guest_web_contents()->GetRenderWidgetHostView(); | 1360 guest_web_contents()->GetRenderWidgetHostView(); |
| 1360 ASSERT_TRUE(guest_rwhv); | 1361 ASSERT_TRUE(guest_rwhv); |
| 1361 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); | 1362 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); |
| 1362 ASSERT_TRUE(selected_text.size() >= 10u); | 1363 ASSERT_TRUE(selected_text.size() >= 10u); |
| 1363 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); | 1364 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
| 1364 } | 1365 } |
| 1366 | |
| 1367 // The original TextInputClientMessageFilter is added during the initialization | |
| 1368 // phase of RenderProcessHost. The only chance we have to add the test filter | |
| 1369 // (so that it can receive the TextInputClientMac incoming IPC messages) is | |
| 1370 // during the call to RenderProcessWillLaunch() on ContentBrowserClient. This | |
| 1371 // class provides that for testing. | |
| 1372 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.
| |
| 1373 public: | |
| 1374 TestBrowserClient() {} | |
| 1375 ~TestBrowserClient() override {} | |
| 1376 | |
| 1377 // ContentBrowserClient overrides. | |
| 1378 void RenderProcessWillLaunch( | |
| 1379 content::RenderProcessHost* process_host) override { | |
| 1380 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host); | |
| 1381 filters_.push_back( | |
| 1382 new content::TestTextInputClientMessageFilter(process_host)); | |
| 1383 } | |
| 1384 | |
| 1385 // Retrieves the registered filter for the given RenderProcessHost. It will | |
| 1386 // return false if the RenderProcessHost was initialized while a different | |
| 1387 // instance of ContentBrowserClient was in action. | |
| 1388 scoped_refptr<content::TestTextInputClientMessageFilter> | |
| 1389 GetTextInputClientMessageFilterForProcess( | |
| 1390 content::RenderProcessHost* process_host) const { | |
| 1391 for (auto filter : filters_) { | |
| 1392 if (filter->process() == process_host) | |
| 1393 return filter; | |
| 1394 } | |
| 1395 return nullptr; | |
| 1396 } | |
| 1397 | |
| 1398 private: | |
| 1399 std::vector<scoped_refptr<content::TestTextInputClientMessageFilter>> | |
| 1400 filters_; | |
| 1401 | |
| 1402 DISALLOW_COPY_AND_ASSIGN(TestBrowserClient); | |
| 1403 }; | |
| 1404 | |
| 1405 // Verifies that asking for a word lookup from a guest's RWHV will open the | |
| 1406 // 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
| |
| 1407 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.
| |
| 1408 // TestBrowserClient needs to replace the ChromeContentBrowserClient after | |
| 1409 // most things are initialized but before the WebContents is created. | |
| 1410 TestBrowserClient browser_client; | |
| 1411 content::ContentBrowserClient* old_browser_client = | |
| 1412 content::SetBrowserClientForTesting(&browser_client); | |
| 1413 | |
| 1414 SetupTest("web_view/text_selection", | |
| 1415 "/extensions/platform_apps/web_view/text_selection/guest.html"); | |
| 1416 ASSERT_TRUE(guest_web_contents()); | |
| 1417 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); | |
| 1418 | |
| 1419 auto guest_message_filter = | |
| 1420 browser_client.GetTextInputClientMessageFilterForProcess( | |
| 1421 guest_web_contents()->GetRenderProcessHost()); | |
| 1422 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!
| |
| 1423 | |
| 1424 // Lookup some string through context menu. | |
| 1425 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_LOOK_UP); | |
| 1426 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
| |
| 1427 blink::WebMouseEvent::Button::kRight, 20, 20); | |
| 1428 // Wait for the response form the guest renderer. | |
| 1429 guest_message_filter->WaitForStringFromRange(); | |
| 1430 | |
| 1431 // Sanity check. | |
| 1432 ASSERT_EQ("AAAA", guest_message_filter->string_from_range().substr(0, 4)); | |
| 1433 | |
| 1434 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
| |
| 1435 } | |
| 1365 #endif | 1436 #endif |
| 1366 | 1437 |
| 1367 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) { | 1438 IN_PROC_BROWSER_TEST_P(WebViewFocusInteractiveTest, FocusAndVisibility) { |
| 1368 ASSERT_TRUE(StartEmbeddedTestServer()); | 1439 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1369 LoadAndLaunchPlatformApp("web_view/focus_visibility", | 1440 LoadAndLaunchPlatformApp("web_view/focus_visibility", |
| 1370 "WebViewInteractiveTest.LOADED"); | 1441 "WebViewInteractiveTest.LOADED"); |
| 1371 ExtensionTestMessageListener test_init_listener( | 1442 ExtensionTestMessageListener test_init_listener( |
| 1372 "WebViewInteractiveTest.WebViewInitialized", false); | 1443 "WebViewInteractiveTest.WebViewInitialized", false); |
| 1373 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init"); | 1444 SendMessageToEmbedder(GetParam() ? "init-oopif" : "init"); |
| 1374 test_init_listener.WaitUntilSatisfied(); | 1445 test_init_listener.WaitUntilSatisfied(); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1589 // Get the input value from the guest. | 1660 // Get the input value from the guest. |
| 1590 value.clear(); | 1661 value.clear(); |
| 1591 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, | 1662 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, |
| 1592 "window.domAutomationController." | 1663 "window.domAutomationController." |
| 1593 "send(document.querySelector('" | 1664 "send(document.querySelector('" |
| 1594 "input').value)", | 1665 "input').value)", |
| 1595 &value)); | 1666 &value)); |
| 1596 EXPECT_EQ("A B C D", value); | 1667 EXPECT_EQ("A B C D", value); |
| 1597 } | 1668 } |
| 1598 #endif // OS_MACOSX | 1669 #endif // OS_MACOSX |
| OLD | NEW |