Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Unified Diff: content/browser/renderer_host/input/gesture_text_selector_unittest.cc

Issue 342633003: [Android] Select text when stylus first button is pressed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not select text when two buttons are pressed Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..367a3eeb01b16b9451bc2d555a9aad1981cd4d59
--- /dev/null
+++ b/content/browser/renderer_host/input/gesture_text_selector_unittest.cc
@@ -0,0 +1,156 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "content/browser/renderer_host/input/gesture_text_selector.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/event_constants.h"
+#include "ui/events/gesture_detection/gesture_event_data.h"
+#include "ui/events/gesture_detection/mock_motion_event.h"
+#include "ui/events/gesture_detection/motion_event.h"
+#include "ui/gfx/geometry/rect_f.h"
+
+using ui::GestureEventData;
+using ui::GestureEventDetails;
+using ui::MockMotionEvent;
+using ui::MotionEvent;
+
+namespace content {
+
+class GestureTextSelectorTest : public testing::Test,
+ public GestureTextSelectorClient {
+ public:
+ GestureTextSelectorTest() {}
+ virtual ~GestureTextSelectorTest() {}
+
+ // Test implementation.
+ virtual void SetUp() OVERRIDE {
+ selector_.reset(new GestureTextSelector(this));
+ event_log_.clear();
+ }
+
+ virtual void TearDown() OVERRIDE {
+ selector_.reset();
+ event_log_.clear();
+ }
+
+ // GestureTextSelectorClient implementation.
+ virtual void ShowSelectionHandlesAutomatically() OVERRIDE {
+ event_log_.push_back("Show");
+ }
+
+ virtual void SelectRange(float x1, float y1, float x2, float y2) OVERRIDE {
+ event_log_.push_back("SelectRange");
+ }
+
+ virtual void SelectWord(float x, float y) OVERRIDE {
+ event_log_.push_back("SelectWord");
+ }
+
+ virtual void Unselect() OVERRIDE {
+ event_log_.push_back("Unselect");
+ }
+
+ protected:
+ scoped_ptr<GestureTextSelector> selector_;
+ std::vector<std::string> event_log_;
+};
+
+TEST_F(GestureTextSelectorTest, ShouldStartTextSelection) {
+ base::TimeTicks event_time = base::TimeTicks::Now();
+ { // Touched with a finger.
+ MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
+ e.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER);
+ e.SetButtonState(0);
+ EXPECT_FALSE(selector_->ShouldStartTextSelection(e));
+ }
+
+ { // Touched with a stylus, but no button pressed.
+ MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
+ e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
+ e.SetButtonState(0);
+ EXPECT_FALSE(selector_->ShouldStartTextSelection(e));
+ }
+
+ { // Touched with a stylus, with first button (BUTTON_SECONDARY) pressed.
+ MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
+ e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
+ e.SetButtonState(MotionEvent::BUTTON_SECONDARY);
+ EXPECT_TRUE(selector_->ShouldStartTextSelection(e));
+ }
+
+ { // Touched with a stylus, with two buttons pressed.
jdduke (slow) 2014/06/24 15:38:37 Do you know what the SPen does in this case? Will
Changwan Ryu 2014/06/25 07:26:21 SPen has only one button. We may want to assign so
+ MockMotionEvent e(MotionEvent::ACTION_DOWN, event_time, 50.0f, 50.0f);
+ e.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
+ e.SetButtonState(
+ MotionEvent::BUTTON_SECONDARY | MotionEvent::BUTTON_TERTIARY);
+ EXPECT_FALSE(selector_->ShouldStartTextSelection(e));
+ }
+}
+
+TEST_F(GestureTextSelectorTest, EventConsumption) {
+ 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 GestureEventData long_press(
+ GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0), 0, event_time,
+ x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0));
+ const GestureEventData double_tap(
+ GestureEventDetails(ui::ET_GESTURE_DOUBLE_TAP, 0, 0), 0, event_time,
+ x2, y2, x2, y2, 1, gfx::RectF(0, 0, 0, 0));
+ // 0. Touched with a finger: ignored
+ MockMotionEvent finger(MotionEvent::ACTION_DOWN, event_time, x1, y1);
+ finger.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER);
+ EXPECT_FALSE(selector_->OnTouchEvent(finger));
+ // We do not consume finger events.
+ EXPECT_FALSE(selector_->OnGestureEvent(long_press));
+ EXPECT_FALSE(selector_->OnGestureEvent(double_tap));
+ EXPECT_TRUE(event_log_.empty());
+
+ // 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.SetButtonState(MotionEvent::BUTTON_SECONDARY);
+ EXPECT_TRUE(selector_->OnTouchEvent(action_down));
+ EXPECT_EQ(2, event_log_.size()); // Show, Unselect
+ EXPECT_STREQ("Unselect", event_log_.back().c_str());
+
+ // 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.SetButtonState(MotionEvent::BUTTON_SECONDARY);
+ EXPECT_TRUE(selector_->OnTouchEvent(action_move));
+ // Consume and suppress events when in text selection mode (except LONG PRESS
+ // and some other events).
+ EXPECT_TRUE(selector_->OnGestureEvent(double_tap));
+ EXPECT_EQ(4, event_log_.size()); // Show, Unselect, Show, SelectRange
+ EXPECT_STREQ("SelectRange", event_log_.back().c_str());
+
+ // 3. ACTION_UP
+ event_time += base::TimeDelta::FromMilliseconds(10);
+ MockMotionEvent action_up(MotionEvent::ACTION_UP, event_time, x2, y2);
+ action_up.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
+ action_up.SetButtonState(0);
+ EXPECT_TRUE(selector_->OnTouchEvent(action_up));
+ // Show, Unselect, Show, SelectRange, Show, SelectRange
+ EXPECT_EQ(6, event_log_.size());
+ EXPECT_STREQ("SelectRange", event_log_.back().c_str());
+
+ // 4. LONG_PRESS (This can occur before or after ACTION_UP.)
jdduke (slow) 2014/06/24 15:38:37 Hmm, LONG_PRESS should only ever occur before ACTI
Changwan Ryu 2014/06/25 07:26:21 Removed as LONG_PRESS requirement is still in talk
+ event_time += base::TimeDelta::FromMilliseconds(10);
+ EXPECT_TRUE(selector_->OnGestureEvent(long_press));
+ // Show, Unselect, Show, SelectRange, Show, SelectRange, SelectWord
+ EXPECT_EQ(7, event_log_.size());
+ EXPECT_STREQ("SelectWord", event_log_.back().c_str());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698