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

Side by Side Diff: ui/views/touchui/touch_selection_controller_impl_unittest.cc

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 unified diff | Download patch
« no previous file with comments | « ui/views/mus/window_manager_connection_unittest.cc ('k') | ui/views/view_targeter_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "ui/aura/client/screen_position_client.h" 10 #include "ui/aura/client/screen_position_client.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 void SimulateSelectionHandleDrag(gfx::Vector2d v, int selection_handle) { 146 void SimulateSelectionHandleDrag(gfx::Vector2d v, int selection_handle) {
147 TouchSelectionControllerImpl* controller = GetSelectionController(); 147 TouchSelectionControllerImpl* controller = GetSelectionController();
148 views::WidgetDelegateView* handle = nullptr; 148 views::WidgetDelegateView* handle = nullptr;
149 if (selection_handle == 1) 149 if (selection_handle == 1)
150 handle = controller->GetHandle1View(); 150 handle = controller->GetHandle1View();
151 else 151 else
152 handle = controller->GetHandle2View(); 152 handle = controller->GetHandle2View();
153 153
154 gfx::Point grip_location = gfx::Point(handle->size().width() / 2, 154 gfx::Point grip_location = gfx::Point(handle->size().width() / 2,
155 handle->size().height() / 2); 155 handle->size().height() / 2);
156 base::TimeDelta time_stamp = base::TimeDelta(); 156 base::TimeTicks time_stamp = base::TimeTicks();
157 { 157 {
158 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_BEGIN); 158 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_BEGIN);
159 ui::GestureEvent scroll_begin( 159 ui::GestureEvent scroll_begin(
160 grip_location.x(), grip_location.y(), 0, time_stamp, details); 160 grip_location.x(), grip_location.y(), 0, time_stamp, details);
161 handle->OnGestureEvent(&scroll_begin); 161 handle->OnGestureEvent(&scroll_begin);
162 } 162 }
163 test_cursor_client_->DisableMouseEvents(); 163 test_cursor_client_->DisableMouseEvents();
164 { 164 {
165 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE); 165 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE);
166 gfx::Point update_location = grip_location + v; 166 gfx::Point update_location = grip_location + v;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 CreateTextfield(); 281 CreateTextfield();
282 std::string some_text("some text"); 282 std::string some_text("some text");
283 std::string textfield_text; 283 std::string textfield_text;
284 for (int i = 0; i < 10; ++i) 284 for (int i = 0; i < 10; ++i)
285 textfield_text += some_text; 285 textfield_text += some_text;
286 textfield_->SetText(ASCIIToUTF16(textfield_text)); 286 textfield_->SetText(ASCIIToUTF16(textfield_text));
287 287
288 // Tap the textfield to invoke selection. 288 // Tap the textfield to invoke selection.
289 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 289 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
290 details.set_tap_count(1); 290 details.set_tap_count(1);
291 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 291 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
292 textfield_->OnGestureEvent(&tap); 292 textfield_->OnGestureEvent(&tap);
293 293
294 // Select some text such that one handle is hidden. 294 // Select some text such that one handle is hidden.
295 textfield_->SelectRange(gfx::Range( 295 textfield_->SelectRange(gfx::Range(
296 selection_start, static_cast<uint32_t>(textfield_text.length()))); 296 selection_start, static_cast<uint32_t>(textfield_text.length())));
297 297
298 // Check that one selection handle is hidden. 298 // Check that one selection handle is hidden.
299 EXPECT_FALSE(IsSelectionHandle1Visible()); 299 EXPECT_FALSE(IsSelectionHandle1Visible());
300 EXPECT_TRUE(IsSelectionHandle2Visible()); 300 EXPECT_TRUE(IsSelectionHandle2Visible());
301 EXPECT_EQ(gfx::Range(selection_start, 301 EXPECT_EQ(gfx::Range(selection_start,
(...skipping 14 matching lines...) Expand all
316 }; 316 };
317 317
318 // Tests that the selection handles are placed appropriately when selection in 318 // Tests that the selection handles are placed appropriately when selection in
319 // a Textfield changes. 319 // a Textfield changes.
320 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { 320 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) {
321 CreateTextfield(); 321 CreateTextfield();
322 textfield_->SetText(ASCIIToUTF16("some text")); 322 textfield_->SetText(ASCIIToUTF16("some text"));
323 // Tap the textfield to invoke touch selection. 323 // Tap the textfield to invoke touch selection.
324 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 324 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
325 details.set_tap_count(1); 325 details.set_tap_count(1);
326 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 326 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
327 textfield_->OnGestureEvent(&tap); 327 textfield_->OnGestureEvent(&tap);
328 328
329 // Test selecting a range. 329 // Test selecting a range.
330 textfield_->SelectRange(gfx::Range(3, 7)); 330 textfield_->SelectRange(gfx::Range(3, 7));
331 VerifyHandlePositions(false, true, FROM_HERE); 331 VerifyHandlePositions(false, true, FROM_HERE);
332 332
333 // Test selecting everything. 333 // Test selecting everything.
334 textfield_->SelectAll(false); 334 textfield_->SelectAll(false);
335 VerifyHandlePositions(false, true, FROM_HERE); 335 VerifyHandlePositions(false, true, FROM_HERE);
336 336
(...skipping 12 matching lines...) Expand all
349 VerifyHandlePositions(false, true, FROM_HERE); 349 VerifyHandlePositions(false, true, FROM_HERE);
350 } 350 }
351 351
352 // Tests that the selection handles are placed appropriately in bidi text. 352 // Tests that the selection handles are placed appropriately in bidi text.
353 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { 353 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) {
354 CreateTextfield(); 354 CreateTextfield();
355 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 355 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
356 // Tap the textfield to invoke touch selection. 356 // Tap the textfield to invoke touch selection.
357 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 357 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
358 details.set_tap_count(1); 358 details.set_tap_count(1);
359 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 359 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
360 textfield_->OnGestureEvent(&tap); 360 textfield_->OnGestureEvent(&tap);
361 361
362 // Test cursor at run boundary and with empty selection. 362 // Test cursor at run boundary and with empty selection.
363 textfield_->SelectSelectionModel( 363 textfield_->SelectSelectionModel(
364 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD)); 364 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD));
365 VerifyHandlePositions(false, true, FROM_HERE); 365 VerifyHandlePositions(false, true, FROM_HERE);
366 366
367 // Test selection range inside one run and starts or ends at run boundary. 367 // Test selection range inside one run and starts or ends at run boundary.
368 textfield_->SelectRange(gfx::Range(2, 3)); 368 textfield_->SelectRange(gfx::Range(2, 3));
369 VerifyHandlePositions(false, true, FROM_HERE); 369 VerifyHandlePositions(false, true, FROM_HERE);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 401 }
402 402
403 // Tests if the SelectRect callback is called appropriately when selection 403 // Tests if the SelectRect callback is called appropriately when selection
404 // handles are moved. 404 // handles are moved.
405 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { 405 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) {
406 CreateTextfield(); 406 CreateTextfield();
407 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); 407 textfield_->SetText(ASCIIToUTF16("textfield with selected text"));
408 // Tap the textfield to invoke touch selection. 408 // Tap the textfield to invoke touch selection.
409 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 409 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
410 details.set_tap_count(1); 410 details.set_tap_count(1);
411 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 411 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
412 textfield_->OnGestureEvent(&tap); 412 textfield_->OnGestureEvent(&tap);
413 textfield_->SelectRange(gfx::Range(3, 7)); 413 textfield_->SelectRange(gfx::Range(3, 7));
414 414
415 gfx::Point textfield_origin; 415 gfx::Point textfield_origin;
416 textfield_->ConvertPointToScreen(&textfield_origin); 416 textfield_->ConvertPointToScreen(&textfield_origin);
417 417
418 EXPECT_EQ("tfie", UTF16ToUTF8(textfield_->GetSelectedText())); 418 EXPECT_EQ("tfie", UTF16ToUTF8(textfield_->GetSelectedText()));
419 VerifyHandlePositions(false, true, FROM_HERE); 419 VerifyHandlePositions(false, true, FROM_HERE);
420 420
421 // Drag selection handle 2 to right by 3 chars. 421 // Drag selection handle 2 to right by 3 chars.
(...skipping 21 matching lines...) Expand all
443 EXPECT_EQ("selected ", UTF16ToUTF8(textfield_->GetSelectedText())); 443 EXPECT_EQ("selected ", UTF16ToUTF8(textfield_->GetSelectedText()));
444 VerifyHandlePositions(false, true, FROM_HERE); 444 VerifyHandlePositions(false, true, FROM_HERE);
445 } 445 }
446 446
447 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { 447 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
448 CreateTextfield(); 448 CreateTextfield();
449 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); 449 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def"));
450 // Tap the textfield to invoke touch selection. 450 // Tap the textfield to invoke touch selection.
451 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 451 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
452 details.set_tap_count(1); 452 details.set_tap_count(1);
453 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 453 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
454 textfield_->OnGestureEvent(&tap); 454 textfield_->OnGestureEvent(&tap);
455 455
456 // Select [c] from left to right. 456 // Select [c] from left to right.
457 textfield_->SelectRange(gfx::Range(2, 3)); 457 textfield_->SelectRange(gfx::Range(2, 3));
458 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); 458 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText());
459 VerifyHandlePositions(false, true, FROM_HERE); 459 VerifyHandlePositions(false, true, FROM_HERE);
460 460
461 // Drag selection handle 2 to right by 1 char. 461 // Drag selection handle 2 to right by 1 char.
462 const gfx::FontList& font_list = textfield_->GetFontList(); 462 const gfx::FontList& font_list = textfield_->GetFontList();
463 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list); 463 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list); 568 x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
569 SimulateSelectionHandleDrag(gfx::Vector2d(x, 0), 2); 569 SimulateSelectionHandleDrag(gfx::Vector2d(x, 0), 2);
570 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); 570 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
571 VerifyHandlePositions(false, false, FROM_HERE); 571 VerifyHandlePositions(false, false, FROM_HERE);
572 } 572 }
573 573
574 TEST_F(TouchSelectionControllerImplTest, 574 TEST_F(TouchSelectionControllerImplTest,
575 HiddenSelectionHandleRetainsCursorPosition) { 575 HiddenSelectionHandleRetainsCursorPosition) {
576 static const uint32_t selection_start = 10u; 576 static const uint32_t selection_start = 10u;
577 SetupSelectionInvisibleHandle(selection_start); 577 SetupSelectionInvisibleHandle(selection_start);
578
579 // Drag the visible handle around and make sure the selection end point of the 578 // Drag the visible handle around and make sure the selection end point of the
580 // invisible handle does not change. 579 // invisible handle does not change.
581 size_t visible_handle_position = textfield_->GetSelectedRange().end(); 580 size_t visible_handle_position = textfield_->GetSelectedRange().end();
582 for (int i = 0; i < 10; ++i) { 581 for (int i = 0; i < 10; ++i) {
583 static const int drag_diff = -10; 582 static const int drag_diff = -10;
584 SimulateSelectionHandleDrag(gfx::Vector2d(drag_diff, 0), 2); 583 SimulateSelectionHandleDrag(gfx::Vector2d(drag_diff, 0), 2);
585 // Make sure that the visible handle is being dragged. 584 // Make sure that the visible handle is being dragged.
586 EXPECT_NE(visible_handle_position, textfield_->GetSelectedRange().end()); 585 EXPECT_NE(visible_handle_position, textfield_->GetSelectedRange().end());
587 visible_handle_position = textfield_->GetSelectedRange().end(); 586 visible_handle_position = textfield_->GetSelectedRange().end();
588 EXPECT_EQ((size_t) 10, textfield_->GetSelectedRange().start()); 587 EXPECT_EQ((size_t) 10, textfield_->GetSelectedRange().start());
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 843
845 ui::test::EventGenerator generator( 844 ui::test::EventGenerator generator(
846 textfield_widget_->GetNativeView()->GetRootWindow()); 845 textfield_widget_->GetNativeView()->GetRootWindow());
847 RunPendingMessages(); 846 RunPendingMessages();
848 847
849 // Start touch editing; then generate a mouse-capture-changed event and ensure 848 // Start touch editing; then generate a mouse-capture-changed event and ensure
850 // it does not deactivate touch selection. 849 // it does not deactivate touch selection.
851 StartTouchEditing(); 850 StartTouchEditing();
852 EXPECT_TRUE(GetSelectionController()); 851 EXPECT_TRUE(GetSelectionController());
853 ui::MouseEvent capture_changed(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(5, 5), 852 ui::MouseEvent capture_changed(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(5, 5),
854 gfx::Point(5, 5), base::TimeDelta(), 0, 0); 853 gfx::Point(5, 5), base::TimeTicks(), 0, 0);
855 generator.Dispatch(&capture_changed); 854 generator.Dispatch(&capture_changed);
856 RunPendingMessages(); 855 RunPendingMessages();
857 EXPECT_TRUE(GetSelectionController()); 856 EXPECT_TRUE(GetSelectionController());
858 } 857 }
859 858
860 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) { 859 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) {
861 CreateTextfield(); 860 CreateTextfield();
862 EXPECT_FALSE(GetSelectionController()); 861 EXPECT_FALSE(GetSelectionController());
863 862
864 ui::test::EventGenerator generator( 863 ui::test::EventGenerator generator(
865 textfield_widget_->GetNativeView()->GetRootWindow()); 864 textfield_widget_->GetNativeView()->GetRootWindow());
866 865
867 RunPendingMessages(); 866 RunPendingMessages();
868 867
869 // Start touch editing; then press a key and ensure it deactivates touch 868 // Start touch editing; then press a key and ensure it deactivates touch
870 // selection. 869 // selection.
871 StartTouchEditing(); 870 StartTouchEditing();
872 EXPECT_TRUE(GetSelectionController()); 871 EXPECT_TRUE(GetSelectionController());
873 generator.PressKey(ui::VKEY_A, 0); 872 generator.PressKey(ui::VKEY_A, 0);
874 RunPendingMessages(); 873 RunPendingMessages();
875 EXPECT_FALSE(GetSelectionController()); 874 EXPECT_FALSE(GetSelectionController());
876 } 875 }
877 876
878 } // namespace views 877 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/window_manager_connection_unittest.cc ('k') | ui/views/view_targeter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698