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" |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 } else { | 555 } else { |
| 556 scoped_feature_list_.InitAndDisableFeature( | 556 scoped_feature_list_.InitAndDisableFeature( |
| 557 features::kGuestViewCrossProcessFrames); | 557 features::kGuestViewCrossProcessFrames); |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 private: | 561 private: |
| 562 base::test::ScopedFeatureList scoped_feature_list_; | 562 base::test::ScopedFeatureList scoped_feature_list_; |
| 563 }; | 563 }; |
| 564 | 564 |
| 565 class WebViewImeInteractiveTest : public WebViewInteractiveTest { | |
| 566 protected: | |
| 567 // This class observes all the composition range updates associated with the | |
| 568 // TextInputManager of the provided WebContents. The WebContents should be an | |
| 569 // outer most WebContents. | |
| 570 class CompositionRangeUpdateObserver { | |
| 571 public: | |
| 572 explicit CompositionRangeUpdateObserver(content::WebContents* web_contents) | |
| 573 : tester_(web_contents) { | |
| 574 tester_.SetOnImeCompositionRangeChangedCallback( | |
| 575 base::Bind(&CompositionRangeUpdateObserver::OnCompositionRangeUpdated, | |
| 576 base::Unretained(this))); | |
| 577 } | |
| 578 ~CompositionRangeUpdateObserver() {} | |
| 579 | |
| 580 // Wait until a composition range update with a range length equal to | |
| 581 // |length| is received. | |
| 582 void WaitForCompositionRangeLength(uint32_t length) { | |
| 583 if (last_composition_range_length_.has_value() && | |
| 584 last_composition_range_length_.value() == length) | |
| 585 return; | |
| 586 expected_length_ = length; | |
| 587 run_loop_.reset(new base::RunLoop()); | |
| 588 run_loop_->Run(); | |
| 589 } | |
| 590 | |
| 591 private: | |
| 592 void OnCompositionRangeUpdated() { | |
| 593 uint32_t length; | |
|
Charlie Reis
2017/06/14 19:57:22
nit: Let's initialize this to something like -1.
EhsanK
2017/06/14 21:51:19
Done.
| |
| 594 if (tester_.GetLastCompositionRangeLength(&length)) { | |
| 595 last_composition_range_length_ = length; | |
| 596 } | |
| 597 if (last_composition_range_length_.value() == expected_length_) | |
| 598 run_loop_->Quit(); | |
| 599 } | |
| 600 | |
| 601 content::TextInputManagerTester tester_; | |
| 602 std::unique_ptr<base::RunLoop> run_loop_; | |
| 603 base::Optional<uint32_t> last_composition_range_length_; | |
| 604 uint32_t expected_length_ = 0; | |
| 605 | |
| 606 DISALLOW_COPY_AND_ASSIGN(CompositionRangeUpdateObserver); | |
| 607 }; | |
| 608 }; | |
| 609 | |
| 565 class WebViewDragDropInteractiveTest : public WebViewInteractiveTest {}; | 610 class WebViewDragDropInteractiveTest : public WebViewInteractiveTest {}; |
| 566 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; | 611 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
| 567 class WebViewFocusInteractiveTest : public WebViewInteractiveTest {}; | 612 class WebViewFocusInteractiveTest : public WebViewInteractiveTest {}; |
| 568 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTest {}; | 613 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTest {}; |
| 569 class WebViewImeInteractiveTest : public WebViewInteractiveTest {}; | |
| 570 | 614 |
| 571 // The tests below aren't needed in --use-cross-process-frames-for-guests. | 615 // The tests below aren't needed in --use-cross-process-frames-for-guests. |
| 572 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; | 616 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
| 573 | 617 |
| 574 // The following class of tests do not work for OOPIF <webview>. | 618 // The following class of tests do not work for OOPIF <webview>. |
| 575 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes | 619 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
| 576 // with WebViewInteractiveTest (see crbug.com/582562). | 620 // with WebViewInteractiveTest (see crbug.com/582562). |
| 577 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; | 621 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; |
| 578 | 622 |
| 579 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 623 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1646 | 1690 |
| 1647 // Click the <input> element inside the <webview>. In its focus handle, the | 1691 // Click the <input> element inside the <webview>. In its focus handle, the |
| 1648 // <input> inside the <webview> initializes its value to "A B X D". | 1692 // <input> inside the <webview> initializes its value to "A B X D". |
| 1649 ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused", | 1693 ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused", |
| 1650 false); | 1694 false); |
| 1651 content::WebContents* target_web_contents = | 1695 content::WebContents* target_web_contents = |
| 1652 GetParam() | 1696 GetParam() |
| 1653 ? guest_web_contents | 1697 ? guest_web_contents |
| 1654 : guest_view::GuestViewBase::FromWebContents(guest_web_contents) | 1698 : guest_view::GuestViewBase::FromWebContents(guest_web_contents) |
| 1655 ->embedder_web_contents(); | 1699 ->embedder_web_contents(); |
| 1700 | |
| 1701 // The guest page has a large input box and (50, 50) lies inside the box. | |
| 1656 content::SimulateMouseClickAt(target_web_contents, 0, | 1702 content::SimulateMouseClickAt(target_web_contents, 0, |
| 1657 blink::WebMouseEvent::Button::kLeft, | 1703 blink::WebMouseEvent::Button::kLeft, |
| 1658 gfx::Point(50, 50)); | 1704 gfx::Point(50, 50)); |
| 1659 focus_listener.WaitUntilSatisfied(); | 1705 focus_listener.WaitUntilSatisfied(); |
| 1660 | 1706 |
| 1661 // Verify the text inside the <input> is "A B X D". | 1707 // Verify the text inside the <input> is "A B X D". |
| 1662 std::string value; | 1708 std::string value; |
| 1663 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, | 1709 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, |
| 1664 "window.domAutomationController." | 1710 "window.domAutomationController." |
| 1665 "send(document.querySelector('" | 1711 "send(document.querySelector('" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1682 // Get the input value from the guest. | 1728 // Get the input value from the guest. |
| 1683 value.clear(); | 1729 value.clear(); |
| 1684 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, | 1730 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, |
| 1685 "window.domAutomationController." | 1731 "window.domAutomationController." |
| 1686 "send(document.querySelector('" | 1732 "send(document.querySelector('" |
| 1687 "input').value)", | 1733 "input').value)", |
| 1688 &value)); | 1734 &value)); |
| 1689 EXPECT_EQ("A B C D", value); | 1735 EXPECT_EQ("A B C D", value); |
| 1690 } | 1736 } |
| 1691 #endif // OS_MACOSX | 1737 #endif // OS_MACOSX |
| 1738 | |
| 1739 // This test verifies that focusing an input inside a <webview> will put the | |
| 1740 // guest process's render widget into a monitoring mode for composition range | |
| 1741 // changes. | |
| 1742 IN_PROC_BROWSER_TEST_P(WebViewImeInteractiveTest, CompositionRangeUpdates) { | |
| 1743 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. | |
| 1744 LoadAndLaunchPlatformApp("web_view/ime", "WebViewImeTest.Launched"); | |
| 1745 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); | |
| 1746 | |
| 1747 // Flush any pending events to make sure we start with a clean slate. | |
| 1748 content::RunAllPendingInMessageLoop(); | |
| 1749 | |
| 1750 content::WebContents* guest_web_contents = | |
| 1751 GetGuestViewManager()->GetLastGuestCreated(); | |
| 1752 | |
| 1753 // Click the <input> element inside the <webview>. In its focus handle, the | |
| 1754 // <input> inside the <webview> initializes its value to "A B X D". | |
| 1755 ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused", | |
| 1756 false); | |
| 1757 content::WebContents* embedder_web_contents = | |
| 1758 guest_view::GuestViewBase::FromWebContents(guest_web_contents) | |
| 1759 ->embedder_web_contents(); | |
| 1760 | |
| 1761 // Event routing in OOPIF and non-OOPIF <webview> is different. With OOPIF, | |
| 1762 // input is directly routed to the guest process as opposed to the non OOPIF | |
| 1763 // mode where input is always sent to the embedder process first (then hops | |
| 1764 // back to the browser and then to the guest). | |
| 1765 content::WebContents* target_web_contents = | |
| 1766 GetParam() ? guest_web_contents : embedder_web_contents; | |
| 1767 | |
| 1768 // The guest page has a large input box and (50, 50) lies inside the box. | |
| 1769 content::SimulateMouseClickAt(target_web_contents, 0, | |
| 1770 blink::WebMouseEvent::Button::kLeft, | |
| 1771 gfx::Point(50, 50)); | |
| 1772 focus_listener.WaitUntilSatisfied(); | |
| 1773 | |
| 1774 // Clear the string as it already contains some text. Then verify the text in | |
| 1775 // the <input> is empty. | |
| 1776 std::string value; | |
| 1777 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 1778 guest_web_contents, | |
| 1779 "var input = document.querySelector('input');" | |
| 1780 "input.value = '';" | |
| 1781 "window.domAutomationController.send(" | |
| 1782 " document.querySelector('input').value)", | |
| 1783 &value)); | |
| 1784 EXPECT_EQ("", value); | |
| 1785 | |
| 1786 // Now set some composition text which should lead to an update in composition | |
| 1787 // range information. | |
| 1788 CompositionRangeUpdateObserver observer(embedder_web_contents); | |
| 1789 content::SendImeSetCompositionTextToWidget( | |
| 1790 target_web_contents->GetRenderWidgetHostView()->GetRenderWidgetHost(), | |
| 1791 base::UTF8ToUTF16("ABC"), std::vector<ui::CompositionUnderline>(), | |
| 1792 gfx::Range::InvalidRange(), 0, 3); | |
| 1793 observer.WaitForCompositionRangeLength(3U); | |
| 1794 } | |
| OLD | NEW |