OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/site_per_process_browsertest.h" | |
6 | |
7 #include "content/public/test/content_browser_test_utils.h" | |
8 #include "content/public/test/test_utils.h" | |
9 | |
10 namespace content { | |
11 | |
12 namespace { | |
13 | |
14 // Helper class for TextInputClientMac. | |
15 class TextInputClientMacHelper { | |
16 public: | |
17 TextInputClientMacHelper() {} | |
18 ~TextInputClientMacHelper() {} | |
19 | |
20 void WaitForStringFromRange(RenderWidgetHost* rwh, const gfx::Range& range) { | |
21 GetStringFromRangeForRenderWidget( | |
22 rwh, range, base::Bind(&TextInputClientMacHelper::OnResult, | |
23 base::Unretained(this))); | |
24 loop_runner_ = new MessageLoopRunner(); | |
25 loop_runner_->Run(); | |
26 } | |
27 | |
28 void WaitForStringAtPoint(RenderWidgetHost* rwh, const gfx::Point& point) { | |
29 GetStringAtPointForRenderWidget( | |
30 rwh, point, base::Bind(&TextInputClientMacHelper::OnResult, | |
31 base::Unretained(this))); | |
32 loop_runner_ = new MessageLoopRunner(); | |
33 loop_runner_->Run(); | |
34 } | |
35 const std::string& word() const { return word_; } | |
36 const gfx::Point& point() const { return point_; } | |
37 | |
38 private: | |
39 void OnResult(const std::string& string, const gfx::Point& point) { | |
40 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
41 BrowserThread::PostTask( | |
42 BrowserThread::UI, FROM_HERE, | |
43 base::Bind(&TextInputClientMacHelper::OnResult, | |
44 base::Unretained(this), string, point)); | |
45 return; | |
46 } | |
47 word_ = string; | |
48 point_ = point; | |
49 | |
50 if (loop_runner_ && loop_runner_->loop_running()) | |
51 loop_runner_->Quit(); | |
52 } | |
53 | |
54 std::string word_; | |
55 gfx::Point point_; | |
56 scoped_refptr<MessageLoopRunner> loop_runner_; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(TextInputClientMacHelper); | |
59 }; | |
60 | |
61 } // namespace | |
62 | |
63 // Site per process browser tests inside content which are specific to Mac OSX | |
64 // platform. | |
65 class SitePerProcessMacBrowserTest : public SitePerProcessBrowserTest {}; | |
Charlie Reis
2016/09/23 06:24:10
I'm probably just missing something from here or t
EhsanK
2016/09/23 14:36:49
I would, maybe say the .mm extension does the job?
| |
66 | |
67 // This test will load a text only page inside a child frame and then queries | |
68 // the string range which includes the first word. Then it uses the returned | |
69 // point to query the text again and verifies that correct result is returned. | |
70 // Finally, the returned words are compared against the first word in the html | |
71 // file which is "This". | |
72 IN_PROC_BROWSER_TEST_F(SitePerProcessMacBrowserTest, | |
73 GetStringFromRangeAndPointChildFrame) { | |
74 GURL main_url(embedded_test_server()->GetURL( | |
75 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
76 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
77 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
78 FrameTreeNode* child = root->child_at(0); | |
79 NavigateFrameToURL(child, | |
80 embedded_test_server()->GetURL("b.com", "/title1.html")); | |
81 | |
82 RenderWidgetHost* child_widget_host = | |
83 child->current_frame_host()->GetRenderWidgetHost(); | |
84 TextInputClientMacHelper helper; | |
85 | |
86 // Get string from range. | |
87 helper.WaitForStringFromRange(child_widget_host, gfx::Range(0, 4)); | |
88 gfx::Point point = helper.point(); | |
89 std::string word = helper.word(); | |
90 | |
91 // Now get it at a given point. | |
92 point.SetPoint(point.x(), | |
93 child_widget_host->GetView()->GetViewBounds().size().height() - | |
94 point.y()); | |
95 helper.WaitForStringAtPoint(child_widget_host, point); | |
96 EXPECT_EQ(word, helper.word()); | |
97 EXPECT_EQ("This", word); | |
98 } | |
99 | |
100 // This test will load a text only page and then queries the string range which | |
101 // includes the first word. Then it uses the returned point to query the text | |
102 // again and verifies that correct result is returned. Finally, the returned | |
103 // words are compared against the first word in the html file which is "This". | |
104 IN_PROC_BROWSER_TEST_F(SitePerProcessMacBrowserTest, | |
105 GetStringFromRangeAndPointMainFrame) { | |
106 GURL main_url(embedded_test_server()->GetURL("a.com", "/title1.html")); | |
107 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
108 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); | |
109 RenderWidgetHost* widget_host = | |
110 root->current_frame_host()->GetRenderWidgetHost(); | |
111 TextInputClientMacHelper helper; | |
112 | |
113 // Get string from range. | |
114 helper.WaitForStringFromRange(widget_host, gfx::Range(0, 4)); | |
115 gfx::Point point = helper.point(); | |
116 std::string word = helper.word(); | |
117 | |
118 // Now get it at a given point. | |
119 point.SetPoint( | |
120 point.x(), | |
121 widget_host->GetView()->GetViewBounds().size().height() - point.y()); | |
122 helper.WaitForStringAtPoint(widget_host, point); | |
123 EXPECT_EQ(word, helper.word()); | |
124 EXPECT_EQ("This", word); | |
125 } | |
126 } // namespace content | |
OLD | NEW |