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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 124 |
125 // 3. ACTION_UP | 125 // 3. ACTION_UP |
126 event_time += base::TimeDelta::FromMilliseconds(10); | 126 event_time += base::TimeDelta::FromMilliseconds(10); |
127 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 127 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
128 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 128 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
129 action_up.set_button_state(0); | 129 action_up.set_button_state(0); |
130 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 130 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
131 ASSERT_EQ(2u, event_log_.size()); // NO CHANGE | 131 ASSERT_EQ(2u, event_log_.size()); // NO CHANGE |
132 } | 132 } |
133 | 133 |
134 TEST_F(GestureTextSelectorTest, PenDraggingButtonNotPressed) { | |
135 base::TimeTicks event_time = base::TimeTicks::Now(); | |
136 float x = 50.0f; | |
137 float y = 30.0f; | |
138 | |
139 // 1. ACTION_DOWN with stylus + button | |
140 event_time += base::TimeDelta::FromMilliseconds(10); | |
141 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x, y); | |
142 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
143 action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); | |
144 EXPECT_TRUE(selector_->OnTouchEvent(action_down)); | |
145 EXPECT_TRUE(event_log_.empty()); | |
146 | |
147 // 2. ACTION_MOVE | |
148 event_time += base::TimeDelta::FromMilliseconds(10); | |
149 x += 20; | |
150 y += 20; | |
151 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x, y); | |
152 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
153 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | |
154 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | |
155 ASSERT_EQ(2u, event_log_.size()); | |
156 EXPECT_STREQ("Show", event_log_[0].c_str()); | |
157 EXPECT_STREQ("SelectRange", event_log_[1].c_str()); | |
158 | |
159 // 3. ACTION_MOVE with stylus + no button | |
160 event_time += base::TimeDelta::FromMilliseconds(10); | |
161 x += 20; | |
162 y += 20; | |
163 action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); | |
164 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
165 action_move.set_button_state(0); | |
166 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | |
167 EXPECT_EQ(2u, event_log_.size()); // NO CHANGE | |
168 | |
169 // 4. ACTION_MOVE with stylus + button pressed again | |
170 event_time += base::TimeDelta::FromMilliseconds(10); | |
171 x += 20; | |
172 y += 20; | |
173 action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); | |
174 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
175 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | |
176 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | |
177 EXPECT_EQ(4u, event_log_.size()); | |
178 EXPECT_STREQ("SelectRange", event_log_.back().c_str()); | |
jdduke (slow)
2014/10/10 14:37:33
Ideally we could check the actual SelectRange coor
AviD
2014/10/10 16:06:11
I have added a function to convert the float value
| |
179 | |
180 // 5. ACTION_UP | |
181 event_time += base::TimeDelta::FromMilliseconds(10); | |
182 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x, y); | |
183 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | |
184 action_up.set_button_state(0); | |
185 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | |
186 EXPECT_EQ(4u, event_log_.size()); // NO CHANGE | |
187 } | |
188 | |
134 TEST_F(GestureTextSelectorTest, TapTriggersLongPressSelection) { | 189 TEST_F(GestureTextSelectorTest, TapTriggersLongPressSelection) { |
135 base::TimeTicks event_time = base::TimeTicks::Now(); | 190 base::TimeTicks event_time = base::TimeTicks::Now(); |
136 const float x1 = 50.0f; | 191 const float x1 = 50.0f; |
137 const float y1 = 30.0f; | 192 const float y1 = 30.0f; |
138 const float x2 = 51.0f; | 193 const float x2 = 51.0f; |
139 const float y2 = 31.0f; | 194 const float y2 = 31.0f; |
140 // 1. ACTION_DOWN with stylus + button | 195 // 1. ACTION_DOWN with stylus + button |
141 event_time += base::TimeDelta::FromMilliseconds(1); | 196 event_time += base::TimeDelta::FromMilliseconds(1); |
142 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); | 197 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); |
143 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 198 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
(...skipping 13 matching lines...) Expand all Loading... | |
157 event_time += base::TimeDelta::FromMilliseconds(1); | 212 event_time += base::TimeDelta::FromMilliseconds(1); |
158 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 213 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
159 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 214 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
160 action_up.set_button_state(0); | 215 action_up.set_button_state(0); |
161 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 216 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
162 ASSERT_EQ(1u, event_log_.size()); | 217 ASSERT_EQ(1u, event_log_.size()); |
163 EXPECT_STREQ("LongPress", event_log_.back().c_str()); | 218 EXPECT_STREQ("LongPress", event_log_.back().c_str()); |
164 } | 219 } |
165 | 220 |
166 } // namespace content | 221 } // namespace content |
OLD | NEW |