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

Side by Side Diff: ui/views/controls/textfield/textfield_unittest.cc

Issue 1865063004: views: support vertical-drag-to-end on textfields (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move logic into Textfield Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 TEST_F(TextfieldTest, DragUpOrDownSelectsToEnd) {
tapted 2016/04/08 08:53:28 nit: although the other tests are missing one,...
Elly Fong-Jones 2016/04/08 16:46:47 Done.
1200 if (!PlatformStyle::kTextfieldDragVerticallyDragsToEnd)
tapted 2016/04/08 08:53:28 Can we verify the behaviour when this is false as
Elly Fong-Jones 2016/04/08 16:46:48 Yes. I changed the test to test the correct behavi
1201 return;
1202 InitTextfield();
1203 textfield_->SetText(ASCIIToUTF16("hello world"));
1204 const int kStartX = GetCursorPositionX(5);
1205 gfx::Point start_point(kStartX, 0);
1206 gfx::Point down_point(kStartX, 500);
1207 gfx::Point up_point(kStartX, -500);
1208 ui::MouseEvent click_start(ui::ET_MOUSE_PRESSED, start_point, start_point,
tapted 2016/04/08 08:53:28 Can these be simplified with a ui::EventGenerator?
Elly Fong-Jones 2016/04/08 16:46:48 I spent a bit of time trying to use EventGenerator
1209 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1210 ui::EF_LEFT_MOUSE_BUTTON);
1211 ui::MouseEvent click_down(ui::ET_MOUSE_PRESSED, down_point, down_point,
1212 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1213 ui::EF_LEFT_MOUSE_BUTTON);
1214 ui::MouseEvent drag_up(ui::ET_MOUSE_DRAGGED, up_point, up_point,
1215 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1216 ui::MouseEvent drag_down(ui::ET_MOUSE_DRAGGED, down_point, down_point,
1217 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1218 ui::MouseEvent release_up(ui::ET_MOUSE_RELEASED, up_point, up_point,
1219 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1220 ui::EF_LEFT_MOUSE_BUTTON);
1221 ui::MouseEvent release_down(ui::ET_MOUSE_RELEASED, down_point, down_point,
1222 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
1223 ui::EF_LEFT_MOUSE_BUTTON);
1224
1225 textfield_->OnMousePressed(click_start);
1226 textfield_->OnMouseDragged(drag_up);
1227 textfield_->OnMouseReleased(release_up);
1228 EXPECT_EQ(textfield_->GetSelectedText(), base::ASCIIToUTF16("hello"));
1229
1230 textfield_->OnMousePressed(click_start);
1231 textfield_->OnMouseDragged(drag_down);
1232 textfield_->OnMouseReleased(release_down);
1233 EXPECT_EQ(textfield_->GetSelectedText(), base::ASCIIToUTF16(" world"));
1234 }
1235
1198 #if defined(OS_WIN) 1236 #if defined(OS_WIN)
1199 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) { 1237 TEST_F(TextfieldTest, DragAndDrop_AcceptDrop) {
1200 InitTextfield(); 1238 InitTextfield();
1201 textfield_->SetText(ASCIIToUTF16("hello world")); 1239 textfield_->SetText(ASCIIToUTF16("hello world"));
1202 1240
1203 ui::OSExchangeData data; 1241 ui::OSExchangeData data;
1204 base::string16 string(ASCIIToUTF16("string ")); 1242 base::string16 string(ASCIIToUTF16("string "));
1205 data.SetString(string); 1243 data.SetString(string);
1206 int formats = 0; 1244 int formats = 0;
1207 std::set<ui::Clipboard::FormatType> format_types; 1245 std::set<ui::Clipboard::FormatType> format_types;
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 2607
2570 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); 2608 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
2571 ui::AXViewState state_protected; 2609 ui::AXViewState state_protected;
2572 textfield_->GetAccessibleState(&state_protected); 2610 textfield_->GetAccessibleState(&state_protected);
2573 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); 2611 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role);
2574 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); 2612 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value);
2575 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); 2613 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED));
2576 } 2614 }
2577 2615
2578 } // namespace views 2616 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.cc ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698