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

Unified Diff: ui/views/touchui/touch_selection_controller_impl_unittest.cc

Issue 1947123003: Fixes a crash which occurs when a concealed selection handle in a textfield is exposed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@touch_devices_crash
Patch Set: Fixing the unit test on Windows - start the selection at 0, so that the drag doesn't overshoot. Created 4 years, 7 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
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/touchui/touch_selection_controller_impl_unittest.cc
diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
index 213170162b2aa9dcff012bc3903dedda6939dc74..602795aec8f905d0d00c7a14d74749c080223e7c 100644
--- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
+++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
@@ -181,6 +181,10 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
return GetSelectionController()->GetCursorHandleNativeView();
}
+ ui::SelectionBound::Type GetSelectionHandle1Type() {
+ return GetSelectionController()->GetSelectionHandle1Type();
+ }
+
gfx::Rect GetSelectionHandle1Bounds() {
return GetSelectionController()->GetSelectionHandle1Bounds();
}
@@ -269,6 +273,36 @@ class TouchSelectionControllerImplTest : public ViewsTestBase {
}
}
+ // Sets up a textfield with a long text string such that it doesn't all fit
+ // into the textfield. Then selects the text - the first handle is expected
+ // to be invisible. |selection_start| is the position of the first handle.
+ void SetupSelectionInvisibleHandle(uint32_t selection_start) {
+ // Create a textfield with lots of text in it.
+ CreateTextfield();
+ std::string some_text("some text");
+ std::string textfield_text;
+ for (int i = 0; i < 10; ++i)
+ textfield_text += some_text;
+ textfield_->SetText(ASCIIToUTF16(textfield_text));
+
+ // Tap the textfield to invoke selection.
+ ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
+ details.set_tap_count(1);
+ ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
+ textfield_->OnGestureEvent(&tap);
+
+ // Select some text such that one handle is hidden.
+ textfield_->SelectRange(gfx::Range(
+ selection_start, static_cast<uint32_t>(textfield_text.length())));
+
+ // Check that one selection handle is hidden.
+ EXPECT_FALSE(IsSelectionHandle1Visible());
+ EXPECT_TRUE(IsSelectionHandle2Visible());
+ EXPECT_EQ(gfx::Range(selection_start,
+ static_cast<uint32_t>(textfield_text.length())),
+ textfield_->GetSelectedRange());
+ }
+
Widget* textfield_widget_;
Widget* widget_;
@@ -539,29 +573,8 @@ TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
TEST_F(TouchSelectionControllerImplTest,
HiddenSelectionHandleRetainsCursorPosition) {
- // Create a textfield with lots of text in it.
- CreateTextfield();
- std::string textfield_text("some text");
- for (int i = 0; i < 10; ++i)
- textfield_text += textfield_text;
- textfield_->SetText(ASCIIToUTF16(textfield_text));
-
- // Tap the textfield to invoke selection.
- ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
- details.set_tap_count(1);
- ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
- textfield_->OnGestureEvent(&tap);
-
- // Select some text such that one handle is hidden.
- textfield_->SelectRange(
- gfx::Range(10u, static_cast<uint32_t>(textfield_text.length())));
-
- // Check that one selection handle is hidden.
- EXPECT_FALSE(IsSelectionHandle1Visible());
- EXPECT_TRUE(IsSelectionHandle2Visible());
- EXPECT_EQ(
- gfx::Range(10u, static_cast<uint32_t>(textfield_text.length())),
- textfield_->GetSelectedRange());
+ static const uint32_t selection_start = 10u;
+ SetupSelectionInvisibleHandle(selection_start);
// Drag the visible handle around and make sure the selection end point of the
// invisible handle does not change.
@@ -576,6 +589,24 @@ TEST_F(TouchSelectionControllerImplTest,
}
}
+// Tests that we can handle the hidden handle getting exposed as a result of a
+// drag and that it maintains the correct orientation when exposed.
+TEST_F(TouchSelectionControllerImplTest, HiddenSelectionHandleExposed) {
+ static const uint32_t selection_start = 0u;
+ SetupSelectionInvisibleHandle(selection_start);
+
+ // Drag the handle until the selection shrinks such that the other handle
+ // becomes visible.
+ while (!IsSelectionHandle1Visible()) {
+ static const int drag_diff = -10;
+ SimulateSelectionHandleDrag(gfx::Vector2d(drag_diff, 0), 2);
+ }
+
+ // Confirm that the exposed handle maintains the LEFT orientation
+ // (and does not reset to ui::SelectionBound::Type::CENTER).
+ EXPECT_EQ(ui::SelectionBound::Type::LEFT, GetSelectionHandle1Type());
+}
+
TEST_F(TouchSelectionControllerImplTest,
DoubleTapInTextfieldWithCursorHandleShouldSelectText) {
CreateTextfield();
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698