Index: content/browser/site_per_process_browsertest.cc |
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc |
index f579093fb7123c1d014fecfc0aed3222740c7aa1..15b66f9afcfad72d171046b6b83f8300393043ec 100644 |
--- a/content/browser/site_per_process_browsertest.cc |
+++ b/content/browser/site_per_process_browsertest.cc |
@@ -8001,4 +8001,117 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
EXPECT_TRUE(ExecuteScript(popup_shell->web_contents(), "true")); |
} |
+#if defined(OS_MACOSX) |
+class TextInputClientMacHelper { |
+ public: |
+ TextInputClientMacHelper() {} |
+ ~TextInputClientMacHelper() {} |
+ |
+ void WaitForStringFromRange(RenderWidgetHost* rwh, const gfx::Range& range) { |
+ GetStringFromRangeForRenderWidget( |
+ rwh, range, base::Bind(&TextInputClientMacHelper::OnResult, |
+ base::Unretained(this))); |
+ loop_runner_ = new MessageLoopRunner(); |
+ loop_runner_->Run(); |
+ } |
+ |
+ void WaitForStringAtPoint(RenderWidgetHost* rwh, const gfx::Point& point) { |
+ GetStringAtPointForRenderWidget( |
+ rwh, point, base::Bind(&TextInputClientMacHelper::OnResult, |
+ base::Unretained(this))); |
+ loop_runner_ = new MessageLoopRunner(); |
+ loop_runner_->Run(); |
+ } |
+ const std::string& word() const { return word_; } |
+ const gfx::Point& point() const { return point_; } |
+ |
+ private: |
+ void OnResult(const std::string& string, const gfx::Point& point) { |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ base::Bind(&TextInputClientMacHelper::OnResult, |
+ base::Unretained(this), string, point)); |
+ return; |
+ } |
+ word_ = string; |
+ point_ = point; |
+ |
+ if (loop_runner_ && loop_runner_->loop_running()) |
+ loop_runner_->Quit(); |
+ } |
+ |
+ std::string word_; |
+ gfx::Point point_; |
+ scoped_refptr<MessageLoopRunner> loop_runner_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TextInputClientMacHelper); |
+}; |
+ |
+// Tests related to TextInputClientMac. |
+class SitePerProcessTextInputClientMacTest : public SitePerProcessBrowserTest { |
Charlie Reis
2016/09/02 21:57:47
We should probably put this in a new test file. T
EhsanK
2016/09/08 17:10:40
Sure. Is it OK to open up a new file just for this
Charlie Reis
2016/09/09 22:23:32
Yes, creating a new file for it will be fine.
EhsanK
2016/09/13 18:52:15
Added a new file. Thanks!
|
+}; |
+ |
+// This test will load a text only page inside a child frame and then queries |
+// the string range which includes the first word. Then it uses the returned |
+// point to query the text again and verifies that correct result is returned. |
+// Finally, the returned words are compared against the first word in the html |
+// file which is "This". |
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, |
+ GetStringFromRangeAndPointChildFrame) { |
+ GURL main_url(embedded_test_server()->GetURL( |
+ "a.com", "/cross_site_iframe_factory.html?a(b)")); |
+ EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
+ FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
+ FrameTreeNode* child = root->child_at(0); |
+ NavigateFrameToURL(child, |
+ embedded_test_server()->GetURL("b.com", "/title1.html")); |
+ |
+ RenderWidgetHost* child_widget_host = |
+ child->current_frame_host()->GetRenderWidgetHost(); |
+ TextInputClientMacHelper helper; |
+ |
+ // Get string from range. |
+ helper.WaitForStringFromRange(child_widget_host, gfx::Range(0, 4)); |
+ gfx::Point point = helper.point(); |
+ std::string word = helper.word(); |
+ |
+ // Now get it at a given point. |
+ point.SetPoint(point.x(), |
+ child_widget_host->GetView()->GetViewBounds().size().height() - |
+ point.y()); |
+ helper.WaitForStringAtPoint(child_widget_host, point); |
+ EXPECT_EQ(word, helper.word()); |
+ EXPECT_EQ("This", word); |
+} |
+ |
+// This test will load a text only page and then queries the string range which |
+// includes the first word. Then it uses the returned point to query the text |
+// again and verifies that correct result is returned. Finally, the returned |
+// words are compared against the first word in the html file which is "This". |
+IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, |
+ GetStringFromRangeAndPointMainFrame) { |
+ GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
+ EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
+ FrameTreeNode* root = web_contents()->GetFrameTree()->root(); |
+ RenderWidgetHost* widget_host = |
+ root->current_frame_host()->GetRenderWidgetHost(); |
+ TextInputClientMacHelper helper; |
+ |
+ // Get string from range. |
+ helper.WaitForStringFromRange(widget_host, gfx::Range(0, 4)); |
+ gfx::Point point = helper.point(); |
+ std::string word = helper.word(); |
+ |
+ // Now get it at a given point. |
+ point.SetPoint( |
+ point.x(), |
+ widget_host->GetView()->GetViewBounds().size().height() - point.y()); |
+ helper.WaitForStringAtPoint(widget_host, point); |
+ EXPECT_EQ(word, helper.word()); |
+ EXPECT_EQ("This", word); |
+} |
+ |
+#endif // defined(OS_MACOSX) |
+ |
} // namespace content |