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

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

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