OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/browser/gpu/compositor_util.h" | 8 #include "content/browser/gpu/compositor_util.h" |
9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/common/input/synthetic_web_input_event_builders.h" | 11 #include "content/common/input/synthetic_web_input_event_builders.h" |
12 #include "content/common/input_messages.h" | 12 #include "content/common/input_messages.h" |
13 #include "content/public/browser/browser_message_filter.h" | 13 #include "content/public/browser/browser_message_filter.h" |
14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
15 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
18 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
19 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
20 #include "third_party/WebKit/public/web/WebInputEvent.h" | 20 #include "third_party/WebKit/public/web/WebInputEvent.h" |
21 #include "ui/events/event_switches.h" | 21 #include "ui/events/event_switches.h" |
22 #include "ui/events/latency_info.h" | 22 #include "ui/events/latency_info.h" |
23 | 23 |
24 #if defined(OS_ANDROID) | |
25 #include "content/browser/renderer_host/render_widget_host_view_android.h" | |
26 #endif | |
27 | |
24 using blink::WebInputEvent; | 28 using blink::WebInputEvent; |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
28 void GiveItSomeTime() { | 32 void GiveItSomeTime() { |
29 base::RunLoop run_loop; | 33 base::RunLoop run_loop; |
30 base::MessageLoop::current()->PostDelayedTask( | 34 base::MessageLoop::current()->PostDelayedTask( |
31 FROM_HERE, | 35 FROM_HERE, |
32 run_loop.QuitClosure(), | 36 run_loop.QuitClosure(), |
33 base::TimeDelta::FromMilliseconds(10)); | 37 base::TimeDelta::FromMilliseconds(10)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 146 |
143 protected: | 147 protected: |
144 void LoadURLAndAddFilter() { | 148 void LoadURLAndAddFilter() { |
145 const GURL data_url(kTouchEventDataURL); | 149 const GURL data_url(kTouchEventDataURL); |
146 NavigateToURL(shell(), data_url); | 150 NavigateToURL(shell(), data_url); |
147 | 151 |
148 WebContentsImpl* web_contents = | 152 WebContentsImpl* web_contents = |
149 static_cast<WebContentsImpl*>(shell()->web_contents()); | 153 static_cast<WebContentsImpl*>(shell()->web_contents()); |
150 RenderWidgetHostImpl* host = | 154 RenderWidgetHostImpl* host = |
151 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); | 155 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); |
156 #if defined(OS_ANDROID) | |
157 static_cast<RenderWidgetHostViewAndroid*>(host->GetView()) | |
158 ->GenerateNewFrameForTesting(); | |
no sievers
2015/02/09 23:11:20
Why do we need to do this, i.e. fake onSizeChanged
Jaekyun Seok (inactive)
2015/02/09 23:23:14
RenderWidgetHostImpl::OnUpdateRect() wasn't called
| |
159 #else | |
152 host->GetView()->SetSize(gfx::Size(400, 400)); | 160 host->GetView()->SetSize(gfx::Size(400, 400)); |
161 #endif | |
153 | 162 |
154 // The page is loaded in the renderer, wait for a new frame to arrive. | 163 // The page is loaded in the renderer, wait for a new frame to arrive. |
155 while (!host->ScheduleComposite()) | 164 while (!host->ScheduleComposite()) |
156 GiveItSomeTime(); | 165 GiveItSomeTime(); |
157 | 166 |
158 filter_ = new InputEventMessageFilter(); | 167 filter_ = new InputEventMessageFilter(); |
159 host->GetProcess()->AddFilter(filter_.get()); | 168 host->GetProcess()->AddFilter(filter_.get()); |
160 } | 169 } |
161 | 170 |
162 void SetUpCommandLine(base::CommandLine* cmd) override { | 171 void SetUpCommandLine(base::CommandLine* cmd) override { |
163 cmd->AppendSwitchASCII(switches::kTouchEvents, | 172 cmd->AppendSwitchASCII(switches::kTouchEvents, |
164 switches::kTouchEventsEnabled); | 173 switches::kTouchEventsEnabled); |
165 } | 174 } |
166 | 175 |
176 #if defined(OS_ANDROID) | |
177 float GetPageScaleFactor() { | |
178 WebContentsImpl* web_contents = | |
179 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
180 RenderWidgetHostImpl* host = | |
181 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); | |
182 return static_cast<RenderWidgetHostViewAndroid*>(host->GetView()) | |
183 ->last_page_scale_factor(); | |
184 } | |
185 #endif | |
186 | |
167 scoped_refptr<InputEventMessageFilter> filter_; | 187 scoped_refptr<InputEventMessageFilter> filter_; |
168 }; | 188 }; |
169 | 189 |
170 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
171 // TODO(ccameron): Failing on mac: crbug.com/346363 | 191 // TODO(ccameron): Failing on mac: crbug.com/346363 |
172 #define MAYBE_TouchNoHandler DISABLED_TouchNoHandler | 192 #define MAYBE_TouchNoHandler DISABLED_TouchNoHandler |
173 #else | 193 #else |
174 #define MAYBE_TouchNoHandler TouchNoHandler | 194 #define MAYBE_TouchNoHandler TouchNoHandler |
175 #endif | 195 #endif |
176 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_TouchNoHandler) { | 196 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_TouchNoHandler) { |
177 LoadURLAndAddFilter(); | 197 LoadURLAndAddFilter(); |
178 SyntheticWebTouchEvent touch; | 198 SyntheticWebTouchEvent touch; |
179 | 199 |
180 // A press on |first| should be acked with NO_CONSUMER_EXISTS since there is | 200 // A press on |first| should be acked with NO_CONSUMER_EXISTS since there is |
181 // no touch-handler on it. | 201 // no touch-handler on it. |
202 #if defined(OS_ANDROID) | |
203 float scale = GetPageScaleFactor(); | |
204 touch.PressPoint(25 * scale, 25 * scale); | |
205 #else | |
182 touch.PressPoint(25, 25); | 206 touch.PressPoint(25, 25); |
207 #endif | |
183 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 208 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
184 filter()->WaitForAck(WebInputEvent::TouchStart); | 209 filter()->WaitForAck(WebInputEvent::TouchStart); |
185 | 210 |
186 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, | 211 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
187 filter()->last_ack_state()); | 212 filter()->last_ack_state()); |
188 | 213 |
189 // If a touch-press is acked with NO_CONSUMER_EXISTS, then subsequent | 214 // If a touch-press is acked with NO_CONSUMER_EXISTS, then subsequent |
190 // touch-points don't need to be dispatched until the touch point is released. | 215 // touch-points don't need to be dispatched until the touch point is released. |
191 touch.ReleasePoint(0); | 216 touch.ReleasePoint(0); |
192 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 217 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
193 touch.ResetPoints(); | 218 touch.ResetPoints(); |
194 } | 219 } |
195 | 220 |
196 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerNoConsume) { | 221 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerNoConsume) { |
197 LoadURLAndAddFilter(); | 222 LoadURLAndAddFilter(); |
198 SyntheticWebTouchEvent touch; | 223 SyntheticWebTouchEvent touch; |
199 | 224 |
200 // Press on |second| should be acked with NOT_CONSUMED since there is a | 225 // Press on |second| should be acked with NOT_CONSUMED since there is a |
201 // touch-handler on |second|, but it doesn't consume the event. | 226 // touch-handler on |second|, but it doesn't consume the event. |
227 #if defined(OS_ANDROID) | |
228 float scale = GetPageScaleFactor(); | |
229 touch.PressPoint(125 * scale, 25 * scale); | |
230 #else | |
202 touch.PressPoint(125, 25); | 231 touch.PressPoint(125, 25); |
232 #endif | |
203 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 233 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
204 filter()->WaitForAck(WebInputEvent::TouchStart); | 234 filter()->WaitForAck(WebInputEvent::TouchStart); |
205 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state()); | 235 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state()); |
206 | 236 |
207 touch.ReleasePoint(0); | 237 touch.ReleasePoint(0); |
208 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 238 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
209 filter()->WaitForAck(WebInputEvent::TouchEnd); | 239 filter()->WaitForAck(WebInputEvent::TouchEnd); |
210 touch.ResetPoints(); | 240 touch.ResetPoints(); |
211 } | 241 } |
212 | 242 |
213 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerConsume) { | 243 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerConsume) { |
214 LoadURLAndAddFilter(); | 244 LoadURLAndAddFilter(); |
215 SyntheticWebTouchEvent touch; | 245 SyntheticWebTouchEvent touch; |
216 | 246 |
217 // Press on |third| should be acked with CONSUMED since the touch-handler on | 247 // Press on |third| should be acked with CONSUMED since the touch-handler on |
218 // |third| consimes the event. | 248 // |third| consimes the event. |
249 #if defined(OS_ANDROID) | |
250 float scale = GetPageScaleFactor(); | |
251 touch.PressPoint(25 * scale, 125 * scale); | |
252 #else | |
219 touch.PressPoint(25, 125); | 253 touch.PressPoint(25, 125); |
254 #endif | |
220 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 255 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
221 filter()->WaitForAck(WebInputEvent::TouchStart); | 256 filter()->WaitForAck(WebInputEvent::TouchStart); |
222 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); | 257 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); |
223 | 258 |
224 touch.ReleasePoint(0); | 259 touch.ReleasePoint(0); |
225 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 260 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
226 filter()->WaitForAck(WebInputEvent::TouchEnd); | 261 filter()->WaitForAck(WebInputEvent::TouchEnd); |
227 } | 262 } |
228 | 263 |
229 #if defined(OS_MACOSX) | 264 #if defined(OS_MACOSX) |
230 // TODO(ccameron): Failing on mac: crbug.com/346363 | 265 // TODO(ccameron): Failing on mac: crbug.com/346363 |
231 #define MAYBE_MultiPointTouchPress DISABLED_MultiPointTouchPress | 266 #define MAYBE_MultiPointTouchPress DISABLED_MultiPointTouchPress |
232 #else | 267 #else |
233 #define MAYBE_MultiPointTouchPress MultiPointTouchPress | 268 #define MAYBE_MultiPointTouchPress MultiPointTouchPress |
234 #endif | 269 #endif |
235 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_MultiPointTouchPress) { | 270 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_MultiPointTouchPress) { |
236 LoadURLAndAddFilter(); | 271 LoadURLAndAddFilter(); |
237 SyntheticWebTouchEvent touch; | 272 SyntheticWebTouchEvent touch; |
238 | 273 |
239 // Press on |first|, which sould be acked with NO_CONSUMER_EXISTS. Then press | 274 // Press on |first|, which sould be acked with NO_CONSUMER_EXISTS. Then press |
240 // on |third|. That point should be acked with CONSUMED. | 275 // on |third|. That point should be acked with CONSUMED. |
276 #if defined(OS_ANDROID) | |
277 float scale = GetPageScaleFactor(); | |
278 touch.PressPoint(25 * scale, 25 * scale); | |
279 #else | |
241 touch.PressPoint(25, 25); | 280 touch.PressPoint(25, 25); |
281 #endif | |
242 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 282 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
243 filter()->WaitForAck(WebInputEvent::TouchStart); | 283 filter()->WaitForAck(WebInputEvent::TouchStart); |
244 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, | 284 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, |
245 filter()->last_ack_state()); | 285 filter()->last_ack_state()); |
246 | 286 |
287 #if defined(OS_ANDROID) | |
288 touch.PressPoint(25 * scale, 125 * scale); | |
289 #else | |
247 touch.PressPoint(25, 125); | 290 touch.PressPoint(25, 125); |
291 #endif | |
248 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | 292 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); |
249 filter()->WaitForAck(WebInputEvent::TouchStart); | 293 filter()->WaitForAck(WebInputEvent::TouchStart); |
250 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); | 294 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); |
251 } | 295 } |
252 | 296 |
253 } // namespace content | 297 } // namespace content |
OLD | NEW |