OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 aura::Env::DeleteInstance(); | 64 aura::Env::DeleteInstance(); |
65 screen_.reset(); | 65 screen_.reset(); |
66 #endif | 66 #endif |
67 } | 67 } |
68 | 68 |
69 virtual void ForwardGestureEvent( | 69 virtual void ForwardGestureEvent( |
70 const blink::WebGestureEvent& event) OVERRIDE { | 70 const blink::WebGestureEvent& event) OVERRIDE { |
71 forwarded_events_.push_back(event.type); | 71 forwarded_events_.push_back(event.type); |
72 } | 72 } |
73 | 73 |
74 virtual void ForwardTouchEvent( | 74 virtual void ForwardEmulatedTouchEvent( |
75 const blink::WebTouchEvent& event) OVERRIDE { | 75 const blink::WebTouchEvent& event) OVERRIDE { |
76 forwarded_events_.push_back(event.type); | 76 forwarded_events_.push_back(event.type); |
77 EXPECT_EQ(1U, event.touchesLength); | 77 EXPECT_EQ(1U, event.touchesLength); |
78 EXPECT_EQ(last_mouse_x_, event.touches[0].position.x); | 78 EXPECT_EQ(last_mouse_x_, event.touches[0].position.x); |
79 EXPECT_EQ(last_mouse_y_, event.touches[0].position.y); | 79 EXPECT_EQ(last_mouse_y_, event.touches[0].position.y); |
80 int expectedCancelable = event.type != WebInputEvent::TouchCancel; | 80 int expectedCancelable = event.type != WebInputEvent::TouchCancel; |
81 EXPECT_EQ(expectedCancelable, event.cancelable); | 81 EXPECT_EQ(expectedCancelable, event.cancelable); |
82 emulator()->HandleTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 82 emulator()->HandleTouchEventAck( |
| 83 event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
83 } | 84 } |
84 | 85 |
85 virtual void SetCursor(const WebCursor& cursor) OVERRIDE {} | 86 virtual void SetCursor(const WebCursor& cursor) OVERRIDE {} |
86 | 87 |
87 protected: | 88 protected: |
88 TouchEmulator* emulator() const { | 89 TouchEmulator* emulator() const { |
89 return emulator_.get(); | 90 return emulator_.get(); |
90 } | 91 } |
91 | 92 |
92 int modifiers() const { | 93 int modifiers() const { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 175 } |
175 | 176 |
176 void MouseUp(int x, int y) { | 177 void MouseUp(int x, int y) { |
177 DCHECK(mouse_pressed_); | 178 DCHECK(mouse_pressed_); |
178 if (x != last_mouse_x_ || y != last_mouse_y_) | 179 if (x != last_mouse_x_ || y != last_mouse_y_) |
179 SendMouseEvent(WebInputEvent::MouseMove, x, y); | 180 SendMouseEvent(WebInputEvent::MouseMove, x, y); |
180 SendMouseEvent(WebInputEvent::MouseUp, x, y); | 181 SendMouseEvent(WebInputEvent::MouseUp, x, y); |
181 mouse_pressed_ = false; | 182 mouse_pressed_ = false; |
182 } | 183 } |
183 | 184 |
| 185 bool TouchStart(int x, int y) { |
| 186 return SendTouchEvent( |
| 187 WebInputEvent::TouchStart, WebTouchPoint::StatePressed, x, y); |
| 188 } |
| 189 |
| 190 bool TouchMove(int x, int y) { |
| 191 return SendTouchEvent( |
| 192 WebInputEvent::TouchMove, WebTouchPoint::StateMoved, x, y); |
| 193 } |
| 194 |
| 195 bool TouchEnd(int x, int y) { |
| 196 return SendTouchEvent( |
| 197 WebInputEvent::TouchEnd, WebTouchPoint::StateReleased, x, y); |
| 198 } |
| 199 |
| 200 bool SendTouchEvent(WebInputEvent::Type type, WebTouchPoint::State state, |
| 201 int x, int y) { |
| 202 WebTouchEvent event; |
| 203 event.type = type; |
| 204 event.timeStampSeconds = GetNextEventTimeSeconds(); |
| 205 event.touchesLength = 1; |
| 206 event.touches[0].id = 0; |
| 207 event.touches[0].state = state; |
| 208 event.touches[0].position.x = x; |
| 209 event.touches[0].position.y = y; |
| 210 event.touches[0].screenPosition.x = x; |
| 211 event.touches[0].screenPosition.y = y; |
| 212 if (emulator()->HandleTouchEvent(event)) { |
| 213 // Touch event is not forwarded. |
| 214 return false; |
| 215 } else { |
| 216 // Touch event is forwarded, ack should not be handled by emulator. |
| 217 EXPECT_FALSE(emulator()->HandleTouchEventAck( |
| 218 event, INPUT_EVENT_ACK_STATE_CONSUMED)); |
| 219 return true; |
| 220 } |
| 221 } |
| 222 |
184 private: | 223 private: |
185 scoped_ptr<TouchEmulator> emulator_; | 224 scoped_ptr<TouchEmulator> emulator_; |
186 std::vector<WebInputEvent::Type> forwarded_events_; | 225 std::vector<WebInputEvent::Type> forwarded_events_; |
187 #if defined(USE_AURA) | 226 #if defined(USE_AURA) |
188 scoped_ptr<gfx::Screen> screen_; | 227 scoped_ptr<gfx::Screen> screen_; |
189 #endif | 228 #endif |
190 double last_event_time_seconds_; | 229 double last_event_time_seconds_; |
191 double event_time_delta_seconds_; | 230 double event_time_delta_seconds_; |
192 bool shift_pressed_; | 231 bool shift_pressed_; |
193 bool mouse_pressed_; | 232 bool mouse_pressed_; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 MouseDown(300, 200); | 378 MouseDown(300, 200); |
340 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); | 379 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
341 EXPECT_FALSE(SendMouseWheelEvent()); | 380 EXPECT_FALSE(SendMouseWheelEvent()); |
342 emulator()->Disable(); | 381 emulator()->Disable(); |
343 EXPECT_EQ("TouchCancel GestureTapCancel", ExpectedEvents()); | 382 EXPECT_EQ("TouchCancel GestureTapCancel", ExpectedEvents()); |
344 EXPECT_TRUE(SendMouseWheelEvent()); | 383 EXPECT_TRUE(SendMouseWheelEvent()); |
345 emulator()->Enable(true /* allow_pinch */); | 384 emulator()->Enable(true /* allow_pinch */); |
346 EXPECT_TRUE(SendMouseWheelEvent()); | 385 EXPECT_TRUE(SendMouseWheelEvent()); |
347 } | 386 } |
348 | 387 |
| 388 TEST_F(TouchEmulatorTest, MultipleTouchStreams) { |
| 389 // Native stream should be blocked while emulated is active. |
| 390 MouseMove(100, 200); |
| 391 EXPECT_EQ("", ExpectedEvents()); |
| 392 MouseDown(100, 200); |
| 393 EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); |
| 394 EXPECT_FALSE(TouchStart(10, 10)); |
| 395 EXPECT_FALSE(TouchMove(20, 20)); |
| 396 MouseUp(200, 200); |
| 397 EXPECT_EQ( |
| 398 "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" |
| 399 " TouchEnd GestureScrollEnd", |
| 400 ExpectedEvents()); |
| 401 EXPECT_FALSE(TouchEnd(20, 20)); |
| 402 |
| 403 // Emulated stream should be blocked while native is active. |
| 404 EXPECT_TRUE(TouchStart(10, 10)); |
| 405 EXPECT_TRUE(TouchMove(20, 20)); |
| 406 MouseDown(300, 200); |
| 407 EXPECT_EQ("", ExpectedEvents()); |
| 408 MouseDrag(300, 300); |
| 409 EXPECT_EQ("", ExpectedEvents()); |
| 410 MouseUp(300, 300); |
| 411 EXPECT_EQ("", ExpectedEvents()); |
| 412 EXPECT_TRUE(TouchEnd(20, 20)); |
| 413 EXPECT_EQ("", ExpectedEvents()); |
| 414 |
| 415 EXPECT_TRUE(TouchStart(10, 10)); |
| 416 EXPECT_TRUE(TouchMove(20, 20)); |
| 417 MouseDown(300, 200); |
| 418 EXPECT_EQ("", ExpectedEvents()); |
| 419 MouseDrag(300, 300); |
| 420 EXPECT_EQ("", ExpectedEvents()); |
| 421 EXPECT_TRUE(TouchEnd(20, 20)); |
| 422 MouseUp(300, 300); |
| 423 EXPECT_EQ("", ExpectedEvents()); |
| 424 } |
| 425 |
349 } // namespace content | 426 } // namespace content |
OLD | NEW |