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

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: Fix gesture recognizer tests 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 unified diff | Download patch
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 }; 282 };
283 283
284 // Tests that the selection handles are placed appropriately when selection in 284 // Tests that the selection handles are placed appropriately when selection in
285 // a Textfield changes. 285 // a Textfield changes.
286 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { 286 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) {
287 CreateTextfield(); 287 CreateTextfield();
288 textfield_->SetText(ASCIIToUTF16("some text")); 288 textfield_->SetText(ASCIIToUTF16("some text"));
289 // Tap the textfield to invoke touch selection. 289 // Tap the textfield to invoke touch selection.
290 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 290 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
291 details.set_tap_count(1); 291 details.set_tap_count(1);
292 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 292 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
293 textfield_->OnGestureEvent(&tap); 293 textfield_->OnGestureEvent(&tap);
294 294
295 // Test selecting a range. 295 // Test selecting a range.
296 textfield_->SelectRange(gfx::Range(3, 7)); 296 textfield_->SelectRange(gfx::Range(3, 7));
297 VerifyHandlePositions(false, true, FROM_HERE); 297 VerifyHandlePositions(false, true, FROM_HERE);
298 298
299 // Test selecting everything. 299 // Test selecting everything.
300 textfield_->SelectAll(false); 300 textfield_->SelectAll(false);
301 VerifyHandlePositions(false, true, FROM_HERE); 301 VerifyHandlePositions(false, true, FROM_HERE);
302 302
(...skipping 12 matching lines...) Expand all
315 VerifyHandlePositions(false, true, FROM_HERE); 315 VerifyHandlePositions(false, true, FROM_HERE);
316 } 316 }
317 317
318 // Tests that the selection handles are placed appropriately in bidi text. 318 // Tests that the selection handles are placed appropriately in bidi text.
319 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { 319 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) {
320 CreateTextfield(); 320 CreateTextfield();
321 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 321 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
322 // Tap the textfield to invoke touch selection. 322 // Tap the textfield to invoke touch selection.
323 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 323 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
324 details.set_tap_count(1); 324 details.set_tap_count(1);
325 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 325 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
326 textfield_->OnGestureEvent(&tap); 326 textfield_->OnGestureEvent(&tap);
327 327
328 // Test cursor at run boundary and with empty selection. 328 // Test cursor at run boundary and with empty selection.
329 textfield_->SelectSelectionModel( 329 textfield_->SelectSelectionModel(
330 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD)); 330 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD));
331 VerifyHandlePositions(false, true, FROM_HERE); 331 VerifyHandlePositions(false, true, FROM_HERE);
332 332
333 // Test selection range inside one run and starts or ends at run boundary. 333 // Test selection range inside one run and starts or ends at run boundary.
334 textfield_->SelectRange(gfx::Range(2, 3)); 334 textfield_->SelectRange(gfx::Range(2, 3));
335 VerifyHandlePositions(false, true, FROM_HERE); 335 VerifyHandlePositions(false, true, FROM_HERE);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 367 }
368 368
369 // Tests if the SelectRect callback is called appropriately when selection 369 // Tests if the SelectRect callback is called appropriately when selection
370 // handles are moved. 370 // handles are moved.
371 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { 371 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) {
372 CreateTextfield(); 372 CreateTextfield();
373 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); 373 textfield_->SetText(ASCIIToUTF16("textfield with selected text"));
374 // Tap the textfield to invoke touch selection. 374 // Tap the textfield to invoke touch selection.
375 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 375 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
376 details.set_tap_count(1); 376 details.set_tap_count(1);
377 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 377 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
378 textfield_->OnGestureEvent(&tap); 378 textfield_->OnGestureEvent(&tap);
379 textfield_->SelectRange(gfx::Range(3, 7)); 379 textfield_->SelectRange(gfx::Range(3, 7));
380 380
381 gfx::Point textfield_origin; 381 gfx::Point textfield_origin;
382 textfield_->ConvertPointToScreen(&textfield_origin); 382 textfield_->ConvertPointToScreen(&textfield_origin);
383 383
384 EXPECT_EQ("tfie", UTF16ToUTF8(textfield_->GetSelectedText())); 384 EXPECT_EQ("tfie", UTF16ToUTF8(textfield_->GetSelectedText()));
385 VerifyHandlePositions(false, true, FROM_HERE); 385 VerifyHandlePositions(false, true, FROM_HERE);
386 386
387 // Drag selection handle 2 to right by 3 chars. 387 // Drag selection handle 2 to right by 3 chars.
(...skipping 21 matching lines...) Expand all
409 EXPECT_EQ("selected ", UTF16ToUTF8(textfield_->GetSelectedText())); 409 EXPECT_EQ("selected ", UTF16ToUTF8(textfield_->GetSelectedText()));
410 VerifyHandlePositions(false, true, FROM_HERE); 410 VerifyHandlePositions(false, true, FROM_HERE);
411 } 411 }
412 412
413 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { 413 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
414 CreateTextfield(); 414 CreateTextfield();
415 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); 415 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def"));
416 // Tap the textfield to invoke touch selection. 416 // Tap the textfield to invoke touch selection.
417 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 417 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
418 details.set_tap_count(1); 418 details.set_tap_count(1);
419 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 419 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
420 textfield_->OnGestureEvent(&tap); 420 textfield_->OnGestureEvent(&tap);
421 421
422 // Select [c] from left to right. 422 // Select [c] from left to right.
423 textfield_->SelectRange(gfx::Range(2, 3)); 423 textfield_->SelectRange(gfx::Range(2, 3));
424 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); 424 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText());
425 VerifyHandlePositions(false, true, FROM_HERE); 425 VerifyHandlePositions(false, true, FROM_HERE);
426 426
427 // Drag selection handle 2 to right by 1 char. 427 // Drag selection handle 2 to right by 1 char.
428 const gfx::FontList& font_list = textfield_->GetFontList(); 428 const gfx::FontList& font_list = textfield_->GetFontList();
429 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list); 429 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // Create a textfield with lots of text in it. 542 // Create a textfield with lots of text in it.
543 CreateTextfield(); 543 CreateTextfield();
544 std::string textfield_text("some text"); 544 std::string textfield_text("some text");
545 for (int i = 0; i < 10; ++i) 545 for (int i = 0; i < 10; ++i)
546 textfield_text += textfield_text; 546 textfield_text += textfield_text;
547 textfield_->SetText(ASCIIToUTF16(textfield_text)); 547 textfield_->SetText(ASCIIToUTF16(textfield_text));
548 548
549 // Tap the textfield to invoke selection. 549 // Tap the textfield to invoke selection.
550 ui::GestureEventDetails details(ui::ET_GESTURE_TAP); 550 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
551 details.set_tap_count(1); 551 details.set_tap_count(1);
552 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details); 552 ui::GestureEvent tap(0, 0, 0, base::TimeTicks(), details);
553 textfield_->OnGestureEvent(&tap); 553 textfield_->OnGestureEvent(&tap);
554 554
555 // Select some text such that one handle is hidden. 555 // Select some text such that one handle is hidden.
556 textfield_->SelectRange( 556 textfield_->SelectRange(
557 gfx::Range(10u, static_cast<uint32_t>(textfield_text.length()))); 557 gfx::Range(10u, static_cast<uint32_t>(textfield_text.length())));
558 558
559 // Check that one selection handle is hidden. 559 // Check that one selection handle is hidden.
560 EXPECT_FALSE(IsSelectionHandle1Visible()); 560 EXPECT_FALSE(IsSelectionHandle1Visible());
561 EXPECT_TRUE(IsSelectionHandle2Visible()); 561 EXPECT_TRUE(IsSelectionHandle2Visible());
562 EXPECT_EQ( 562 EXPECT_EQ(
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 813
814 ui::test::EventGenerator generator( 814 ui::test::EventGenerator generator(
815 textfield_widget_->GetNativeView()->GetRootWindow()); 815 textfield_widget_->GetNativeView()->GetRootWindow());
816 RunPendingMessages(); 816 RunPendingMessages();
817 817
818 // Start touch editing; then generate a mouse-capture-changed event and ensure 818 // Start touch editing; then generate a mouse-capture-changed event and ensure
819 // it does not deactivate touch selection. 819 // it does not deactivate touch selection.
820 StartTouchEditing(); 820 StartTouchEditing();
821 EXPECT_TRUE(GetSelectionController()); 821 EXPECT_TRUE(GetSelectionController());
822 ui::MouseEvent capture_changed(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(5, 5), 822 ui::MouseEvent capture_changed(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(5, 5),
823 gfx::Point(5, 5), base::TimeDelta(), 0, 0); 823 gfx::Point(5, 5), base::TimeTicks(), 0, 0);
824 generator.Dispatch(&capture_changed); 824 generator.Dispatch(&capture_changed);
825 RunPendingMessages(); 825 RunPendingMessages();
826 EXPECT_TRUE(GetSelectionController()); 826 EXPECT_TRUE(GetSelectionController());
827 } 827 }
828 828
829 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) { 829 TEST_F(TouchSelectionControllerImplTest, KeyEventDeactivatesTouchSelection) {
830 CreateTextfield(); 830 CreateTextfield();
831 EXPECT_FALSE(GetSelectionController()); 831 EXPECT_FALSE(GetSelectionController());
832 832
833 ui::test::EventGenerator generator( 833 ui::test::EventGenerator generator(
834 textfield_widget_->GetNativeView()->GetRootWindow()); 834 textfield_widget_->GetNativeView()->GetRootWindow());
835 835
836 RunPendingMessages(); 836 RunPendingMessages();
837 837
838 // Start touch editing; then press a key and ensure it deactivates touch 838 // Start touch editing; then press a key and ensure it deactivates touch
839 // selection. 839 // selection.
840 StartTouchEditing(); 840 StartTouchEditing();
841 EXPECT_TRUE(GetSelectionController()); 841 EXPECT_TRUE(GetSelectionController());
842 generator.PressKey(ui::VKEY_A, 0); 842 generator.PressKey(ui::VKEY_A, 0);
843 RunPendingMessages(); 843 RunPendingMessages();
844 EXPECT_FALSE(GetSelectionController()); 844 EXPECT_FALSE(GetSelectionController());
845 } 845 }
846 846
847 } // namespace views 847 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698