Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 7983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7994 // it's become pending deletion. | 7994 // it's become pending deletion. |
| 7995 child_rfh->OnDispatchLoad(); | 7995 child_rfh->OnDispatchLoad(); |
| 7996 | 7996 |
| 7997 // In the bug, OnDispatchLoad killed the b.com renderer. Ensure that this is | 7997 // In the bug, OnDispatchLoad killed the b.com renderer. Ensure that this is |
| 7998 // not the case. Note that the process kill doesn't happen immediately, so | 7998 // not the case. Note that the process kill doesn't happen immediately, so |
| 7999 // IsRenderFrameLive() can't be checked here (yet). Instead, check that | 7999 // IsRenderFrameLive() can't be checked here (yet). Instead, check that |
| 8000 // JavaScript can still execute in b.com using the popup. | 8000 // JavaScript can still execute in b.com using the popup. |
| 8001 EXPECT_TRUE(ExecuteScript(popup_shell->web_contents(), "true")); | 8001 EXPECT_TRUE(ExecuteScript(popup_shell->web_contents(), "true")); |
| 8002 } | 8002 } |
| 8003 | 8003 |
| 8004 #if defined(OS_MACOSX) | |
| 8005 class TextInputClientMacHelper { | |
| 8006 public: | |
| 8007 TextInputClientMacHelper() {} | |
| 8008 ~TextInputClientMacHelper() {} | |
| 8009 | |
| 8010 void WaitForStringFromRange(RenderWidgetHost* rwh, const gfx::Range& range) { | |
| 8011 GetStringFromRangeForRenderWidget( | |
| 8012 rwh, range, base::Bind(&TextInputClientMacHelper::OnResult, | |
| 8013 base::Unretained(this))); | |
| 8014 loop_runner_ = new MessageLoopRunner(); | |
| 8015 loop_runner_->Run(); | |
| 8016 } | |
| 8017 | |
| 8018 void WaitForStringAtPoint(RenderWidgetHost* rwh, const gfx::Point& point) { | |
| 8019 GetStringAtPointForRenderWidget( | |
| 8020 rwh, point, base::Bind(&TextInputClientMacHelper::OnResult, | |
| 8021 base::Unretained(this))); | |
| 8022 loop_runner_ = new MessageLoopRunner(); | |
| 8023 loop_runner_->Run(); | |
| 8024 } | |
| 8025 const std::string& word() const { return word_; } | |
| 8026 const gfx::Point& point() const { return point_; } | |
| 8027 | |
| 8028 private: | |
| 8029 void OnResult(const std::string& string, const gfx::Point& point) { | |
| 8030 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 8031 BrowserThread::PostTask( | |
| 8032 BrowserThread::UI, FROM_HERE, | |
| 8033 base::Bind(&TextInputClientMacHelper::OnResult, | |
| 8034 base::Unretained(this), string, point)); | |
| 8035 return; | |
| 8036 } | |
| 8037 word_ = string; | |
| 8038 point_ = point; | |
| 8039 | |
| 8040 if (loop_runner_ && loop_runner_->loop_running()) | |
| 8041 loop_runner_->Quit(); | |
| 8042 } | |
| 8043 | |
| 8044 std::string word_; | |
| 8045 gfx::Point point_; | |
| 8046 scoped_refptr<MessageLoopRunner> loop_runner_; | |
| 8047 | |
| 8048 DISALLOW_COPY_AND_ASSIGN(TextInputClientMacHelper); | |
| 8049 }; | |
| 8050 | |
| 8051 // Tests related to TextInputClientMac. | |
| 8052 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!
| |
| 8053 }; | |
| 8054 | |
| 8055 // This test will load a text only page inside a child frame and then queries | |
| 8056 // the string range which includes the first word. Then it uses the returned | |
| 8057 // point to query the text again and verifies that correct result is returned. | |
| 8058 // Finally, the returned words are compared against the first word in the html | |
| 8059 // file which is "This". | |
| 8060 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, | |
| 8061 GetStringFromRangeAndPointChildFrame) { | |
| 8062 GURL main_url(embedded_test_server()->GetURL( | |
| 8063 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 8064 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 8065 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
| 8066 FrameTreeNode* child = root->child_at(0); | |
| 8067 NavigateFrameToURL(child, | |
| 8068 embedded_test_server()->GetURL("b.com", "/title1.html")); | |
| 8069 | |
| 8070 RenderWidgetHost* child_widget_host = | |
| 8071 child->current_frame_host()->GetRenderWidgetHost(); | |
| 8072 TextInputClientMacHelper helper; | |
| 8073 | |
| 8074 // Get string from range. | |
| 8075 helper.WaitForStringFromRange(child_widget_host, gfx::Range(0, 4)); | |
| 8076 gfx::Point point = helper.point(); | |
| 8077 std::string word = helper.word(); | |
| 8078 | |
| 8079 // Now get it at a given point. | |
| 8080 point.SetPoint(point.x(), | |
| 8081 child_widget_host->GetView()->GetViewBounds().size().height() - | |
| 8082 point.y()); | |
| 8083 helper.WaitForStringAtPoint(child_widget_host, point); | |
| 8084 EXPECT_EQ(word, helper.word()); | |
| 8085 EXPECT_EQ("This", word); | |
| 8086 } | |
| 8087 | |
| 8088 // This test will load a text only page and then queries the string range which | |
| 8089 // includes the first word. Then it uses the returned point to query the text | |
| 8090 // again and verifies that correct result is returned. Finally, the returned | |
| 8091 // words are compared against the first word in the html file which is "This". | |
| 8092 IN_PROC_BROWSER_TEST_F(SitePerProcessTextInputClientMacTest, | |
| 8093 GetStringFromRangeAndPointMainFrame) { | |
| 8094 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
| 8095 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 8096 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
| 8097 RenderWidgetHost* widget_host = | |
| 8098 root->current_frame_host()->GetRenderWidgetHost(); | |
| 8099 TextInputClientMacHelper helper; | |
| 8100 | |
| 8101 // Get string from range. | |
| 8102 helper.WaitForStringFromRange(widget_host, gfx::Range(0, 4)); | |
| 8103 gfx::Point point = helper.point(); | |
| 8104 std::string word = helper.word(); | |
| 8105 | |
| 8106 // Now get it at a given point. | |
| 8107 point.SetPoint( | |
| 8108 point.x(), | |
| 8109 widget_host->GetView()->GetViewBounds().size().height() - point.y()); | |
| 8110 helper.WaitForStringAtPoint(widget_host, point); | |
| 8111 EXPECT_EQ(word, helper.word()); | |
| 8112 EXPECT_EQ("This", word); | |
| 8113 } | |
| 8114 | |
| 8115 #endif // defined(OS_MACOSX) | |
| 8116 | |
| 8004 } // namespace content | 8117 } // namespace content |
| OLD | NEW |