Index: content/browser/renderer_host/input/gesture_text_selector_unittest.cc |
diff --git a/content/browser/renderer_host/input/gesture_text_selector_unittest.cc b/content/browser/renderer_host/input/gesture_text_selector_unittest.cc |
index 2d162458a97cf5831fe6e583dad96966355b88a4..cd0a3b7341c725d5f2b1671d7b3333a4fd53ca8f 100644 |
--- a/content/browser/renderer_host/input/gesture_text_selector_unittest.cc |
+++ b/content/browser/renderer_host/input/gesture_text_selector_unittest.cc |
@@ -2,6 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <sstream> |
#include <string> |
#include <vector> |
@@ -42,7 +43,8 @@ class GestureTextSelectorTest : public testing::Test, |
} |
virtual void SelectRange(float x1, float y1, float x2, float y2) override { |
- event_log_.push_back("SelectRange"); |
+ event_log_.push_back("SelectRange(" + to_string(x1) + ", " + to_string(y1) + |
jdduke (slow)
2014/10/10 16:22:12
Nit: No need for a helper function here, just do:
|
+ ", " + to_string(x2) + ", " + to_string(y2) + ")"); |
} |
virtual void LongPress(base::TimeTicks time, float x, float y) override { |
@@ -52,6 +54,12 @@ class GestureTextSelectorTest : public testing::Test, |
protected: |
scoped_ptr<GestureTextSelector> selector_; |
std::vector<std::string> event_log_; |
+ |
+ std::string to_string(float val) { |
+ std::ostringstream os; |
+ os << val; |
+ return os.str(); |
+ } |
}; |
TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) { |
@@ -120,7 +128,7 @@ TEST_F(GestureTextSelectorTest, PenDragging) { |
EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
ASSERT_EQ(2u, event_log_.size()); |
EXPECT_STREQ("Show", event_log_[0].c_str()); |
- EXPECT_STREQ("SelectRange", event_log_[1].c_str()); |
+ EXPECT_STREQ("SelectRange(50, 30, 100, 90)", event_log_[1].c_str()); |
// 3. ACTION_UP |
event_time += base::TimeDelta::FromMilliseconds(10); |
@@ -131,6 +139,61 @@ TEST_F(GestureTextSelectorTest, PenDragging) { |
ASSERT_EQ(2u, event_log_.size()); // NO CHANGE |
} |
+TEST_F(GestureTextSelectorTest, PenDraggingButtonNotPressed) { |
+ base::TimeTicks event_time = base::TimeTicks::Now(); |
+ float x = 50.0f; |
+ float y = 30.0f; |
+ |
+ // 1. ACTION_DOWN with stylus + button |
+ event_time += base::TimeDelta::FromMilliseconds(10); |
+ MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x, y); |
+ action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
+ action_down.set_button_state(MotionEvent::BUTTON_SECONDARY); |
+ EXPECT_TRUE(selector_->OnTouchEvent(action_down)); |
+ EXPECT_TRUE(event_log_.empty()); |
+ |
+ // 2. ACTION_MOVE |
+ event_time += base::TimeDelta::FromMilliseconds(10); |
+ x += 20; // 70 |
+ y += 20; // 50 |
+ MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x, y); |
+ action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
+ action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
+ EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
+ ASSERT_EQ(2u, event_log_.size()); |
+ EXPECT_STREQ("Show", event_log_[0].c_str()); |
+ EXPECT_STREQ("SelectRange(50, 30, 70, 50)", event_log_[1].c_str()); |
+ |
+ // 3. ACTION_MOVE with stylus + no button |
+ event_time += base::TimeDelta::FromMilliseconds(10); |
+ x += 20; // 90 |
+ y += 20; // 70 |
+ action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); |
+ action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
+ action_move.set_button_state(0); |
+ EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
+ EXPECT_EQ(2u, event_log_.size()); // NO CHANGE |
+ |
+ // 4. ACTION_MOVE with stylus + button pressed again |
+ event_time += base::TimeDelta::FromMilliseconds(10); |
+ x += 20; // 110 |
+ y += 20; // 90 |
+ action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y); |
+ action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
+ action_move.set_button_state(MotionEvent::BUTTON_SECONDARY); |
+ EXPECT_TRUE(selector_->OnTouchEvent(action_move)); |
+ EXPECT_EQ(4u, event_log_.size()); |
+ EXPECT_STREQ("SelectRange(90, 70, 110, 90)", event_log_.back().c_str()); |
+ |
+ // 5. ACTION_UP |
+ event_time += base::TimeDelta::FromMilliseconds(10); |
+ MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x, y); |
+ action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS); |
+ action_up.set_button_state(0); |
+ EXPECT_TRUE(selector_->OnTouchEvent(action_up)); |
+ EXPECT_EQ(4u, event_log_.size()); // NO CHANGE |
+} |
+ |
TEST_F(GestureTextSelectorTest, TapTriggersLongPressSelection) { |
base::TimeTicks event_time = base::TimeTicks::Now(); |
const float x1 = 50.0f; |