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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 WebViewDragDropInteractiveTest : public WebViewInteractiveTest {}; | 565 class WebViewDragDropInteractiveTest : public WebViewInteractiveTest {}; |
| 566 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; | 566 class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
| 567 class WebViewFocusInteractiveTest : public WebViewInteractiveTest {}; | 567 class WebViewFocusInteractiveTest : public WebViewInteractiveTest {}; |
| 568 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTest {}; | 568 class WebViewPointerLockInteractiveTest : public WebViewInteractiveTest {}; |
| 569 class WebViewImeInteractiveTest : public WebViewInteractiveTest {}; | 569 class WebViewImeInteractiveTest : public WebViewInteractiveTest { |
| 570 protected: | |
| 571 // This class observers all the composition range updates associated with the | |
|
Charlie Reis
2017/06/09 21:38:17
nit: observes :)
EhsanK
2017/06/12 13:41:22
Thanks! Sorry! My signature typo again.
| |
| 572 // TextInputManager of the provided WebContents. The WebContents should be an | |
| 573 // outer most WebContents. | |
| 574 class CompositionRangeUpdateObserver { | |
| 575 public: | |
| 576 explicit CompositionRangeUpdateObserver(content::WebContents* web_contents) | |
| 577 : tester_(web_contents) { | |
| 578 tester_.SetOnImeCompositionRangeChangedCallback( | |
| 579 base::Bind(&CompositionRangeUpdateObserver::OnCompositionRangeUpdated, | |
| 580 base::Unretained(this))); | |
| 581 } | |
| 582 ~CompositionRangeUpdateObserver() {} | |
| 583 | |
| 584 // Wait until a composition range update with a range length equal to | |
| 585 // |length| is received. | |
| 586 void WaitForCompositionRangeLength(uint32_t length) { | |
| 587 if (did_update_composition_range_ && | |
| 588 last_composition_range_length_ == length) | |
| 589 return; | |
| 590 expected_length_ = length; | |
| 591 run_loop_.reset(new base::RunLoop()); | |
| 592 run_loop_->Run(); | |
| 593 } | |
| 594 | |
| 595 private: | |
| 596 void OnCompositionRangeUpdated() { | |
| 597 did_update_composition_range_ = tester_.GetLastCompositionRangeLength( | |
| 598 &last_composition_range_length_); | |
| 599 ASSERT_TRUE(did_update_composition_range_); | |
| 600 if (last_composition_range_length_ == expected_length_) | |
| 601 run_loop_->Quit(); | |
| 602 } | |
| 603 | |
| 604 content::TextInputManagerTester tester_; | |
| 605 std::unique_ptr<base::RunLoop> run_loop_; | |
| 606 bool did_update_composition_range_ = false; | |
| 607 uint32_t last_composition_range_length_ = 0; | |
| 608 uint32_t expected_length_ = 0; | |
| 609 | |
| 610 DISALLOW_COPY_AND_ASSIGN(CompositionRangeUpdateObserver); | |
| 611 }; | |
| 612 }; | |
| 570 | 613 |
| 571 // The tests below aren't needed in --use-cross-process-frames-for-guests. | 614 // The tests below aren't needed in --use-cross-process-frames-for-guests. |
| 572 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; | 615 class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
| 573 | 616 |
| 574 // The following class of tests do not work for OOPIF <webview>. | 617 // 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 | 618 // TODO(ekaramad): Make this tests work with OOPIF and replace the test classes |
| 576 // with WebViewInteractiveTest (see crbug.com/582562). | 619 // with WebViewInteractiveTest (see crbug.com/582562). |
| 577 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; | 620 class WebViewPopupInteractiveTest : public WebViewInteractiveTestBase {}; |
| 578 | 621 |
| 579 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, | 622 INSTANTIATE_TEST_CASE_P(WebViewInteractiveTests, |
| (...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 // Get the input value from the guest. | 1725 // Get the input value from the guest. |
| 1683 value.clear(); | 1726 value.clear(); |
| 1684 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, | 1727 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, |
| 1685 "window.domAutomationController." | 1728 "window.domAutomationController." |
| 1686 "send(document.querySelector('" | 1729 "send(document.querySelector('" |
| 1687 "input').value)", | 1730 "input').value)", |
| 1688 &value)); | 1731 &value)); |
| 1689 EXPECT_EQ("A B C D", value); | 1732 EXPECT_EQ("A B C D", value); |
| 1690 } | 1733 } |
| 1691 #endif // OS_MACOSX | 1734 #endif // OS_MACOSX |
| 1735 | |
| 1736 IN_PROC_BROWSER_TEST_P(WebViewImeInteractiveTest, CompositionRangeUpdates) { | |
| 1737 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. | |
| 1738 LoadAndLaunchPlatformApp("web_view/ime", "WebViewImeTest.Launched"); | |
| 1739 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); | |
| 1740 | |
| 1741 // Flush any pending events to make sure we start with a clean slate. | |
| 1742 content::RunAllPendingInMessageLoop(); | |
| 1743 | |
| 1744 content::WebContents* guest_web_contents = | |
| 1745 GetGuestViewManager()->GetLastGuestCreated(); | |
| 1746 | |
| 1747 // Click the <input> element inside the <webview>. In its focus handle, the | |
| 1748 // <input> inside the <webview> initializes its value to "A B X D". | |
| 1749 ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused", | |
| 1750 false); | |
| 1751 content::WebContents* embedder_web_contents = | |
| 1752 guest_view::GuestViewBase::FromWebContents(guest_web_contents) | |
| 1753 ->embedder_web_contents(); | |
| 1754 content::WebContents* target_web_contents = | |
| 1755 GetParam() ? guest_web_contents : embedder_web_contents; | |
| 1756 | |
| 1757 content::SimulateMouseClickAt(target_web_contents, 0, | |
| 1758 blink::WebMouseEvent::Button::kLeft, | |
| 1759 gfx::Point(50, 50)); | |
| 1760 focus_listener.WaitUntilSatisfied(); | |
| 1761 | |
| 1762 // Clear the string as it already contains some text. | |
| 1763 // Verify the text inside the <input> is "A B X D". | |
|
Charlie Reis
2017/06/09 21:38:17
I don't see anything verifying this. Is the comme
EhsanK
2017/06/12 13:41:22
Thanks! It should be empty "" instead.
| |
| 1764 std::string value; | |
| 1765 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 1766 guest_web_contents, | |
| 1767 "var input = document.querySelector('input');" | |
| 1768 "input.value = '';" | |
| 1769 "window.domAutomationController." | |
| 1770 "send(document.querySelector('" | |
| 1771 "input').value)", | |
| 1772 &value)); | |
| 1773 EXPECT_EQ("", value); | |
| 1774 | |
| 1775 // Now set some composition text which should lead to an update in composition | |
| 1776 // range information. | |
| 1777 CompositionRangeUpdateObserver observer(embedder_web_contents); | |
| 1778 content::SendImeSetCompositionTextToWidget( | |
| 1779 target_web_contents->GetRenderWidgetHostView()->GetRenderWidgetHost(), | |
| 1780 base::UTF8ToUTF16("ABC"), std::vector<ui::CompositionUnderline>(), | |
| 1781 gfx::Range::InvalidRange(), 0, 3); | |
| 1782 observer.WaitForCompositionRangeLength(3U); | |
| 1783 } | |
| OLD | NEW |