| 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 "content/common/input/touch_event_stream_validator.h" | 5 #include "content/common/input/touch_event_stream_validator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "content/common/input/synthetic_web_input_event_builders.h" | 9 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 10 #include "content/common/input/web_touch_event_traits.h" | 10 #include "content/common/input/web_touch_event_traits.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 TouchEventStreamValidator validator; | 115 TouchEventStreamValidator validator; |
| 116 WebTouchEvent event; | 116 WebTouchEvent event; |
| 117 std::string error_msg; | 117 std::string error_msg; |
| 118 | 118 |
| 119 EXPECT_FALSE(validator.Validate(event, &error_msg)); | 119 EXPECT_FALSE(validator.Validate(event, &error_msg)); |
| 120 EXPECT_FALSE(error_msg.empty()); | 120 EXPECT_FALSE(error_msg.empty()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST(TouchEventStreamValidator, InvalidEventType) { | 123 TEST(TouchEventStreamValidator, InvalidEventType) { |
| 124 TouchEventStreamValidator validator; | 124 TouchEventStreamValidator validator; |
| 125 WebTouchEvent event; | 125 WebTouchEvent event(WebInputEvent::GestureScrollBegin, |
| 126 WebInputEvent::NoModifiers, |
| 127 WebInputEvent::TimeStampForTesting); |
| 126 std::string error_msg; | 128 std::string error_msg; |
| 127 | 129 |
| 128 event.type = WebInputEvent::GestureScrollBegin; | |
| 129 event.touchesLength = 1; | 130 event.touchesLength = 1; |
| 130 event.touches[0].state = WebTouchPoint::StatePressed; | 131 event.touches[0].state = WebTouchPoint::StatePressed; |
| 131 | 132 |
| 132 EXPECT_FALSE(validator.Validate(event, &error_msg)); | 133 EXPECT_FALSE(validator.Validate(event, &error_msg)); |
| 133 EXPECT_FALSE(error_msg.empty()); | 134 EXPECT_FALSE(error_msg.empty()); |
| 134 } | 135 } |
| 135 | 136 |
| 136 TEST(TouchEventStreamValidator, InvalidPointStates) { | 137 TEST(TouchEventStreamValidator, InvalidPointStates) { |
| 137 TouchEventStreamValidator validator; | 138 TouchEventStreamValidator validator; |
| 138 std::string error_msg; | 139 std::string error_msg; |
| 139 | 140 |
| 140 WebInputEvent::Type kTouchTypes[4] = { | 141 WebInputEvent::Type kTouchTypes[4] = { |
| 141 WebInputEvent::TouchStart, WebInputEvent::TouchMove, | 142 WebInputEvent::TouchStart, WebInputEvent::TouchMove, |
| 142 WebInputEvent::TouchEnd, WebInputEvent::TouchCancel, | 143 WebInputEvent::TouchEnd, WebInputEvent::TouchCancel, |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 WebTouchPoint::State kValidTouchPointStatesForType[4] = { | 146 WebTouchPoint::State kValidTouchPointStatesForType[4] = { |
| 146 WebTouchPoint::StatePressed, WebTouchPoint::StateMoved, | 147 WebTouchPoint::StatePressed, WebTouchPoint::StateMoved, |
| 147 WebTouchPoint::StateReleased, WebTouchPoint::StateCancelled, | 148 WebTouchPoint::StateReleased, WebTouchPoint::StateCancelled, |
| 148 }; | 149 }; |
| 149 | 150 |
| 150 SyntheticWebTouchEvent start; | 151 SyntheticWebTouchEvent start; |
| 151 start.PressPoint(0, 0); | 152 start.PressPoint(0, 0); |
| 152 for (size_t i = 0; i < 4; ++i) { | 153 for (size_t i = 0; i < 4; ++i) { |
| 153 // Always start with a touchstart to reset the stream validation. | 154 // Always start with a touchstart to reset the stream validation. |
| 154 EXPECT_TRUE(validator.Validate(start, &error_msg)); | 155 EXPECT_TRUE(validator.Validate(start, &error_msg)); |
| 155 EXPECT_TRUE(error_msg.empty()); | 156 EXPECT_TRUE(error_msg.empty()); |
| 156 | 157 |
| 157 WebTouchEvent event; | 158 WebTouchEvent event(kTouchTypes[i], WebInputEvent::NoModifiers, |
| 159 WebInputEvent::TimeStampForTesting); |
| 158 event.touchesLength = 1; | 160 event.touchesLength = 1; |
| 159 event.type = kTouchTypes[i]; | |
| 160 for (size_t j = WebTouchPoint::StateUndefined; | 161 for (size_t j = WebTouchPoint::StateUndefined; |
| 161 j <= WebTouchPoint::StateCancelled; | 162 j <= WebTouchPoint::StateCancelled; |
| 162 ++j) { | 163 ++j) { |
| 163 event.touches[0].state = static_cast<WebTouchPoint::State>(j); | 164 event.touches[0].state = static_cast<WebTouchPoint::State>(j); |
| 164 if (event.touches[0].state == kValidTouchPointStatesForType[i]) { | 165 if (event.touches[0].state == kValidTouchPointStatesForType[i]) { |
| 165 EXPECT_TRUE(validator.Validate(event, &error_msg)); | 166 EXPECT_TRUE(validator.Validate(event, &error_msg)); |
| 166 EXPECT_TRUE(error_msg.empty()); | 167 EXPECT_TRUE(error_msg.empty()); |
| 167 } else { | 168 } else { |
| 168 EXPECT_FALSE(validator.Validate(event, &error_msg)); | 169 EXPECT_FALSE(validator.Validate(event, &error_msg)); |
| 169 EXPECT_FALSE(error_msg.empty()); | 170 EXPECT_FALSE(error_msg.empty()); |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace content | 176 } // namespace content |
| OLD | NEW |