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

Unified Diff: content/browser/renderer_host/input/touch_emulator_unittest.cc

Issue 375863005: Touch emulator: allow multiple touch streams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved to touch emulator Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/touch_emulator_unittest.cc
diff --git a/content/browser/renderer_host/input/touch_emulator_unittest.cc b/content/browser/renderer_host/input/touch_emulator_unittest.cc
index 8fdfd54cce29809b2c8b1d557c2134dab84139ea..ce5c61cc47dc7e4acb1e3874dd128710e7e8acfd 100644
--- a/content/browser/renderer_host/input/touch_emulator_unittest.cc
+++ b/content/browser/renderer_host/input/touch_emulator_unittest.cc
@@ -71,7 +71,7 @@ class TouchEmulatorTest : public testing::Test,
forwarded_events_.push_back(event.type);
}
- virtual void ForwardTouchEvent(
+ virtual void ForwardEmulatedTouchEvent(
const blink::WebTouchEvent& event) OVERRIDE {
forwarded_events_.push_back(event.type);
EXPECT_EQ(1U, event.touchesLength);
@@ -79,7 +79,8 @@ class TouchEmulatorTest : public testing::Test,
EXPECT_EQ(last_mouse_y_, event.touches[0].position.y);
int expectedCancelable = event.type != WebInputEvent::TouchCancel;
EXPECT_EQ(expectedCancelable, event.cancelable);
- emulator()->HandleTouchEventAck(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
+ emulator()->HandleTouchEventAck(
+ event, INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS);
}
virtual void SetCursor(const WebCursor& cursor) OVERRIDE {}
@@ -181,6 +182,44 @@ class TouchEmulatorTest : public testing::Test,
mouse_pressed_ = false;
}
+ bool TouchStart(int x, int y) {
+ return SendTouchEvent(
+ WebInputEvent::TouchStart, WebTouchPoint::StatePressed, x, y);
+ }
+
+ bool TouchMove(int x, int y) {
+ return SendTouchEvent(
+ WebInputEvent::TouchMove, WebTouchPoint::StateMoved, x, y);
+ }
+
+ bool TouchEnd(int x, int y) {
+ return SendTouchEvent(
+ WebInputEvent::TouchEnd, WebTouchPoint::StateReleased, x, y);
+ }
+
+ bool SendTouchEvent(WebInputEvent::Type type, WebTouchPoint::State state,
+ int x, int y) {
+ WebTouchEvent event;
+ event.type = type;
+ event.timeStampSeconds = GetNextEventTimeSeconds();
+ event.touchesLength = 1;
+ event.touches[0].id = 0;
+ event.touches[0].state = state;
+ event.touches[0].position.x = x;
+ event.touches[0].position.y = y;
+ event.touches[0].screenPosition.x = x;
+ event.touches[0].screenPosition.y = y;
+ if (emulator()->HandleTouchEvent(event)) {
+ // Touch event is not forwarded.
+ return false;
+ } else {
+ // Touch event is forwarded, ack should not be handled by emulator.
+ EXPECT_FALSE(emulator()->HandleTouchEventAck(
+ event, INPUT_EVENT_ACK_STATE_CONSUMED));
+ return true;
+ }
+ }
+
private:
scoped_ptr<TouchEmulator> emulator_;
std::vector<WebInputEvent::Type> forwarded_events_;
@@ -346,4 +385,42 @@ TEST_F(TouchEmulatorTest, MouseWheel) {
EXPECT_TRUE(SendMouseWheelEvent());
}
+TEST_F(TouchEmulatorTest, MultipleTouchStreams) {
+ // Native stream should be blocked while emulated is active.
+ MouseMove(100, 200);
+ EXPECT_EQ("", ExpectedEvents());
+ MouseDown(100, 200);
+ EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents());
+ EXPECT_FALSE(TouchStart(10, 10));
+ EXPECT_FALSE(TouchMove(20, 20));
+ MouseUp(200, 200);
+ EXPECT_EQ(
+ "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate"
+ " TouchEnd GestureScrollEnd",
+ ExpectedEvents());
+ EXPECT_FALSE(TouchEnd(20, 20));
+
+ // Emulated stream should be blocked while native is active.
+ EXPECT_TRUE(TouchStart(10, 10));
+ EXPECT_TRUE(TouchMove(20, 20));
+ MouseDown(300, 200);
+ EXPECT_EQ("", ExpectedEvents());
+ MouseDrag(300, 300);
+ EXPECT_EQ("", ExpectedEvents());
+ MouseUp(300, 300);
+ EXPECT_EQ("", ExpectedEvents());
+ EXPECT_TRUE(TouchEnd(20, 20));
+ EXPECT_EQ("", ExpectedEvents());
+
+ EXPECT_TRUE(TouchStart(10, 10));
+ EXPECT_TRUE(TouchMove(20, 20));
+ MouseDown(300, 200);
+ EXPECT_EQ("", ExpectedEvents());
+ MouseDrag(300, 300);
+ EXPECT_EQ("", ExpectedEvents());
+ EXPECT_TRUE(TouchEnd(20, 20));
+ MouseUp(300, 300);
+ EXPECT_EQ("", ExpectedEvents());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698