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 24 matching lines...) Expand all Loading... |
35 selector_.reset(); | 35 selector_.reset(); |
36 event_log_.clear(); | 36 event_log_.clear(); |
37 } | 37 } |
38 | 38 |
39 // GestureTextSelectorClient implementation. | 39 // GestureTextSelectorClient implementation. |
40 virtual void ShowSelectionHandlesAutomatically() override { | 40 virtual void ShowSelectionHandlesAutomatically() override { |
41 event_log_.push_back("Show"); | 41 event_log_.push_back("Show"); |
42 } | 42 } |
43 | 43 |
44 virtual void SelectRange(float x1, float y1, float x2, float y2) override { | 44 virtual void SelectRange(float x1, float y1, float x2, float y2) override { |
45 event_log_.push_back("SelectRange"); | 45 std::stringstream ss; |
| 46 ss << "SelectRange(" << x1 << ", " << y1 << ", " << x2 << ", " << y2 << ")"; |
| 47 event_log_.push_back(ss.str()); |
46 } | 48 } |
47 | 49 |
48 virtual void LongPress(base::TimeTicks time, float x, float y) override { | 50 virtual void LongPress(base::TimeTicks time, float x, float y) override { |
49 event_log_.push_back("LongPress"); | 51 event_log_.push_back("LongPress"); |
50 } | 52 } |
51 | 53 |
52 protected: | 54 protected: |
53 scoped_ptr<GestureTextSelector> selector_; | 55 scoped_ptr<GestureTextSelector> selector_; |
54 std::vector<std::string> event_log_; | 56 std::vector<std::string> event_log_; |
55 }; | 57 }; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 EXPECT_TRUE(event_log_.empty()); | 115 EXPECT_TRUE(event_log_.empty()); |
114 | 116 |
115 // 2. ACTION_MOVE | 117 // 2. ACTION_MOVE |
116 event_time += base::TimeDelta::FromMilliseconds(10); | 118 event_time += base::TimeDelta::FromMilliseconds(10); |
117 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); | 119 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2); |
118 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 120 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
119 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); | 121 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
120 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); | 122 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
121 ASSERT_EQ(2u, event_log_.size()); | 123 ASSERT_EQ(2u, event_log_.size()); |
122 EXPECT_STREQ("Show", event_log_[0].c_str()); | 124 EXPECT_STREQ("Show", event_log_[0].c_str()); |
123 EXPECT_STREQ("SelectRange", event_log_[1].c_str()); | 125 EXPECT_STREQ("SelectRange(50, 30, 100, 90)", event_log_[1].c_str()); |
124 | 126 |
125 // 3. ACTION_UP | 127 // 3. ACTION_UP |
126 event_time += base::TimeDelta::FromMilliseconds(10); | 128 event_time += base::TimeDelta::FromMilliseconds(10); |
127 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 129 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
128 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 130 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
129 action_up.set_button_state(0); | 131 action_up.set_button_state(0); |
130 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 132 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
131 ASSERT_EQ(2u, event_log_.size()); // NO CHANGE | 133 ASSERT_EQ(2u, event_log_.size()); // NO CHANGE |
132 } | 134 } |
133 | 135 |
| 136 TEST_F(GestureTextSelectorTest, PenDraggingButtonNotPressed) { |
| 137 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 138 float x = 50.0f; |
| 139 float y = 30.0f; |
| 140 |
| 141 // 1. ACTION_DOWN with stylus + button |
| 142 event_time += base::TimeDelta::FromMilliseconds(10); |
| 143 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x, y); |
| 144 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 145 action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); |
| 146 EXPECT_TRUE(selector_->OnTouchEvent(action_down)); |
| 147 EXPECT_TRUE(event_log_.empty()); |
| 148 |
| 149 // 2. ACTION_MOVE |
| 150 event_time += base::TimeDelta::FromMilliseconds(10); |
| 151 x += 20; // 70 |
| 152 y += 20; // 50 |
| 153 MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x, y); |
| 154 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 155 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
| 156 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
| 157 ASSERT_EQ(2u, event_log_.size()); |
| 158 EXPECT_STREQ("Show", event_log_[0].c_str()); |
| 159 EXPECT_STREQ("SelectRange(50, 30, 70, 50)", event_log_[1].c_str()); |
| 160 |
| 161 // 3. ACTION_MOVE with stylus + no button |
| 162 event_time += base::TimeDelta::FromMilliseconds(10); |
| 163 x += 20; // 90 |
| 164 y += 20; // 70 |
| 165 action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); |
| 166 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 167 action_move.set_button_state(0); |
| 168 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
| 169 EXPECT_EQ(2u, event_log_.size()); // NO CHANGE |
| 170 |
| 171 // 4. ACTION_MOVE with stylus + button pressed again |
| 172 event_time += base::TimeDelta::FromMilliseconds(10); |
| 173 x += 20; // 110 |
| 174 y += 20; // 90 |
| 175 action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); |
| 176 action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 177 action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
| 178 EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
| 179 EXPECT_EQ(4u, event_log_.size()); |
| 180 EXPECT_STREQ("SelectRange(90, 70, 110, 90)", event_log_.back().c_str()); |
| 181 |
| 182 // 5. ACTION_UP |
| 183 event_time += base::TimeDelta::FromMilliseconds(10); |
| 184 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x, y); |
| 185 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
| 186 action_up.set_button_state(0); |
| 187 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
| 188 EXPECT_EQ(4u, event_log_.size()); // NO CHANGE |
| 189 } |
| 190 |
134 TEST_F(GestureTextSelectorTest, TapTriggersLongPressSelection) { | 191 TEST_F(GestureTextSelectorTest, TapTriggersLongPressSelection) { |
135 base::TimeTicks event_time = base::TimeTicks::Now(); | 192 base::TimeTicks event_time = base::TimeTicks::Now(); |
136 const float x1 = 50.0f; | 193 const float x1 = 50.0f; |
137 const float y1 = 30.0f; | 194 const float y1 = 30.0f; |
138 const float x2 = 51.0f; | 195 const float x2 = 51.0f; |
139 const float y2 = 31.0f; | 196 const float y2 = 31.0f; |
140 // 1. ACTION_DOWN with stylus + button | 197 // 1. ACTION_DOWN with stylus + button |
141 event_time += base::TimeDelta::FromMilliseconds(1); | 198 event_time += base::TimeDelta::FromMilliseconds(1); |
142 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); | 199 MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1); |
143 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 200 action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
(...skipping 13 matching lines...) Expand all Loading... |
157 event_time += base::TimeDelta::FromMilliseconds(1); | 214 event_time += base::TimeDelta::FromMilliseconds(1); |
158 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); | 215 MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2); |
159 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); | 216 action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
160 action_up.set_button_state(0); | 217 action_up.set_button_state(0); |
161 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); | 218 EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
162 ASSERT_EQ(1u, event_log_.size()); | 219 ASSERT_EQ(1u, event_log_.size()); |
163 EXPECT_STREQ("LongPress", event_log_.back().c_str()); | 220 EXPECT_STREQ("LongPress", event_log_.back().c_str()); |
164 } | 221 } |
165 | 222 |
166 } // namespace content | 223 } // namespace content |
OLD | NEW |