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/browser/renderer_host/input/stylus_text_selector.h" | 5 #include "content/browser/renderer_host/input/stylus_text_selector.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ss << "Begin(" << x0 << ", " << y0 << ", " << x1 << ", " << y1 << ")"; | 43 ss << "Begin(" << x0 << ", " << y0 << ", " << x1 << ", " << y1 << ")"; |
44 event_log_.push_back(ss.str()); | 44 event_log_.push_back(ss.str()); |
45 } | 45 } |
46 | 46 |
47 void OnStylusSelectUpdate(float x, float y) override { | 47 void OnStylusSelectUpdate(float x, float y) override { |
48 std::stringstream ss; | 48 std::stringstream ss; |
49 ss << "Update(" << x << ", " << y << ")"; | 49 ss << "Update(" << x << ", " << y << ")"; |
50 event_log_.push_back(ss.str()); | 50 event_log_.push_back(ss.str()); |
51 } | 51 } |
52 | 52 |
53 void OnStylusSelectEnd() override { event_log_.push_back("End"); } | |
54 | |
55 void OnStylusSelectTap(base::TimeTicks time, float x, float y) override { | 53 void OnStylusSelectTap(base::TimeTicks time, float x, float y) override { |
56 event_log_.push_back("Tap"); | 54 event_log_.push_back("Tap"); |
57 } | 55 } |
58 | 56 |
59 protected: | 57 protected: |
60 std::unique_ptr<StylusTextSelector> selector_; | 58 std::unique_ptr<StylusTextSelector> selector_; |
61 std::vector<std::string> event_log_; | 59 std::vector<std::string> event_log_; |
62 }; | 60 }; |
63 | 61 |
64 TEST_F(StylusTextSelectorTest, ShouldStartTextSelection) { | 62 TEST_F(StylusTextSelectorTest, ShouldStartTextSelection) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | 135 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
138 ASSERT_EQ(2u, event_log_.size()); | 136 ASSERT_EQ(2u, event_log_.size()); |
139 EXPECT_STREQ("Update(150, 150)", event_log_.back().c_str()); | 137 EXPECT_STREQ("Update(150, 150)", event_log_.back().c_str()); |
140 | 138 |
141 // 3. ACTION_UP | 139 // 3. ACTION_UP |
142 event_time += base::TimeDelta::FromMilliseconds(10); | 140 event_time += base::TimeDelta::FromMilliseconds(10); |
143 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x3, y3); | 141 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x3, y3); |
144 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 142 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
145 action_up.set_button_state(0); | 143 action_up.set_button_state(0); |
146 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 144 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
147 ASSERT_EQ(3u, event_log_.size()); // NO CHANGE | 145 ASSERT_EQ(2u, event_log_.size()); // NO CHANGE |
148 EXPECT_STREQ("End", event_log_.back().c_str()); | |
149 } | 146 } |
150 | 147 |
151 TEST_F(StylusTextSelectorTest, PenDraggingButtonNotPressed) { | 148 TEST_F(StylusTextSelectorTest, PenDraggingButtonNotPressed) { |
152 base::TimeTicks event_time = base::TimeTicks::Now(); | 149 base::TimeTicks event_time = base::TimeTicks::Now(); |
153 float x = 50.0f; | 150 float x = 50.0f; |
154 float y = 30.0f; | 151 float y = 30.0f; |
155 | 152 |
156 // 1. ACTION_DOWN with stylus + button | 153 // 1. ACTION_DOWN with stylus + button |
157 event_time += base::TimeDelta::FromMilliseconds(10); | 154 event_time += base::TimeDelta::FromMilliseconds(10); |
158 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x, y); | 155 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x, y); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 199 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
203 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | 200 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
204 EXPECT_EQ(2u, event_log_.size()); // NO CHANGE | 201 EXPECT_EQ(2u, event_log_.size()); // NO CHANGE |
205 | 202 |
206 // 5. ACTION_UP | 203 // 5. ACTION_UP |
207 event_time += base::TimeDelta::FromMilliseconds(10); | 204 event_time += base::TimeDelta::FromMilliseconds(10); |
208 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x, y); | 205 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x, y); |
209 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 206 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
210 action_up.set_button_state(0); | 207 action_up.set_button_state(0); |
211 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 208 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
212 EXPECT_EQ(3u, event_log_.size()); | 209 EXPECT_EQ(2u, event_log_.size()); // NO CHANGE |
213 EXPECT_STREQ("End", event_log_.back().c_str()); | |
214 } | 210 } |
215 | 211 |
216 TEST_F(StylusTextSelectorTest, TapTriggersLongPressSelection) { | 212 TEST_F(StylusTextSelectorTest, TapTriggersLongPressSelection) { |
217 base::TimeTicks event_time = base::TimeTicks::Now(); | 213 base::TimeTicks event_time = base::TimeTicks::Now(); |
218 const float x1 = 50.0f; | 214 const float x1 = 50.0f; |
219 const float y1 = 30.0f; | 215 const float y1 = 30.0f; |
220 const float x2 = 51.0f; | 216 const float x2 = 51.0f; |
221 const float y2 = 31.0f; | 217 const float y2 = 31.0f; |
222 // 1. ACTION_DOWN with stylus + button | 218 // 1. ACTION_DOWN with stylus + button |
223 event_time += base::TimeDelta::FromMilliseconds(1); | 219 event_time += base::TimeDelta::FromMilliseconds(1); |
(...skipping 15 matching lines...) Expand all Loading... |
239 event_time += base::TimeDelta::FromMilliseconds(1); | 235 event_time += base::TimeDelta::FromMilliseconds(1); |
240 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 236 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
241 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 237 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
242 action_up.set_button_state(0); | 238 action_up.set_button_state(0); |
243 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 239 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
244 ASSERT_EQ(1u, event_log_.size()); | 240 ASSERT_EQ(1u, event_log_.size()); |
245 EXPECT_STREQ("Tap", event_log_.back().c_str()); | 241 EXPECT_STREQ("Tap", event_log_.back().c_str()); |
246 } | 242 } |
247 | 243 |
248 } // namespace content | 244 } // namespace content |
OLD | NEW |