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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 virtual void Unselect() OVERRIDE { | 51 virtual void Unselect() OVERRIDE { |
52 event_log_.push_back("Unselect"); | 52 event_log_.push_back("Unselect"); |
53 } | 53 } |
54 | 54 |
55 virtual void LongPress(base::TimeTicks time, float x, float y) OVERRIDE { | 55 virtual void LongPress(base::TimeTicks time, float x, float y) OVERRIDE { |
56 event_log_.push_back("LongPress"); | 56 event_log_.push_back("LongPress"); |
57 } | 57 } |
58 | 58 |
59 protected: | 59 protected: |
| 60 static GestureEventData CreateGesture(ui::EventType type, |
| 61 base::TimeTicks event_time, |
| 62 float x, |
| 63 float y) { |
| 64 return GestureEventData(GestureEventDetails(type, 0, 0), |
| 65 0, |
| 66 MotionEvent::TOOL_TYPE_FINGER, |
| 67 event_time, |
| 68 x, |
| 69 y, |
| 70 x, |
| 71 y, |
| 72 1, |
| 73 gfx::RectF(0, 0, 0, 0)); |
| 74 } |
| 75 |
60 scoped_ptr<GestureTextSelector> selector_; | 76 scoped_ptr<GestureTextSelector> selector_; |
61 std::vector<std::string> event_log_; | 77 std::vector<std::string> event_log_; |
62 }; | 78 }; |
63 | 79 |
64 TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) { | 80 TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) { |
65 base::TimeTicks event_time = base::TimeTicks::Now(); | 81 base::TimeTicks event_time = base::TimeTicks::Now(); |
66 { // Touched with a finger. | 82 { // Touched with a finger. |
67 MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f); | 83 MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f); |
68 e.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER); | 84 e.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER); |
69 e.set_button_state(0); | 85 e.set_button_state(0); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 event_time += base::TimeDelta::FromMilliseconds(10); | 139 event_time += base::TimeDelta::FromMilliseconds(10); |
124 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); | 140 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); |
125 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 141 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
126 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | 142 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
127 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | 143 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
128 EXPECT_TRUE(event_log_.empty()); | 144 EXPECT_TRUE(event_log_.empty()); |
129 | 145 |
130 // 3. DOUBLE TAP | 146 // 3. DOUBLE TAP |
131 // Suppress most gesture events when in text selection mode. | 147 // Suppress most gesture events when in text selection mode. |
132 event_time += base::TimeDelta::FromMilliseconds(10); | 148 event_time += base::TimeDelta::FromMilliseconds(10); |
133 const GestureEventData double_tap( | 149 const GestureEventData double_tap = |
134 GestureEventDetails(ui::ET_GESTURE_DOUBLE_TAP, 0, 0), 0, event_time, | 150 CreateGesture(ui::ET_GESTURE_DOUBLE_TAP, event_time, x2, y2); |
135 x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0)); | |
136 EXPECT_TRUE(selector_->OnGestureEvent(double_tap)); | 151 EXPECT_TRUE(selector_->OnGestureEvent(double_tap)); |
137 EXPECT_TRUE(event_log_.empty()); | 152 EXPECT_TRUE(event_log_.empty()); |
138 | 153 |
139 // 4. ET_GESTURE_SCROLL_BEGIN | 154 // 4. ET_GESTURE_SCROLL_BEGIN |
140 event_time += base::TimeDelta::FromMilliseconds(10); | 155 event_time += base::TimeDelta::FromMilliseconds(10); |
141 const GestureEventData scroll_begin( | 156 const GestureEventData scroll_begin = |
142 GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0), 0, event_time, | 157 CreateGesture(ui::ET_GESTURE_SCROLL_BEGIN, event_time, x1, y1); |
143 x1, y1, x1, y1, 1, gfx::RectF(0, 0, 0, 0)); | |
144 EXPECT_TRUE(selector_->OnGestureEvent(scroll_begin)); | 158 EXPECT_TRUE(selector_->OnGestureEvent(scroll_begin)); |
145 EXPECT_EQ(1u, event_log_.size()); // Unselect | 159 EXPECT_EQ(1u, event_log_.size()); // Unselect |
146 | 160 |
147 // 5. ET_GESTURE_SCROLL_UPDATE | 161 // 5. ET_GESTURE_SCROLL_UPDATE |
148 event_time += base::TimeDelta::FromMilliseconds(10); | 162 event_time += base::TimeDelta::FromMilliseconds(10); |
149 const GestureEventData scroll_update( | 163 const GestureEventData scroll_update = |
150 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, 0, 0), 0, event_time, | 164 CreateGesture(ui::ET_GESTURE_SCROLL_UPDATE, event_time, x2, y2); |
151 x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0)); | |
152 EXPECT_TRUE(selector_->OnGestureEvent(scroll_update)); | 165 EXPECT_TRUE(selector_->OnGestureEvent(scroll_update)); |
153 EXPECT_EQ(3u, event_log_.size()); // Unselect, Show, SelectRange | 166 EXPECT_EQ(3u, event_log_.size()); // Unselect, Show, SelectRange |
154 EXPECT_STREQ("SelectRange", event_log_.back().c_str()); | 167 EXPECT_STREQ("SelectRange", event_log_.back().c_str()); |
155 | 168 |
156 // 6. ACTION_UP | 169 // 6. ACTION_UP |
157 event_time += base::TimeDelta::FromMilliseconds(10); | 170 event_time += base::TimeDelta::FromMilliseconds(10); |
158 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 171 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
159 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 172 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
160 action_up.set_button_state(0); | 173 action_up.set_button_state(0); |
161 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 174 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
162 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | 175 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE |
163 | 176 |
164 // 7. ET_GESTURE_SCROLL_END | 177 // 7. ET_GESTURE_SCROLL_END |
165 event_time += base::TimeDelta::FromMilliseconds(10); | 178 event_time += base::TimeDelta::FromMilliseconds(10); |
166 const GestureEventData scroll_end( | 179 const GestureEventData scroll_end = |
167 GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0), 0, event_time, | 180 CreateGesture(ui::ET_GESTURE_SCROLL_END, event_time, x2, y2); |
168 x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0)); | |
169 EXPECT_TRUE(selector_->OnGestureEvent(scroll_end)); | 181 EXPECT_TRUE(selector_->OnGestureEvent(scroll_end)); |
170 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE | 182 EXPECT_EQ(3u, event_log_.size()); // NO CHANGE |
171 } | 183 } |
172 | 184 |
173 TEST_F(GestureTextSelectorTest, TapToSelectWord) { | 185 TEST_F(GestureTextSelectorTest, TapToSelectWord) { |
174 base::TimeTicks event_time = base::TimeTicks::Now(); | 186 base::TimeTicks event_time = base::TimeTicks::Now(); |
175 const float x1 = 50.0f; | 187 const float x1 = 50.0f; |
176 const float y1 = 30.0f; | 188 const float y1 = 30.0f; |
177 const float x2 = 51.0f; | 189 const float x2 = 51.0f; |
178 const float y2 = 31.0f; | 190 const float y2 = 31.0f; |
179 // 1. ACTION_DOWN with stylus + button | 191 // 1. ACTION_DOWN with stylus + button |
180 event_time += base::TimeDelta::FromMilliseconds(10); | 192 event_time += base::TimeDelta::FromMilliseconds(10); |
181 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); | 193 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); |
182 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 194 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
183 action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); | 195 action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); |
184 EXPECT_TRUE(selector_->OnTouchEvent(action_down)); | 196 EXPECT_TRUE(selector_->OnTouchEvent(action_down)); |
185 EXPECT_TRUE(event_log_.empty()); | 197 EXPECT_TRUE(event_log_.empty()); |
186 | 198 |
187 // 5. TAP_DOWN | 199 // 5. TAP_DOWN |
188 event_time += base::TimeDelta::FromMilliseconds(10); | 200 event_time += base::TimeDelta::FromMilliseconds(10); |
189 const GestureEventData tap_down( | 201 const GestureEventData tap_down = |
190 GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0), 0, event_time, | 202 CreateGesture(ui::ET_GESTURE_TAP_DOWN, event_time, x2, y2); |
191 x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0)); | |
192 EXPECT_TRUE(selector_->OnGestureEvent(tap_down)); | 203 EXPECT_TRUE(selector_->OnGestureEvent(tap_down)); |
193 EXPECT_TRUE(event_log_.empty()); | 204 EXPECT_TRUE(event_log_.empty()); |
194 | 205 |
195 // 2. ACTION_MOVE | 206 // 2. ACTION_MOVE |
196 event_time += base::TimeDelta::FromMilliseconds(10); | 207 event_time += base::TimeDelta::FromMilliseconds(10); |
197 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); | 208 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); |
198 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 209 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
199 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | 210 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
200 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | 211 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
201 EXPECT_TRUE(event_log_.empty()); | 212 EXPECT_TRUE(event_log_.empty()); |
202 | 213 |
203 // 3. ACTION_UP | 214 // 3. ACTION_UP |
204 event_time += base::TimeDelta::FromMilliseconds(10); | 215 event_time += base::TimeDelta::FromMilliseconds(10); |
205 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 216 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
206 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 217 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
207 action_up.set_button_state(0); | 218 action_up.set_button_state(0); |
208 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 219 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
209 EXPECT_TRUE(event_log_.empty()); | 220 EXPECT_TRUE(event_log_.empty()); |
210 | 221 |
211 // 4. TAP | 222 // 4. TAP |
212 event_time += base::TimeDelta::FromMilliseconds(10); | 223 event_time += base::TimeDelta::FromMilliseconds(10); |
213 const GestureEventData tap( | 224 const GestureEventData tap = |
214 GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0), 0, event_time, | 225 CreateGesture(ui::ET_GESTURE_TAP, event_time, x1, y1); |
215 x1, y1, x1, y1, 1, gfx::RectF(0, 0, 0, 0)); | |
216 EXPECT_TRUE(selector_->OnGestureEvent(tap)); | 226 EXPECT_TRUE(selector_->OnGestureEvent(tap)); |
217 EXPECT_EQ(1u, event_log_.size()); // LongPress | 227 EXPECT_EQ(1u, event_log_.size()); // LongPress |
218 EXPECT_STREQ("LongPress", event_log_.back().c_str()); | 228 EXPECT_STREQ("LongPress", event_log_.back().c_str()); |
219 } | 229 } |
220 | 230 |
221 } // namespace content | 231 } // namespace content |
OLD | NEW |