| 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "ui/events/event_processor.h" | 32 #include "ui/events/event_processor.h" |
| 33 #include "ui/events/event_utils.h" | 33 #include "ui/events/event_utils.h" |
| 34 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
| 35 #include "ui/events/test/event_generator.h" | 35 #include "ui/events/test/event_generator.h" |
| 36 #include "ui/gfx/render_text.h" | 36 #include "ui/gfx/render_text.h" |
| 37 #include "ui/strings/grit/ui_strings.h" | 37 #include "ui/strings/grit/ui_strings.h" |
| 38 #include "ui/views/controls/textfield/textfield_controller.h" | 38 #include "ui/views/controls/textfield/textfield_controller.h" |
| 39 #include "ui/views/controls/textfield/textfield_model.h" | 39 #include "ui/views/controls/textfield/textfield_model.h" |
| 40 #include "ui/views/controls/textfield/textfield_test_api.h" | 40 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 41 #include "ui/views/focus/focus_manager.h" | 41 #include "ui/views/focus/focus_manager.h" |
| 42 #include "ui/views/style/platform_style.h" |
| 42 #include "ui/views/test/test_views_delegate.h" | 43 #include "ui/views/test/test_views_delegate.h" |
| 43 #include "ui/views/test/views_test_base.h" | 44 #include "ui/views/test/views_test_base.h" |
| 44 #include "ui/views/test/widget_test.h" | 45 #include "ui/views/test/widget_test.h" |
| 45 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
| 46 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| 47 | 48 |
| 48 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 49 #include "base/win/windows_version.h" | 50 #include "base/win/windows_version.h" |
| 50 #endif | 51 #endif |
| 51 | 52 |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 // Check that releasing in the same location does not alter the selection. | 1189 // Check that releasing in the same location does not alter the selection. |
| 1189 textfield_->OnMouseReleased(release); | 1190 textfield_->OnMouseReleased(release); |
| 1190 EXPECT_EQ(text_right, textfield_->GetSelectedText()); | 1191 EXPECT_EQ(text_right, textfield_->GetSelectedText()); |
| 1191 // Check that dragging from beyond the text length works too. | 1192 // Check that dragging from beyond the text length works too. |
| 1192 textfield_->OnMousePressed(click_b); | 1193 textfield_->OnMousePressed(click_b); |
| 1193 textfield_->OnMouseDragged(drag_left); | 1194 textfield_->OnMouseDragged(drag_left); |
| 1194 textfield_->OnMouseReleased(release); | 1195 textfield_->OnMouseReleased(release); |
| 1195 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); | 1196 EXPECT_EQ(textfield_->text(), textfield_->GetSelectedText()); |
| 1196 } | 1197 } |
| 1197 | 1198 |
| 1199 // This test checks that dragging above the textfield selects to the beginning |
| 1200 // and dragging below the textfield selects to the end, but only on platforms |
| 1201 // where that is the expected behavior. |
| 1202 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) { |
| 1203 InitTextfield(); |
| 1204 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1205 const base::string16 expected_up = |
| 1206 base::ASCIIToUTF16(PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? |
| 1207 "hello" : "lo"); |
| 1208 const base::string16 expected_down = |
| 1209 base::ASCIIToUTF16(PlatformStyle::kTextfieldDragVerticallyDragsToEnd ? |
| 1210 " world" : " w"); |
| 1211 const int kStartX = GetCursorPositionX(5); |
| 1212 const int kDownX = GetCursorPositionX(7); |
| 1213 const int kUpX = GetCursorPositionX(3); |
| 1214 gfx::Point start_point(kStartX, 0); |
| 1215 gfx::Point down_point(kDownX, 500); |
| 1216 gfx::Point up_point(kUpX, -500); |
| 1217 |
| 1218 ui::MouseEvent click_start(ui::ET_MOUSE_PRESSED, start_point, start_point, |
| 1219 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 1220 ui::EF_LEFT_MOUSE_BUTTON); |
| 1221 ui::MouseEvent click_down(ui::ET_MOUSE_PRESSED, down_point, down_point, |
| 1222 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 1223 ui::EF_LEFT_MOUSE_BUTTON); |
| 1224 ui::MouseEvent drag_up(ui::ET_MOUSE_DRAGGED, up_point, up_point, |
| 1225 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1226 ui::MouseEvent drag_down(ui::ET_MOUSE_DRAGGED, down_point, down_point, |
| 1227 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 1228 ui::MouseEvent release_up(ui::ET_MOUSE_RELEASED, up_point, up_point, |
| 1229 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 1230 ui::EF_LEFT_MOUSE_BUTTON); |
| 1231 ui::MouseEvent release_down(ui::ET_MOUSE_RELEASED, down_point, down_point, |
| 1232 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 1233 ui::EF_LEFT_MOUSE_BUTTON); |
| 1234 |
| 1235 textfield_->OnMousePressed(click_start); |
| 1236 textfield_->OnMouseDragged(drag_up); |
| 1237 textfield_->OnMouseReleased(release_up); |
| 1238 EXPECT_EQ(textfield_->GetSelectedText(), expected_up); |
| 1239 |
| 1240 textfield_->OnMousePressed(click_start); |
| 1241 textfield_->OnMouseDragged(drag_down); |
| 1242 textfield_->OnMouseReleased(release_down); |
| 1243 EXPECT_EQ(textfield_->GetSelectedText(), expected_down); |
| 1244 } |
| 1245 |
| 1198 #if defined(OS_WIN) | 1246 #if defined(OS_WIN) |
| 1199 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { | 1247 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { |
| 1200 InitTextfield(); | 1248 InitTextfield(); |
| 1201 textfield_->SetText(ASCIIToUTF16("hello world")); | 1249 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1202 | 1250 |
| 1203 ui::OSExchangeData data; | 1251 ui::OSExchangeData data; |
| 1204 base::string16 string(ASCIIToUTF16("string ")); | 1252 base::string16 string(ASCIIToUTF16("string ")); |
| 1205 data.SetString(string); | 1253 data.SetString(string); |
| 1206 int formats = 0; | 1254 int formats = 0; |
| 1207 std::set<ui::Clipboard::FormatType> format_types; | 1255 std::set<ui::Clipboard::FormatType> format_types; |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2569 | 2617 |
| 2570 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2618 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2571 ui::AXViewState state_protected; | 2619 ui::AXViewState state_protected; |
| 2572 textfield_->GetAccessibleState(&state_protected); | 2620 textfield_->GetAccessibleState(&state_protected); |
| 2573 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2621 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2574 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2622 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2575 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2623 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2576 } | 2624 } |
| 2577 | 2625 |
| 2578 } // namespace views | 2626 } // namespace views |
| OLD | NEW |