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

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

Issue 2929543002: Request Composition Range Updates for Focused GuestViews based on BrowserPlugins (Closed)
Patch Set: Added a comment Created 3 years, 6 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/browser_plugin/browser_plugin_guest.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"
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (did_update_composition_range_ &&
lazyboy 2017/06/12 21:35:08 nit: base::Optional is better suited for this kind
EhsanK 2017/06/13 20:56:56 Done. Thanks for the suggestions!
584 last_composition_range_length_ == 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 did_update_composition_range_ = tester_.GetLastCompositionRangeLength(
594 &last_composition_range_length_);
595 ASSERT_TRUE(did_update_composition_range_);
596 if (last_composition_range_length_ == expected_length_)
597 run_loop_->Quit();
598 }
599
600 content::TextInputManagerTester tester_;
601 std::unique_ptr<base::RunLoop> run_loop_;
602 bool did_update_composition_range_ = false;
603 uint32_t last_composition_range_length_ = 0;
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 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 // Get the input value from the guest. 1726 // Get the input value from the guest.
1683 value.clear(); 1727 value.clear();
1684 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents, 1728 ASSERT_TRUE(ExecuteScriptAndExtractString(guest_web_contents,
1685 "window.domAutomationController." 1729 "window.domAutomationController."
1686 "send(document.querySelector('" 1730 "send(document.querySelector('"
1687 "input').value)", 1731 "input').value)",
1688 &value)); 1732 &value));
1689 EXPECT_EQ("A B C D", value); 1733 EXPECT_EQ("A B C D", value);
1690 } 1734 }
1691 #endif // OS_MACOSX 1735 #endif // OS_MACOSX
1736
1737 // This test verifies that focusing an input inside a <webview> will put the
1738 // guest process's render widget into a monitoring mode for composition range
1739 // changes.
1740 IN_PROC_BROWSER_TEST_P(WebViewImeInteractiveTest, CompositionRangeUpdates) {
1741 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
1742 LoadAndLaunchPlatformApp("web_view/ime", "WebViewImeTest.Launched");
1743 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
1744
1745 // Flush any pending events to make sure we start with a clean slate.
1746 content::RunAllPendingInMessageLoop();
1747
1748 content::WebContents* guest_web_contents =
1749 GetGuestViewManager()->GetLastGuestCreated();
1750
1751 // Click the <input> element inside the <webview>. In its focus handle, the
1752 // <input> inside the <webview> initializes its value to "A B X D".
1753 ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused",
1754 false);
1755 content::WebContents* embedder_web_contents =
1756 guest_view::GuestViewBase::FromWebContents(guest_web_contents)
1757 ->embedder_web_contents();
1758 content::WebContents* target_web_contents =
lazyboy 2017/06/12 21:35:08 Add a note why there is a difference in WebContent
EhsanK 2017/06/13 20:56:56 Done.
1759 GetParam() ? guest_web_contents : embedder_web_contents;
1760
1761 content::SimulateMouseClickAt(target_web_contents, 0,
lazyboy 2017/06/12 21:35:08 It always helps to point out in comments why (50,
EhsanK 2017/06/13 20:56:56 Done.
1762 blink::WebMouseEvent::Button::kLeft,
1763 gfx::Point(50, 50));
1764 focus_listener.WaitUntilSatisfied();
1765
1766 // Clear the string as it already contains some text. Then verify the text in
1767 // the <input> is empty.
1768 std::string value;
1769 ASSERT_TRUE(ExecuteScriptAndExtractString(
1770 guest_web_contents,
1771 "var input = document.querySelector('input');"
1772 "input.value = '';"
1773 "window.domAutomationController."
lazyboy 2017/06/12 21:35:07 super nit: the line breaking is hard to read may b
EhsanK 2017/06/13 20:56:56 Done. Added some indentation as well!
1774 "send(document.querySelector('"
1775 "input').value)",
1776 &value));
1777 EXPECT_EQ("", value);
1778
1779 // Now set some composition text which should lead to an update in composition
1780 // range information.
1781 CompositionRangeUpdateObserver observer(embedder_web_contents);
1782 content::SendImeSetCompositionTextToWidget(
1783 target_web_contents->GetRenderWidgetHostView()->GetRenderWidgetHost(),
1784 base::UTF8ToUTF16("ABC"), std::vector<ui::CompositionUnderline>(),
1785 gfx::Range::InvalidRange(), 0, 3);
1786 observer.WaitForCompositionRangeLength(3U);
1787 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/browser_plugin/browser_plugin_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698