| Index: content/browser/renderer_host/input/stylus_text_selector_unittest.cc
|
| diff --git a/content/browser/renderer_host/input/stylus_text_selector_unittest.cc b/content/browser/renderer_host/input/stylus_text_selector_unittest.cc
|
| index 887b4c23819ce45311e4cc44eec41ac78a9edb7c..41be0954cc59c9576329ecadb942296008ba77e3 100644
|
| --- a/content/browser/renderer_host/input/stylus_text_selector_unittest.cc
|
| +++ b/content/browser/renderer_host/input/stylus_text_selector_unittest.cc
|
| @@ -78,19 +78,41 @@ TEST_F(StylusTextSelectorTest, ShouldStartTextSelection) {
|
| }
|
|
|
| { // Touched with a stylus, with first button (BUTTON_SECONDARY) pressed.
|
| + // For Android version < M, this stylus state is BUTTON_SECONDARY.
|
| MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
|
| e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| e.set_button_state(MotionEvent::BUTTON_SECONDARY);
|
| EXPECT_TRUE(selector_->ShouldStartTextSelection(e));
|
| }
|
|
|
| + { // Touched with a stylus, with first button (BUTTON_STYLUS_PRIMARY)
|
| + // pressed. From Android M, this stylus state has been changed to
|
| + // BUTTON_STYLUS_PRIMARY.
|
| + MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
|
| + e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + e.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->ShouldStartTextSelection(e));
|
| + }
|
| +
|
| { // Touched with a stylus, with two buttons pressed.
|
| + // For Android version < M, these states are BUTTON_SECONDARY,
|
| + // BUTTON_TERTIARY.
|
| MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
|
| e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| e.set_button_state(MotionEvent::BUTTON_SECONDARY |
|
| MotionEvent::BUTTON_TERTIARY);
|
| EXPECT_FALSE(selector_->ShouldStartTextSelection(e));
|
| }
|
| +
|
| + { // Touched with a stylus, with two buttons pressed.
|
| + // From Android M, these state are BUTTON_STYLUS_PRIMARY,
|
| + // BUTTON_STYLUS_SECONDARY.
|
| + MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
|
| + e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + e.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY |
|
| + MotionEvent::BUTTON_STYLUS_SECONDARY);
|
| + EXPECT_FALSE(selector_->ShouldStartTextSelection(e));
|
| + }
|
| }
|
|
|
| TEST_F(StylusTextSelectorTest, FingerTouch) {
|
| @@ -105,7 +127,9 @@ TEST_F(StylusTextSelectorTest, FingerTouch) {
|
| EXPECT_TRUE(event_log_.empty());
|
| }
|
|
|
| -TEST_F(StylusTextSelectorTest, PenDragging) {
|
| +// The following Tests cover BUTTON_SECONDARY case, which is the stylus button
|
| +// pressed state for Android version < M.
|
| +TEST_F(StylusTextSelectorTest, PenDraggingButtonSecondary) {
|
| base::TimeTicks event_time = base::TimeTicks::Now();
|
| const float x1 = 50.0f;
|
| const float y1 = 30.0f;
|
| @@ -148,7 +172,7 @@ TEST_F(StylusTextSelectorTest, PenDragging) {
|
| EXPECT_STREQ("End", event_log_.back().c_str());
|
| }
|
|
|
| -TEST_F(StylusTextSelectorTest, PenDraggingButtonNotPressed) {
|
| +TEST_F(StylusTextSelectorTest, PenDraggingButtonSecondaryNotPressed) {
|
| base::TimeTicks event_time = base::TimeTicks::Now();
|
| float x = 50.0f;
|
| float y = 30.0f;
|
| @@ -244,5 +268,149 @@ TEST_F(StylusTextSelectorTest, TapTriggersLongPressSelection) {
|
| ASSERT_EQ(1u, event_log_.size());
|
| EXPECT_STREQ("Tap", event_log_.back().c_str());
|
| }
|
| +// End of Tests for BUTTON_SECONDARY case.
|
| +
|
| +// The following Tests cover BUTTON_STYLUS_PRIMARY case, which is the stylus
|
| +// button pressed state from Android M.
|
| +TEST_F(StylusTextSelectorTest, PenDraggingButtonStylusPrimary) {
|
| + base::TimeTicks event_time = base::TimeTicks::Now();
|
| + const float x1 = 50.0f;
|
| + const float y1 = 30.0f;
|
| + const float x2 = 100.0f;
|
| + const float y2 = 90.0f;
|
| + const float x3 = 150.0f;
|
| + const float y3 = 150.0f;
|
| + // 1. ACTION_DOWN with stylus + button
|
| + event_time += base::TimeDelta::FromMilliseconds(10);
|
| + MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1);
|
| + action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_down.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_down));
|
| + EXPECT_TRUE(event_log_.empty());
|
| +
|
| + // 2. ACTION_MOVE
|
| + event_time += base::TimeDelta::FromMilliseconds(10);
|
| + MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2);
|
| + action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_move.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + ASSERT_EQ(1u, event_log_.size());
|
| + EXPECT_STREQ("Begin(50, 30, 100, 90)", event_log_.back().c_str());
|
| +
|
| + event_time += base::TimeDelta::FromMilliseconds(10);
|
| + action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x3, y3);
|
| + action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_move.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + ASSERT_EQ(2u, event_log_.size());
|
| + EXPECT_STREQ("Update(150, 150)", event_log_.back().c_str());
|
| +
|
| + // 3. ACTION_UP
|
| + event_time += base::TimeDelta::FromMilliseconds(10);
|
| + MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x3, y3);
|
| + action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_up.set_button_state(0);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_up));
|
| + ASSERT_EQ(3u, event_log_.size()); // NO CHANGE
|
| + EXPECT_STREQ("End", event_log_.back().c_str());
|
| +}
|
| +
|
| +TEST_F(StylusTextSelectorTest, PenDraggingButtonStylusPrimaryNotPressed) {
|
| + 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_STYLUS_PRIMARY);
|
| + 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_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + ASSERT_EQ(1u, event_log_.size());
|
| + EXPECT_STREQ("Begin(50, 30, 70, 50)", event_log_.back().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(1u, event_log_.size()); // NO CHANGE
|
| +
|
| + // 4. ACTION_MOVE with stylus + button pressed again
|
| + // Note that the end action is deferred until the stylus is lifted.
|
| + 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_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + EXPECT_EQ(2u, event_log_.size());
|
| + EXPECT_STREQ("Begin(90, 70, 110, 90)", event_log_.back().c_str());
|
| +
|
| + // 5. ACTION_MOVE with stylus + no button
|
| + event_time += base::TimeDelta::FromMilliseconds(10);
|
| + x += 20; // 130
|
| + y += 20; // 110
|
| + action_move = MockMotionEvent(MotionEvent::ACTION_MOVE, event_time, x, y);
|
| + action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + EXPECT_EQ(2u, event_log_.size()); // NO CHANGE
|
| +
|
| + // 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(3u, event_log_.size());
|
| + EXPECT_STREQ("End", event_log_.back().c_str());
|
| +}
|
| +
|
| +TEST_F(StylusTextSelectorTest, TapTriggersLongPressSelection2) {
|
| + base::TimeTicks event_time = base::TimeTicks::Now();
|
| + const float x1 = 50.0f;
|
| + const float y1 = 30.0f;
|
| + const float x2 = 51.0f;
|
| + const float y2 = 31.0f;
|
| + // 1. ACTION_DOWN with stylus + button
|
| + event_time += base::TimeDelta::FromMilliseconds(1);
|
| + MockMotionEvent action_down(MotionEvent::ACTION_DOWN, event_time, x1, y1);
|
| + action_down.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_down.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_down));
|
| + EXPECT_TRUE(event_log_.empty());
|
| +
|
| + // 2. ACTION_MOVE
|
| + event_time += base::TimeDelta::FromMilliseconds(1);
|
| + MockMotionEvent action_move(MotionEvent::ACTION_MOVE, event_time, x2, y2);
|
| + action_move.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_move.set_button_state(MotionEvent::BUTTON_STYLUS_PRIMARY);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_move));
|
| + EXPECT_TRUE(event_log_.empty());
|
| +
|
| + // 3. ACTION_UP
|
| + event_time += base::TimeDelta::FromMilliseconds(1);
|
| + MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2);
|
| + action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
|
| + action_up.set_button_state(0);
|
| + EXPECT_TRUE(selector_->OnTouchEvent(action_up));
|
| + ASSERT_EQ(1u, event_log_.size());
|
| + EXPECT_STREQ("Tap", event_log_.back().c_str());
|
| +}
|
| +// End of tests for BUTTON_STLUS_PRIMARY case.
|
|
|
| } // namespace content
|
|
|