Index: chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
diff --git a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
index f6f563556e77ab03c263eeaa4243b5551fb07f67..55d5647d6fecedf779f5553e6aa27cd0373d7a79 100644 |
--- a/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
+++ b/chrome/browser/apps/guest_view/web_view_interactive_browsertest.cc |
@@ -562,11 +562,55 @@ class WebViewInteractiveTest : public WebViewInteractiveTestBase, |
base::test::ScopedFeatureList scoped_feature_list_; |
}; |
+class WebViewImeInteractiveTest : public WebViewInteractiveTest { |
+ protected: |
+ // This class observes all the composition range updates associated with the |
+ // TextInputManager of the provided WebContents. The WebContents should be an |
+ // outer most WebContents. |
+ class CompositionRangeUpdateObserver { |
+ public: |
+ explicit CompositionRangeUpdateObserver(content::WebContents* web_contents) |
+ : tester_(web_contents) { |
+ tester_.SetOnImeCompositionRangeChangedCallback( |
+ base::Bind(&CompositionRangeUpdateObserver::OnCompositionRangeUpdated, |
+ base::Unretained(this))); |
+ } |
+ ~CompositionRangeUpdateObserver() {} |
+ |
+ // Wait until a composition range update with a range length equal to |
+ // |length| is received. |
+ void WaitForCompositionRangeLength(uint32_t length) { |
+ 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!
|
+ last_composition_range_length_ == length) |
+ return; |
+ expected_length_ = length; |
+ run_loop_.reset(new base::RunLoop()); |
+ run_loop_->Run(); |
+ } |
+ |
+ private: |
+ void OnCompositionRangeUpdated() { |
+ did_update_composition_range_ = tester_.GetLastCompositionRangeLength( |
+ &last_composition_range_length_); |
+ ASSERT_TRUE(did_update_composition_range_); |
+ if (last_composition_range_length_ == expected_length_) |
+ run_loop_->Quit(); |
+ } |
+ |
+ content::TextInputManagerTester tester_; |
+ std::unique_ptr<base::RunLoop> run_loop_; |
+ bool did_update_composition_range_ = false; |
+ uint32_t last_composition_range_length_ = 0; |
+ uint32_t expected_length_ = 0; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CompositionRangeUpdateObserver); |
+ }; |
+}; |
+ |
class WebViewDragDropInteractiveTest : public WebViewInteractiveTest {}; |
class WebViewNewWindowInteractiveTest : public WebViewInteractiveTest {}; |
class WebViewFocusInteractiveTest : public WebViewInteractiveTest {}; |
class WebViewPointerLockInteractiveTest : public WebViewInteractiveTest {}; |
-class WebViewImeInteractiveTest : public WebViewInteractiveTest {}; |
// The tests below aren't needed in --use-cross-process-frames-for-guests. |
class WebViewContextMenuInteractiveTest : public WebViewInteractiveTestBase {}; |
@@ -1689,3 +1733,55 @@ IN_PROC_BROWSER_TEST_P(WebViewImeInteractiveTest, |
EXPECT_EQ("A B C D", value); |
} |
#endif // OS_MACOSX |
+ |
+// This test verifies that focusing an input inside a <webview> will put the |
+// guest process's render widget into a monitoring mode for composition range |
+// changes. |
+IN_PROC_BROWSER_TEST_P(WebViewImeInteractiveTest, CompositionRangeUpdates) { |
+ ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. |
+ LoadAndLaunchPlatformApp("web_view/ime", "WebViewImeTest.Launched"); |
+ ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())); |
+ |
+ // Flush any pending events to make sure we start with a clean slate. |
+ content::RunAllPendingInMessageLoop(); |
+ |
+ content::WebContents* guest_web_contents = |
+ GetGuestViewManager()->GetLastGuestCreated(); |
+ |
+ // Click the <input> element inside the <webview>. In its focus handle, the |
+ // <input> inside the <webview> initializes its value to "A B X D". |
+ ExtensionTestMessageListener focus_listener("WebViewImeTest.InputFocused", |
+ false); |
+ content::WebContents* embedder_web_contents = |
+ guest_view::GuestViewBase::FromWebContents(guest_web_contents) |
+ ->embedder_web_contents(); |
+ 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.
|
+ GetParam() ? guest_web_contents : embedder_web_contents; |
+ |
+ 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.
|
+ blink::WebMouseEvent::Button::kLeft, |
+ gfx::Point(50, 50)); |
+ focus_listener.WaitUntilSatisfied(); |
+ |
+ // Clear the string as it already contains some text. Then verify the text in |
+ // the <input> is empty. |
+ std::string value; |
+ ASSERT_TRUE(ExecuteScriptAndExtractString( |
+ guest_web_contents, |
+ "var input = document.querySelector('input');" |
+ "input.value = '';" |
+ "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!
|
+ "send(document.querySelector('" |
+ "input').value)", |
+ &value)); |
+ EXPECT_EQ("", value); |
+ |
+ // Now set some composition text which should lead to an update in composition |
+ // range information. |
+ CompositionRangeUpdateObserver observer(embedder_web_contents); |
+ content::SendImeSetCompositionTextToWidget( |
+ target_web_contents->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
+ base::UTF8ToUTF16("ABC"), std::vector<ui::CompositionUnderline>(), |
+ gfx::Range::InvalidRange(), 0, 3); |
+ observer.WaitForCompositionRangeLength(3U); |
+} |