Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/renderer_host/input/gesture_text_selector.h" | 10 #include "content/browser/renderer_host/input/gesture_text_selector.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | 176 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE |
| 177 | 177 |
| 178 // 7. ET_GESTURE_SCROLL_END | 178 // 7. ET_GESTURE_SCROLL_END |
| 179 event_time += base::TimeDelta::FromMilliseconds(10); | 179 event_time += base::TimeDelta::FromMilliseconds(10); |
| 180 const GestureEventData scroll_end = | 180 const GestureEventData scroll_end = |
| 181 CreateGesture(ui::ET_GESTURE_SCROLL_END, event_time, x2, y2); | 181 CreateGesture(ui::ET_GESTURE_SCROLL_END, event_time, x2, y2); |
| 182 EXPECT_TRUE(selector_->OnGestureEvent(scroll_end)); | 182 EXPECT_TRUE(selector_->OnGestureEvent(scroll_end)); |
| 183 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | 183 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(GestureTextSelectorTest, PenDraggingButtonNotPressed) { | |
| 187 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 188 const float x1 = 50.0f; | |
| 189 const float y1 = 30.0f; | |
| 190 const float x2 = 75.0f; | |
| 191 const float y2 = 60.0f; | |
| 192 const float x3 = 100.0f; | |
| 193 const float y3 = 90.0f; | |
| 194 // 1. ACTION_DOWN with stylus + button | |
| 195 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 196 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); | |
| 197 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
| 198 action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); | |
| 199 EXPECT_TRUE(selector_->OnTouchEvent(action_down)); | |
| 200 EXPECT_TRUE(event_log_.empty()); | |
| 201 | |
| 202 // 2. ACTION_MOVE | |
| 203 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 204 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); | |
| 205 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
| 206 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | |
| 207 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | |
| 208 EXPECT_TRUE(event_log_.empty()); | |
| 209 | |
| 210 // 3. ET_GESTURE_SCROLL_BEGIN | |
| 211 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 212 const GestureEventData scroll_begin = | |
| 213 CreateGesture(ui::ET_GESTURE_SCROLL_BEGIN, event_time, x1, y1); | |
| 214 EXPECT_TRUE(selector_->OnGestureEvent(scroll_begin)); | |
| 215 EXPECT_EQ(1u, event_log_.size()); // Unselect | |
| 216 | |
| 217 // 4. ET_GESTURE_SCROLL_UPDATE | |
| 218 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 219 const GestureEventData scroll_update = | |
| 220 CreateGesture(ui::ET_GESTURE_SCROLL_UPDATE, event_time, x2, y2); | |
| 221 EXPECT_TRUE(selector_->OnGestureEvent(scroll_update)); | |
| 222 EXPECT_EQ(3u, event_log_.size()); // Unselect, Show, SelectRange | |
| 223 EXPECT_STREQ("SelectRange", event_log_.back().c_str()); | |
| 224 | |
| 225 // 5. ACTION_MOVE with stylus + no button | |
| 226 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 227 action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x3, y3); | |
| 228 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
| 229 action_move.set_button_state(0); | |
| 230 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | |
| 231 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | |
| 232 | |
| 233 // 7. ET_GESTURE_SCROLL_UPDATE without button | |
| 234 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 235 const GestureEventData second_scroll_update = | |
| 236 CreateGesture(ui::ET_GESTURE_SCROLL_UPDATE, event_time, x3, y3); | |
| 237 EXPECT_TRUE(selector_->OnGestureEvent(scroll_update)); | |
| 238 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | |
|
jdduke (slow)
2014/09/23 15:10:48
What if they press the button again?
| |
| 239 | |
| 240 // 8. ACTION_UP | |
| 241 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 242 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x3, y3); | |
| 243 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
| 244 action_up.set_button_state(0); | |
| 245 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | |
| 246 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | |
| 247 | |
| 248 // 9. ET_GESTURE_SCROLL_END | |
| 249 event_time += base::TimeDelta::FromMilliseconds(10); | |
| 250 const GestureEventData scroll_end = | |
| 251 CreateGesture(ui::ET_GESTURE_SCROLL_END, event_time, x3, y3); | |
| 252 EXPECT_TRUE(selector_->OnGestureEvent(scroll_end)); | |
| 253 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | |
| 254 } | |
| 255 | |
| 186 TEST_F(GestureTextSelectorTest, TapToSelectWord) { | 256 TEST_F(GestureTextSelectorTest, TapToSelectWord) { |
| 187 base::TimeTicks event_time = base::TimeTicks::Now(); | 257 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 188 const float x1 = 50.0f; | 258 const float x1 = 50.0f; |
| 189 const float y1 = 30.0f; | 259 const float y1 = 30.0f; |
| 190 const float x2 = 51.0f; | 260 const float x2 = 51.0f; |
| 191 const float y2 = 31.0f; | 261 const float y2 = 31.0f; |
| 192 // 1. ACTION_DOWN with stylus + button | 262 // 1. ACTION_DOWN with stylus + button |
| 193 event_time += base::TimeDelta::FromMilliseconds(10); | 263 event_time += base::TimeDelta::FromMilliseconds(10); |
| 194 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); | 264 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); |
| 195 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 265 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 223 // 4. TAP | 293 // 4. TAP |
| 224 event_time += base::TimeDelta::FromMilliseconds(10); | 294 event_time += base::TimeDelta::FromMilliseconds(10); |
| 225 const GestureEventData tap = | 295 const GestureEventData tap = |
| 226 CreateGesture(ui::ET_GESTURE_TAP, event_time, x1, y1); | 296 CreateGesture(ui::ET_GESTURE_TAP, event_time, x1, y1); |
| 227 EXPECT_TRUE(selector_->OnGestureEvent(tap)); | 297 EXPECT_TRUE(selector_->OnGestureEvent(tap)); |
| 228 EXPECT_EQ(1u, event_log_.size()); // LongPress | 298 EXPECT_EQ(1u, event_log_.size()); // LongPress |
| 229 EXPECT_STREQ("LongPress", event_log_.back().c_str()); | 299 EXPECT_STREQ("LongPress", event_log_.back().c_str()); |
| 230 } | 300 } |
| 231 | 301 |
| 232 } // namespace content | 302 } // namespace content |
| OLD | NEW |