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 32e9079fd710589f56f2898cd536318dfb8af49e..7c144f7ca4ce97fc85dd96300efc7417c4e9f3d6 100644 |
--- a/content/browser/site_per_process_browsertest.cc |
+++ b/content/browser/site_per_process_browsertest.cc |
@@ -7922,4 +7922,117 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, SessionHistoryReplication) { |
EXPECT_EQ(child2_last_url, child2->current_url()); |
} |
+#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))); |
erikchen
2016/09/01 00:04:29
why don't you need to run the RunLoop here? If tha
EhsanK
2016/09/01 21:58:37
I should have used the loop. Fails without it sinc
|
+ } |
+ 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); |
+}; |
+ |
+void SetDocumentBodyHTML(FrameTreeNode* node, const std::string& html) { |
erikchen
2016/09/01 00:04:29
This should be in an anonymous namespace?
EhsanK
2016/09/01 21:58:37
Actually I do not need this method anymore. Sorry
|
+ EXPECT_TRUE(ExecuteScript( |
+ node, |
+ base::StringPrintf("document.body.innerHTML = '%s';", html.c_str()))); |
+} |
+ |
+// Tests related to TextInputClientMac. |
+class SitePerProcessTextInputClientMacTest : public SitePerProcessBrowserTest { |
+}; |
+ |
+// This test will load a text only page inside a child frame and then queries |
+// the |
Charlie Reis
2016/08/31 22:50:03
nit: Fix line wrap.
EhsanK
2016/09/01 21:58:37
Done. When I get a chance I will take a look at 'g
|
+// 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. |
+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, 5)); |
+ gfx::Point point = helper.point(); |
+ std::string word = helper.word(); |
erikchen
2016/09/01 00:04:29
can you add an expectation that verifies the conte
EhsanK
2016/09/01 21:58:37
Done. Thanks! (the word to be verified is "This").
|
+ |
+ // 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()); |
+} |
+ |
+// 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. |
+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, 5)); |
+ 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()); |
+} |
+ |
+#endif |
erikchen
2016/09/01 00:04:29
s/#endif/#endif // defined(OS_MACOSX)
EhsanK
2016/09/01 21:58:37
Done.
|
+ |
} // namespace content |