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

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

Issue 19666006: Supports FontList in Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removes ResourceBundle::Delegate::GetFontList. Created 7 years, 4 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 | Annotate | Revision Log
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 "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "ui/base/resource/resource_bundle.h" 8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/base/touch/touch_editing_controller.h" 9 #include "ui/base/touch/touch_editing_controller.h"
10 #include "ui/base/ui_base_switches.h" 10 #include "ui/base/ui_base_switches.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Tap the textfield to invoke touch selection. 277 // Tap the textfield to invoke touch selection.
278 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), 278 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
279 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); 279 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
280 textfield_view_->OnGestureEvent(&tap); 280 textfield_view_->OnGestureEvent(&tap);
281 textfield_->SelectRange(ui::Range(3, 7)); 281 textfield_->SelectRange(ui::Range(3, 7));
282 282
283 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie"); 283 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie");
284 VERIFY_HANDLE_POSITIONS(false); 284 VERIFY_HANDLE_POSITIONS(false);
285 285
286 // Drag selection handle 2 to right by 3 chars. 286 // Drag selection handle 2 to right by 3 chars.
287 int x = textfield_->font().GetStringWidth(ASCIIToUTF16("ld ")); 287 const gfx::Font& font = textfield_->GetPrimaryFont();
288 int x = font.GetStringWidth(ASCIIToUTF16("ld "));
288 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 289 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
289 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield "); 290 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield ");
290 VERIFY_HANDLE_POSITIONS(false); 291 VERIFY_HANDLE_POSITIONS(false);
291 292
292 // Drag selection handle 1 to the left by a large amount (selection should 293 // Drag selection handle 1 to the left by a large amount (selection should
293 // just stick to the beginning of the textfield). 294 // just stick to the beginning of the textfield).
294 SimulateSelectionHandleDrag(gfx::Point(-50, 0), 1); 295 SimulateSelectionHandleDrag(gfx::Point(-50, 0), 1);
295 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "textfield "); 296 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "textfield ");
296 VERIFY_HANDLE_POSITIONS(true); 297 VERIFY_HANDLE_POSITIONS(true);
297 298
298 // Drag selection handle 1 across selection handle 2. 299 // Drag selection handle 1 across selection handle 2.
299 x = textfield_->font().GetStringWidth(ASCIIToUTF16("textfield with ")); 300 x = font.GetStringWidth(ASCIIToUTF16("textfield with "));
300 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); 301 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
301 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with "); 302 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with ");
302 VERIFY_HANDLE_POSITIONS(true); 303 VERIFY_HANDLE_POSITIONS(true);
303 304
304 // Drag selection handle 2 across selection handle 1. 305 // Drag selection handle 2 across selection handle 1.
305 x = textfield_->font().GetStringWidth(ASCIIToUTF16("with selected ")); 306 x = font.GetStringWidth(ASCIIToUTF16("with selected "));
306 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 307 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
307 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); 308 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected ");
308 VERIFY_HANDLE_POSITIONS(false); 309 VERIFY_HANDLE_POSITIONS(false);
309 } 310 }
310 311
311 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) { 312 TEST_F(TouchSelectionControllerImplTest, SelectRectInBidiCallbackTest) {
312 CreateTextfield(); 313 CreateTextfield();
313 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def")); 314 textfield_->SetText(WideToUTF16(L"abc\x05e1\x05e2\x05e3" L"def"));
314 // Tap the textfield to invoke touch selection. 315 // Tap the textfield to invoke touch selection.
315 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(), 316 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
316 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0); 317 ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
317 textfield_view_->OnGestureEvent(&tap); 318 textfield_view_->OnGestureEvent(&tap);
318 319
319 // Select [c] from left to right. 320 // Select [c] from left to right.
320 textfield_->SelectRange(ui::Range(2, 3)); 321 textfield_->SelectRange(ui::Range(2, 3));
321 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); 322 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText());
322 VERIFY_HANDLE_POSITIONS(false); 323 VERIFY_HANDLE_POSITIONS(false);
323 324
324 // Drag selection handle 2 to right by 1 char. 325 // Drag selection handle 2 to right by 1 char.
325 int x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e3")); 326 const gfx::Font& font = textfield_->GetPrimaryFont();
327 int x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
326 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 328 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
327 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); 329 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
328 VERIFY_HANDLE_POSITIONS(false); 330 VERIFY_HANDLE_POSITIONS(false);
329 331
330 // Drag selection handle 1 to left by 1 char. 332 // Drag selection handle 1 to left by 1 char.
331 x = textfield_->font().GetStringWidth(WideToUTF16(L"b")); 333 x = font.GetStringWidth(WideToUTF16(L"b"));
332 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); 334 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
333 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); 335 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
334 VERIFY_HANDLE_POSITIONS(true); 336 VERIFY_HANDLE_POSITIONS(true);
335 337
336 // Select [c] from right to left. 338 // Select [c] from right to left.
337 textfield_->SelectRange(ui::Range(3, 2)); 339 textfield_->SelectRange(ui::Range(3, 2));
338 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText()); 340 EXPECT_EQ(WideToUTF16(L"c"), textfield_->GetSelectedText());
339 VERIFY_HANDLE_POSITIONS(false); 341 VERIFY_HANDLE_POSITIONS(false);
340 342
341 // Drag selection handle 1 to right by 1 char. 343 // Drag selection handle 1 to right by 1 char.
342 x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e3")); 344 x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
343 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); 345 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
344 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); 346 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
345 VERIFY_HANDLE_POSITIONS(true); 347 VERIFY_HANDLE_POSITIONS(true);
346 348
347 // Drag selection handle 2 to left by 1 char. 349 // Drag selection handle 2 to left by 1 char.
348 x = textfield_->font().GetStringWidth(WideToUTF16(L"b")); 350 x = font.GetStringWidth(WideToUTF16(L"b"));
349 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); 351 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
350 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText()); 352 EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
351 VERIFY_HANDLE_POSITIONS(false); 353 VERIFY_HANDLE_POSITIONS(false);
352 354
353 // Select [\x5e1] from right to left. 355 // Select [\x5e1] from right to left.
354 textfield_->SelectRange(ui::Range(3, 4)); 356 textfield_->SelectRange(ui::Range(3, 4));
355 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); 357 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText());
356 VERIFY_HANDLE_POSITIONS(false); 358 VERIFY_HANDLE_POSITIONS(false);
357 359
358 /* TODO(xji): for bidi text "abcDEF" whose display is "abcFEDhij", when click 360 /* TODO(xji): for bidi text "abcDEF" whose display is "abcFEDhij", when click
359 right of 'D' and select [D] then move the left selection handle to left 361 right of 'D' and select [D] then move the left selection handle to left
360 by one character, it should select [ED], instead it selects [F]. 362 by one character, it should select [ED], instead it selects [F].
361 Reason: click right of 'D' and left of 'h' return the same x-axis position, 363 Reason: click right of 'D' and left of 'h' return the same x-axis position,
362 pass this position to FindCursorPosition() returns index of 'h'. which 364 pass this position to FindCursorPosition() returns index of 'h'. which
363 means the selection start changed from 3 to 6. 365 means the selection start changed from 3 to 6.
364 Need further investigation on whether this is a bug in Pango and how to 366 Need further investigation on whether this is a bug in Pango and how to
365 work around it. 367 work around it.
366 // Drag selection handle 2 to left by 1 char. 368 // Drag selection handle 2 to left by 1 char.
367 x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e2")); 369 x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
368 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); 370 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
369 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); 371 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
370 VERIFY_HANDLE_POSITIONS(false); 372 VERIFY_HANDLE_POSITIONS(false);
371 */ 373 */
372 374
373 // Drag selection handle 1 to right by 1 char. 375 // Drag selection handle 1 to right by 1 char.
374 x = textfield_->font().GetStringWidth(WideToUTF16(L"d")); 376 x = font.GetStringWidth(WideToUTF16(L"d"));
375 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); 377 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
376 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); 378 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
377 VERIFY_HANDLE_POSITIONS(true); 379 VERIFY_HANDLE_POSITIONS(true);
378 380
379 // Select [\x5e1] from left to right. 381 // Select [\x5e1] from left to right.
380 textfield_->SelectRange(ui::Range(4, 3)); 382 textfield_->SelectRange(ui::Range(4, 3));
381 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText()); 383 EXPECT_EQ(WideToUTF16(L"\x05e1"), textfield_->GetSelectedText());
382 VERIFY_HANDLE_POSITIONS(false); 384 VERIFY_HANDLE_POSITIONS(false);
383 385
384 /* TODO(xji): see detail of above commented out test case. 386 /* TODO(xji): see detail of above commented out test case.
385 // Drag selection handle 1 to left by 1 char. 387 // Drag selection handle 1 to left by 1 char.
386 x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e2")); 388 x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
387 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); 389 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
388 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText()); 390 EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
389 VERIFY_HANDLE_POSITIONS(true); 391 VERIFY_HANDLE_POSITIONS(true);
390 */ 392 */
391 393
392 // Drag selection handle 2 to right by 1 char. 394 // Drag selection handle 2 to right by 1 char.
393 x = textfield_->font().GetStringWidth(WideToUTF16(L"d")); 395 x = font.GetStringWidth(WideToUTF16(L"d"));
394 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 396 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
395 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText()); 397 EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
396 VERIFY_HANDLE_POSITIONS(false); 398 VERIFY_HANDLE_POSITIONS(false);
397 399
398 // Select [\x05r3] from right to left. 400 // Select [\x05r3] from right to left.
399 textfield_->SelectRange(ui::Range(5, 6)); 401 textfield_->SelectRange(ui::Range(5, 6));
400 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); 402 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText());
401 VERIFY_HANDLE_POSITIONS(false); 403 VERIFY_HANDLE_POSITIONS(false);
402 404
403 // Drag selection handle 2 to left by 1 char. 405 // Drag selection handle 2 to left by 1 char.
404 x = textfield_->font().GetStringWidth(WideToUTF16(L"c")); 406 x = font.GetStringWidth(WideToUTF16(L"c"));
405 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2); 407 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
406 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); 408 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
407 VERIFY_HANDLE_POSITIONS(false); 409 VERIFY_HANDLE_POSITIONS(false);
408 410
409 // Drag selection handle 1 to right by 1 char. 411 // Drag selection handle 1 to right by 1 char.
410 x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e2")); 412 x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
411 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1); 413 SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
412 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); 414 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
413 VERIFY_HANDLE_POSITIONS(true); 415 VERIFY_HANDLE_POSITIONS(true);
414 416
415 // Select [\x05r3] from left to right. 417 // Select [\x05r3] from left to right.
416 textfield_->SelectRange(ui::Range(6, 5)); 418 textfield_->SelectRange(ui::Range(6, 5));
417 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText()); 419 EXPECT_EQ(WideToUTF16(L"\x05e3"), textfield_->GetSelectedText());
418 VERIFY_HANDLE_POSITIONS(false); 420 VERIFY_HANDLE_POSITIONS(false);
419 421
420 // Drag selection handle 1 to left by 1 char. 422 // Drag selection handle 1 to left by 1 char.
421 x = textfield_->font().GetStringWidth(WideToUTF16(L"c")); 423 x = font.GetStringWidth(WideToUTF16(L"c"));
422 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1); 424 SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
423 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText()); 425 EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
424 VERIFY_HANDLE_POSITIONS(true); 426 VERIFY_HANDLE_POSITIONS(true);
425 427
426 // Drag selection handle 2 to right by 1 char. 428 // Drag selection handle 2 to right by 1 char.
427 x = textfield_->font().GetStringWidth(WideToUTF16(L"\x05e2")); 429 x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
428 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); 430 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
429 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText()); 431 EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
430 VERIFY_HANDLE_POSITIONS(false); 432 VERIFY_HANDLE_POSITIONS(false);
431 } 433 }
432 434
433 TEST_F(TouchSelectionControllerImplTest, 435 TEST_F(TouchSelectionControllerImplTest,
434 HiddenSelectionHandleRetainsCursorPosition) { 436 HiddenSelectionHandleRetainsCursorPosition) {
435 // Create a textfield with lots of text in it. 437 // Create a textfield with lots of text in it.
436 CreateTextfield(); 438 CreateTextfield();
437 std::string textfield_text("some text"); 439 std::string textfield_text("some text");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 gfx::Point cursor_pos = GetCursorHandlePosition(); 488 gfx::Point cursor_pos = GetCursorHandlePosition();
487 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); 489 cursor_pos.Offset(GetHandleImageSize().width() / 2 + kPadding, 0);
488 generator.GestureTapAt(cursor_pos); 490 generator.GestureTapAt(cursor_pos);
489 generator.GestureTapAt(cursor_pos); 491 generator.GestureTapAt(cursor_pos);
490 EXPECT_TRUE(textfield_->HasSelection()); 492 EXPECT_TRUE(textfield_->HasSelection());
491 VERIFY_HANDLE_POSITIONS(false); 493 VERIFY_HANDLE_POSITIONS(false);
492 } 494 }
493 #endif 495 #endif
494 496
495 } // namespace views 497 } // namespace views
OLDNEW
« ui/base/resource/resource_bundle.cc ('K') | « ui/views/examples/multiline_example.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698