Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: content/browser/renderer_host/input/touch_input_browsertest.cc

Issue 888793002: Make content_browsertests for Chrome on Android running with valid Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set valid physical backing size before viewport size is set Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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));
34 run_loop.Run(); 38 run_loop.Run();
35 } 39 }
36 40
37 const char kTouchEventDataURL[] = 41 const char kTouchEventDataURL[] =
38 "data:text/html;charset=utf-8," 42 "data:text/html;charset=utf-8,"
39 "<body onload='setup();'>" 43 "<body onload='setup();'>"
jdduke (slow) 2015/02/18 22:07:03 Can you just give this a mobile viewport? <head>
Jaekyun Seok (inactive) 2015/02/23 10:41:34 I confirmed that your suggestion worked well. I wi
40 "<div id='first'></div><div id='second'></div><div id='third'></div>" 44 "<div id='first'></div><div id='second'></div><div id='third'></div>"
41 "<style>" 45 "<style>"
42 " #first {" 46 " #first {"
43 " position: absolute;" 47 " position: absolute;"
44 " width: 100px;" 48 " width: 100px;"
45 " height: 100px;" 49 " height: 100px;"
46 " top: 0px;" 50 " top: 0px;"
47 " left: 0px;" 51 " left: 0px;"
48 " background-color: green;" 52 " background-color: green;"
49 " -webkit-transform: translate3d(0, 0, 0);" 53 " -webkit-transform: translate3d(0, 0, 0);"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 161
158 filter_ = new InputEventMessageFilter(); 162 filter_ = new InputEventMessageFilter();
159 host->GetProcess()->AddFilter(filter_.get()); 163 host->GetProcess()->AddFilter(filter_.get());
160 } 164 }
161 165
162 void SetUpCommandLine(base::CommandLine* cmd) override { 166 void SetUpCommandLine(base::CommandLine* cmd) override {
163 cmd->AppendSwitchASCII(switches::kTouchEvents, 167 cmd->AppendSwitchASCII(switches::kTouchEvents,
164 switches::kTouchEventsEnabled); 168 switches::kTouchEventsEnabled);
165 } 169 }
166 170
171 #if defined(OS_ANDROID)
172 float GetPageScaleFactor() {
173 WebContentsImpl* web_contents =
174 static_cast<WebContentsImpl*>(shell()->web_contents());
175 RenderWidgetHostImpl* host =
176 RenderWidgetHostImpl::From(web_contents->GetRenderViewHost());
177 return static_cast<RenderWidgetHostViewAndroid*>(host->GetView())
178 ->last_page_scale_factor();
179 }
180 #endif
181
167 scoped_refptr<InputEventMessageFilter> filter_; 182 scoped_refptr<InputEventMessageFilter> filter_;
168 }; 183 };
169 184
170 #if defined(OS_MACOSX) 185 #if defined(OS_MACOSX)
171 // TODO(ccameron): Failing on mac: crbug.com/346363 186 // TODO(ccameron): Failing on mac: crbug.com/346363
172 #define MAYBE_TouchNoHandler DISABLED_TouchNoHandler 187 #define MAYBE_TouchNoHandler DISABLED_TouchNoHandler
173 #else 188 #else
174 #define MAYBE_TouchNoHandler TouchNoHandler 189 #define MAYBE_TouchNoHandler TouchNoHandler
175 #endif 190 #endif
176 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_TouchNoHandler) { 191 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_TouchNoHandler) {
177 LoadURLAndAddFilter(); 192 LoadURLAndAddFilter();
178 SyntheticWebTouchEvent touch; 193 SyntheticWebTouchEvent touch;
179 194
180 // A press on |first| should be acked with NO_CONSUMER_EXISTS since there is 195 // A press on |first| should be acked with NO_CONSUMER_EXISTS since there is
181 // no touch-handler on it. 196 // no touch-handler on it.
197 #if defined(OS_ANDROID)
198 float scale = GetPageScaleFactor();
199 touch.PressPoint(25 * scale, 25 * scale);
200 #else
182 touch.PressPoint(25, 25); 201 touch.PressPoint(25, 25);
202 #endif
183 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 203 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
184 filter()->WaitForAck(WebInputEvent::TouchStart); 204 filter()->WaitForAck(WebInputEvent::TouchStart);
185 205
186 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, 206 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS,
187 filter()->last_ack_state()); 207 filter()->last_ack_state());
188 208
189 // If a touch-press is acked with NO_CONSUMER_EXISTS, then subsequent 209 // 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. 210 // touch-points don't need to be dispatched until the touch point is released.
191 touch.ReleasePoint(0); 211 touch.ReleasePoint(0);
192 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 212 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
193 touch.ResetPoints(); 213 touch.ResetPoints();
194 } 214 }
195 215
196 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerNoConsume) { 216 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerNoConsume) {
197 LoadURLAndAddFilter(); 217 LoadURLAndAddFilter();
198 SyntheticWebTouchEvent touch; 218 SyntheticWebTouchEvent touch;
199 219
200 // Press on |second| should be acked with NOT_CONSUMED since there is a 220 // 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. 221 // touch-handler on |second|, but it doesn't consume the event.
222 #if defined(OS_ANDROID)
223 float scale = GetPageScaleFactor();
224 touch.PressPoint(125 * scale, 25 * scale);
225 #else
202 touch.PressPoint(125, 25); 226 touch.PressPoint(125, 25);
227 #endif
203 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 228 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
204 filter()->WaitForAck(WebInputEvent::TouchStart); 229 filter()->WaitForAck(WebInputEvent::TouchStart);
205 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state()); 230 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter()->last_ack_state());
206 231
207 touch.ReleasePoint(0); 232 touch.ReleasePoint(0);
208 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 233 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
209 filter()->WaitForAck(WebInputEvent::TouchEnd); 234 filter()->WaitForAck(WebInputEvent::TouchEnd);
210 touch.ResetPoints(); 235 touch.ResetPoints();
211 } 236 }
212 237
213 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerConsume) { 238 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, TouchHandlerConsume) {
214 LoadURLAndAddFilter(); 239 LoadURLAndAddFilter();
215 SyntheticWebTouchEvent touch; 240 SyntheticWebTouchEvent touch;
216 241
217 // Press on |third| should be acked with CONSUMED since the touch-handler on 242 // Press on |third| should be acked with CONSUMED since the touch-handler on
218 // |third| consimes the event. 243 // |third| consimes the event.
244 #if defined(OS_ANDROID)
245 float scale = GetPageScaleFactor();
246 touch.PressPoint(25 * scale, 125 * scale);
247 #else
219 touch.PressPoint(25, 125); 248 touch.PressPoint(25, 125);
249 #endif
220 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 250 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
221 filter()->WaitForAck(WebInputEvent::TouchStart); 251 filter()->WaitForAck(WebInputEvent::TouchStart);
222 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); 252 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state());
223 253
224 touch.ReleasePoint(0); 254 touch.ReleasePoint(0);
225 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 255 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
226 filter()->WaitForAck(WebInputEvent::TouchEnd); 256 filter()->WaitForAck(WebInputEvent::TouchEnd);
227 } 257 }
228 258
229 #if defined(OS_MACOSX) 259 #if defined(OS_MACOSX)
230 // TODO(ccameron): Failing on mac: crbug.com/346363 260 // TODO(ccameron): Failing on mac: crbug.com/346363
231 #define MAYBE_MultiPointTouchPress DISABLED_MultiPointTouchPress 261 #define MAYBE_MultiPointTouchPress DISABLED_MultiPointTouchPress
232 #else 262 #else
233 #define MAYBE_MultiPointTouchPress MultiPointTouchPress 263 #define MAYBE_MultiPointTouchPress MultiPointTouchPress
234 #endif 264 #endif
235 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_MultiPointTouchPress) { 265 IN_PROC_BROWSER_TEST_F(TouchInputBrowserTest, MAYBE_MultiPointTouchPress) {
236 LoadURLAndAddFilter(); 266 LoadURLAndAddFilter();
237 SyntheticWebTouchEvent touch; 267 SyntheticWebTouchEvent touch;
238 268
239 // Press on |first|, which sould be acked with NO_CONSUMER_EXISTS. Then press 269 // Press on |first|, which sould be acked with NO_CONSUMER_EXISTS. Then press
240 // on |third|. That point should be acked with CONSUMED. 270 // on |third|. That point should be acked with CONSUMED.
271 #if defined(OS_ANDROID)
272 float scale = GetPageScaleFactor();
273 touch.PressPoint(25 * scale, 25 * scale);
274 #else
241 touch.PressPoint(25, 25); 275 touch.PressPoint(25, 25);
276 #endif
242 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 277 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
243 filter()->WaitForAck(WebInputEvent::TouchStart); 278 filter()->WaitForAck(WebInputEvent::TouchStart);
244 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, 279 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS,
245 filter()->last_ack_state()); 280 filter()->last_ack_state());
246 281
282 #if defined(OS_ANDROID)
283 touch.PressPoint(25 * scale, 125 * scale);
284 #else
247 touch.PressPoint(25, 125); 285 touch.PressPoint(25, 125);
286 #endif
248 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); 287 GetWidgetHost()->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo());
249 filter()->WaitForAck(WebInputEvent::TouchStart); 288 filter()->WaitForAck(WebInputEvent::TouchStart);
250 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state()); 289 EXPECT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter()->last_ack_state());
251 } 290 }
252 291
253 } // namespace content 292 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698