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

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

Issue 565583005: Clean up GestureEventDetails constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload to the most recent patch Created 6 years, 3 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "ui/aura/client/screen_position_client.h" 7 #include "ui/aura/client/screen_position_client.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/base/touch/touch_editing_controller.h" 10 #include "ui/base/touch/touch_editing_controller.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EXPECT_EQ(ch_pos, cursor_pos); \ 245 EXPECT_EQ(ch_pos, cursor_pos); \
246 } \ 246 } \
247 } 247 }
248 248
249 // Tests that the selection handles are placed appropriately when selection in 249 // Tests that the selection handles are placed appropriately when selection in
250 // a Textfield changes. 250 // a Textfield changes.
251 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) { 251 TEST_F(TouchSelectionControllerImplTest, SelectionInTextfieldTest) {
252 CreateTextfield(); 252 CreateTextfield();
253 textfield_->SetText(ASCIIToUTF16("some text")); 253 textfield_->SetText(ASCIIToUTF16("some text"));
254 // Tap the textfield to invoke touch selection. 254 // Tap the textfield to invoke touch selection.
255 ui::GestureEvent tap(0, 255 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
256 0, 256 details.set_tap_count(1);
257 0, 257 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
258 base::TimeDelta(),
259 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f));
260 textfield_->OnGestureEvent(&tap); 258 textfield_->OnGestureEvent(&tap);
261 259
262 // Test selecting a range. 260 // Test selecting a range.
263 textfield_->SelectRange(gfx::Range(3, 7)); 261 textfield_->SelectRange(gfx::Range(3, 7));
264 VERIFY_HANDLE_POSITIONS(false); 262 VERIFY_HANDLE_POSITIONS(false);
265 263
266 // Test selecting everything. 264 // Test selecting everything.
267 textfield_->SelectAll(false); 265 textfield_->SelectAll(false);
268 VERIFY_HANDLE_POSITIONS(false); 266 VERIFY_HANDLE_POSITIONS(false);
269 267
(...skipping 10 matching lines...) Expand all
280 EXPECT_FALSE(GetSelectionController()); 278 EXPECT_FALSE(GetSelectionController());
281 textfield_->OnGestureEvent(&tap); 279 textfield_->OnGestureEvent(&tap);
282 VERIFY_HANDLE_POSITIONS(false); 280 VERIFY_HANDLE_POSITIONS(false);
283 } 281 }
284 282
285 // Tests that the selection handles are placed appropriately in bidi text. 283 // Tests that the selection handles are placed appropriately in bidi text.
286 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) { 284 TEST_F(TouchSelectionControllerImplTest, SelectionInBidiTextfieldTest) {
287 CreateTextfield(); 285 CreateTextfield();
288 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2")); 286 textfield_->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
289 // Tap the textfield to invoke touch selection. 287 // Tap the textfield to invoke touch selection.
290 ui::GestureEvent tap(0, 288 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
291 0, 289 details.set_tap_count(1);
292 0, 290 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
293 base::TimeDelta(),
294 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f));
295 textfield_->OnGestureEvent(&tap); 291 textfield_->OnGestureEvent(&tap);
296 292
297 // Test cursor at run boundary and with empty selection. 293 // Test cursor at run boundary and with empty selection.
298 textfield_->SelectSelectionModel( 294 textfield_->SelectSelectionModel(
299 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD)); 295 gfx::SelectionModel(3, gfx::CURSOR_BACKWARD));
300 VERIFY_HANDLE_POSITIONS(false); 296 VERIFY_HANDLE_POSITIONS(false);
301 297
302 // Test selection range inside one run and starts or ends at run boundary. 298 // Test selection range inside one run and starts or ends at run boundary.
303 textfield_->SelectRange(gfx::Range(2, 3)); 299 textfield_->SelectRange(gfx::Range(2, 3));
304 VERIFY_HANDLE_POSITIONS(false); 300 VERIFY_HANDLE_POSITIONS(false);
(...skipping 26 matching lines...) Expand all
331 textfield_->SelectRange(gfx::Range(4, 1)); 327 textfield_->SelectRange(gfx::Range(4, 1));
332 VERIFY_HANDLE_POSITIONS(false); 328 VERIFY_HANDLE_POSITIONS(false);
333 } 329 }
334 330
335 // Tests if the SelectRect callback is called appropriately when selection 331 // Tests if the SelectRect callback is called appropriately when selection
336 // handles are moved. 332 // handles are moved.
337 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) { 333 TEST_F(TouchSelectionControllerImplTest, SelectRectCallbackTest) {
338 CreateTextfield(); 334 CreateTextfield();
339 textfield_->SetText(ASCIIToUTF16("textfield with selected text")); 335 textfield_->SetText(ASCIIToUTF16("textfield with selected text"));
340 // Tap the textfield to invoke touch selection. 336 // Tap the textfield to invoke touch selection.
341 ui::GestureEvent tap(0, 337 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
342 0, 338 details.set_tap_count(1);
343 0, 339 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
344 base::TimeDelta(),
345 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f));
346 textfield_->OnGestureEvent(&tap); 340 textfield_->OnGestureEvent(&tap);
347 textfield_->SelectRange(gfx::Range(3, 7)); 341 textfield_->SelectRange(gfx::Range(3, 7));
348 342
349 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); 343 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie");
350 VERIFY_HANDLE_POSITIONS(false); 344 VERIFY_HANDLE_POSITIONS(false);
351 345
352 // Drag selection handle 2 to right by 3 chars. 346 // Drag selection handle 2 to right by 3 chars.
353 const gfx::FontList& font_list = textfield_->GetFontList(); 347 const gfx::FontList& font_list = textfield_->GetFontList();
354 int x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("ld "), font_list); 348 int x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("ld "), font_list);
355 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 349 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
(...skipping 16 matching lines...) Expand all
372 x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("with selected "), font_list); 366 x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("with selected "), font_list);
373 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 367 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
374 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); 368 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected ");
375 VERIFY_HANDLE_POSITIONS(false); 369 VERIFY_HANDLE_POSITIONS(false);
376 } 370 }
377 371
378 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { 372 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
379 CreateTextfield(); 373 CreateTextfield();
380 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); 374 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def"));
381 // Tap the textfield to invoke touch selection. 375 // Tap the textfield to invoke touch selection.
382 ui::GestureEvent tap(0, 376 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
383 0, 377 details.set_tap_count(1);
384 0, 378 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
385 base::TimeDelta(),
386 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f));
387 textfield_->OnGestureEvent(&tap); 379 textfield_->OnGestureEvent(&tap);
388 380
389 // Select [c] from left to right. 381 // Select [c] from left to right.
390 textfield_->SelectRange(gfx::Range(2, 3)); 382 textfield_->SelectRange(gfx::Range(2, 3));
391 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); 383 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText());
392 VERIFY_HANDLE_POSITIONS(false); 384 VERIFY_HANDLE_POSITIONS(false);
393 385
394 // Drag selection handle 2 to right by 1 char. 386 // Drag selection handle 2 to right by 1 char.
395 const gfx::FontList& font_list = textfield_->GetFontList(); 387 const gfx::FontList& font_list = textfield_->GetFontList();
396 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list); 388 int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 TEST_F(TouchSelectionControllerImplTest, 496 TEST_F(TouchSelectionControllerImplTest,
505 HiddenSelectionHandleRetainsCursorPosition) { 497 HiddenSelectionHandleRetainsCursorPosition) {
506 // Create a textfield with lots of text in it. 498 // Create a textfield with lots of text in it.
507 CreateTextfield(); 499 CreateTextfield();
508 std::string textfield_text("some text"); 500 std::string textfield_text("some text");
509 for (int i = 0; i < 10; ++i) 501 for (int i = 0; i < 10; ++i)
510 textfield_text += textfield_text; 502 textfield_text += textfield_text;
511 textfield_->SetText(ASCIIToUTF16(textfield_text)); 503 textfield_->SetText(ASCIIToUTF16(textfield_text));
512 504
513 // Tap the textfield to invoke selection. 505 // Tap the textfield to invoke selection.
514 ui::GestureEvent tap(0, 506 ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
515 0, 507 details.set_tap_count(1);
516 0, 508 ui::GestureEvent tap(0, 0, 0, base::TimeDelta(), details);
517 base::TimeDelta(),
518 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f));
519 textfield_->OnGestureEvent(&tap); 509 textfield_->OnGestureEvent(&tap);
520 510
521 // Select some text such that one handle is hidden. 511 // Select some text such that one handle is hidden.
522 textfield_->SelectRange(gfx::Range(10, textfield_text.length())); 512 textfield_->SelectRange(gfx::Range(10, textfield_text.length()));
523 513
524 // Check that one selection handle is hidden. 514 // Check that one selection handle is hidden.
525 EXPECT_FALSE(IsSelectionHandle1Visible()); 515 EXPECT_FALSE(IsSelectionHandle1Visible());
526 EXPECT_TRUE(IsSelectionHandle2Visible()); 516 EXPECT_TRUE(IsSelectionHandle2Visible());
527 EXPECT_EQ(gfx::Range(10, textfield_text.length()), 517 EXPECT_EQ(gfx::Range(10, textfield_text.length()),
528 textfield_->GetSelectedRange()); 518 textfield_->GetSelectedRange());
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 // Start touch editing; then press a key and ensure it deactivates touch 843 // Start touch editing; then press a key and ensure it deactivates touch
854 // selection. 844 // selection.
855 StartTouchEditing(); 845 StartTouchEditing();
856 EXPECT_TRUE(GetSelectionController()); 846 EXPECT_TRUE(GetSelectionController());
857 generator.PressKey(ui::VKEY_A, 0); 847 generator.PressKey(ui::VKEY_A, 0);
858 RunPendingMessages(); 848 RunPendingMessages();
859 EXPECT_FALSE(GetSelectionController()); 849 EXPECT_FALSE(GetSelectionController());
860 } 850 }
861 851
862 } // namespace views 852 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/desktop_capture_controller_unittest.cc ('k') | ui/views/view_targeter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698