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

Side by Side Diff: ui/gfx/render_text_unittest.cc

Issue 10693061: Fix RenderTextWin base dir and adjacent char code; remove test exceptions; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert gypi change to keep Mac working. Created 8 years, 5 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
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/render_text_win.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 "ui/gfx/render_text.h" 5 #include "ui/gfx/render_text.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #endif 14 #endif
15 15
16 #if defined(TOOLKIT_GTK)
17 #include <gtk/gtk.h>
18 #endif
19
16 namespace gfx { 20 namespace gfx {
17 21
18 namespace { 22 namespace {
19 23
20 // Checks whether |range| contains |index|. This is not the same as calling 24 // Checks whether |range| contains |index|. This is not the same as calling
21 // |range.Contains(ui::Range(index))| - as that would return true when 25 // |range.Contains(ui::Range(index))| - as that would return true when
22 // |index| == |range.end()|. 26 // |index| == |range.end()|.
23 bool IndexInRange(const ui::Range& range, size_t index) { 27 bool IndexInRange(const ui::Range& range, size_t index) {
24 return index >= range.start() && index < range.end(); 28 return index >= range.start() && index < range.end();
25 } 29 }
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 render_text->SetText(seuss); 332 render_text->SetText(seuss);
329 render_text->SetObscured(true); 333 render_text->SetObscured(true);
330 EXPECT_EQ(seuss, render_text->text()); 334 EXPECT_EQ(seuss, render_text->text());
331 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); 335 EXPECT_EQ(no_seuss, render_text->GetDisplayText());
332 render_text->SetObscured(false); 336 render_text->SetObscured(false);
333 EXPECT_EQ(seuss, render_text->text()); 337 EXPECT_EQ(seuss, render_text->text());
334 EXPECT_EQ(seuss, render_text->GetDisplayText()); 338 EXPECT_EQ(seuss, render_text->GetDisplayText());
335 339
336 // TODO(benrg): No Windows implementation yet. 340 // TODO(benrg): No Windows implementation yet.
337 #if !defined(OS_WIN) 341 #if !defined(OS_WIN)
338
339 render_text->SetObscured(true); 342 render_text->SetObscured(true);
340 343
341 // Surrogate pairs are counted as one code point. 344 // Surrogate pairs are counted as one code point.
342 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; 345 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0};
343 render_text->SetText(invalid_surrogates); 346 render_text->SetText(invalid_surrogates);
344 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); 347 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText());
345 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; 348 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0};
346 render_text->SetText(valid_surrogates); 349 render_text->SetText(valid_surrogates);
347 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); 350 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText());
348 EXPECT_EQ(0U, render_text->cursor_position()); 351 EXPECT_EQ(0U, render_text->cursor_position());
349 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); 352 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false);
350 EXPECT_EQ(2U, render_text->cursor_position()); 353 EXPECT_EQ(2U, render_text->cursor_position());
351 354
352 // Cursoring is independent of the underlying characters when the text is 355 // Cursoring is independent of the underlying characters when the text is
353 // obscured. 356 // obscured.
354 const wchar_t* const texts[] = { 357 const wchar_t* const texts[] = {
355 L"hop on pop", // word boundaries 358 L"hop on pop", // word boundaries
356 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2 359 L"ab \x5D0\x5D1" L"12", // bidi embedding level of 2
357 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux 360 L"\x5D0\x5D1" L"12", // RTL paragraph direction on Linux
358 L"\x5D0\x5D1" // pure RTL 361 L"\x5D0\x5D1" // pure RTL
359 }; 362 };
360 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) { 363 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(texts); ++i) {
361 string16 text = WideToUTF16(texts[i]); 364 string16 text = WideToUTF16(texts[i]);
362 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); 365 TestVisualCursorMotionInObscuredField(render_text.get(), text, false);
363 TestVisualCursorMotionInObscuredField(render_text.get(), text, true); 366 TestVisualCursorMotionInObscuredField(render_text.get(), text, true);
364 } 367 }
365 #endif // !defined(OS_WIN) 368 #endif // !defined(OS_WIN)
366 } 369 }
367 370
371 // A test utility function to set the application default text direction.
372 void SetRTL(bool rtl) {
Alexei Svitkine (slow) 2012/07/04 15:05:33 Nit: Move it to the anonymous namespace already at
msw 2012/07/04 15:58:08 Done.
373 // Override the current locale/direction.
374 base::i18n::SetICUDefaultLocale(rtl ? "he" : "en");
375 #if defined(TOOLKIT_GTK)
376 // Do the same for GTK, which does not rely on the ICU default locale.
377 gtk_widget_set_default_direction(rtl ? GTK_TEXT_DIR_RTL : GTK_TEXT_DIR_LTR);
378 #endif
379 EXPECT_EQ(rtl, base::i18n::IsRTL());
380 }
381
382 TEST_F(RenderTextTest, GetTextDirection) {
383 // Ensure that text direction is set by the first strong character direction.
384 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
385 for (size_t i = 0; i < 2; ++i) {
386 // Toggle the application default text direction (to try each direction).
387 SetRTL(!base::i18n::IsRTL());
Alexei Svitkine (slow) 2012/07/04 15:05:33 Can you check that the RTL before and after this l
msw 2012/07/04 15:58:08 Done.
388
389 // Blank strings (and those without directionality) default to LTR.
390 render_text->SetText(string16());
391 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection());
392 render_text->SetText(ASCIIToUTF16(" "));
393 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection());
394
395 // Pure LTR.
396 render_text->SetText(ASCIIToUTF16("abc"));
397 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection());
398 // LTR-RTL
399 render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
400 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection());
401 // LTR-RTL-LTR.
402 render_text->SetText(WideToUTF16(L"a"L"\x05d1"L"b"));
403 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, render_text->GetTextDirection());
404 // Pure RTL.
405 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
406 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection());
407 // RTL-LTR
408 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc"));
409 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection());
410 // RTL-LTR-RTL.
411 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1"));
412 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, render_text->GetTextDirection());
413 }
414 }
415
368 void RunMoveCursorLeftRightTest(RenderText* render_text, 416 void RunMoveCursorLeftRightTest(RenderText* render_text,
369 const std::vector<SelectionModel>& expected, 417 const std::vector<SelectionModel>& expected,
370 VisualCursorDirection direction) { 418 VisualCursorDirection direction) {
371 for (size_t i = 0; i < expected.size(); ++i) { 419 for (size_t i = 0; i < expected.size(); ++i) {
372 EXPECT_EQ(expected[i], render_text->selection_model()); 420 EXPECT_EQ(expected[i], render_text->selection_model());
373 render_text->MoveCursor(CHARACTER_BREAK, direction, false); 421 render_text->MoveCursor(CHARACTER_BREAK, direction, false);
374 } 422 }
375 // Check that cursoring is clamped at the line edge. 423 // Check that cursoring is clamped at the line edge.
376 EXPECT_EQ(expected.back(), render_text->selection_model()); 424 EXPECT_EQ(expected.back(), render_text->selection_model());
377 // Check that it is the line edge. 425 // Check that it is the line edge.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 500 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
453 } 501 }
454 502
455 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { 503 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) {
456 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 504 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
457 // Pure RTL. 505 // Pure RTL.
458 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); 506 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
459 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 507 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
460 std::vector<SelectionModel> expected; 508 std::vector<SelectionModel> expected;
461 509
462 #if defined(OS_LINUX)
463 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 510 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
464 #else
465 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
466 #endif
467 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 511 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
468 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 512 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
469 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 513 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
470 #if defined(OS_LINUX)
471 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 514 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
472 #else
473 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
474 #endif
475 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 515 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
476 516
477 expected.clear(); 517 expected.clear();
478 518
479 #if defined(OS_LINUX)
480 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 519 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
481 #else
482 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
483 #endif
484 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 520 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
485 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 521 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
486 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 522 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
487 #if defined(OS_LINUX)
488 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 523 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
489 #else
490 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
491 #endif
492 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 524 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
493 } 525 }
494 526
495 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { 527 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) {
496 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 528 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
497 // RTL-LTR 529 // RTL-LTR
498 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); 530 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc"));
499 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 531 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
500 std::vector<SelectionModel> expected; 532 std::vector<SelectionModel> expected;
501 #if defined(OS_LINUX)
502 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 533 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
503 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 534 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
504 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 535 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
505 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 536 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
506 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); 537 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
507 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 538 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
508 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 539 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
509 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 540 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
510 #else
511 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
512 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
513 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
514 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
515 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
516 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
517 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
518 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
519 #endif
520
521 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 541 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
522 542
523 expected.clear(); 543 expected.clear();
524 #if defined(OS_LINUX)
525 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 544 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
526 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 545 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
527 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); 546 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
528 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); 547 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
529 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 548 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
530 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 549 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
531 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 550 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
532 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 551 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
533 #else
534 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
535 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
536 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
537 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
538 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
539 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
540 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
541 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
542 #endif
543 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 552 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
544 } 553 }
545 554
546 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { 555 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) {
547 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 556 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
548 // RTL-LTR-RTL. 557 // RTL-LTR-RTL.
549 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); 558 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1"));
550 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 559 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
551 std::vector<SelectionModel> expected; 560 std::vector<SelectionModel> expected;
552 #if defined(OS_LINUX)
553 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 561 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
554 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 562 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
555 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 563 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
556 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 564 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
557 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 565 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
558 #else
559 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
560 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
561 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
562 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
563 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
564 #endif
565 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 566 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
566 567
567 expected.clear(); 568 expected.clear();
568 #if defined(OS_LINUX)
569 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 569 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
570 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 570 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
571 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 571 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
572 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 572 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
573 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 573 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
574 #else
575 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
576 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
577 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
578 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
579 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
580 #endif
581 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT); 574 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
582 } 575 }
583 576
584 // TODO(xji): temporarily disable in platform Win since the complex script 577 // TODO(xji): temporarily disable in platform Win since the complex script
585 // characters turned into empty square due to font regression. So, not able 578 // characters turned into empty square due to font regression. So, not able
586 // to test 2 characters belong to the same grapheme. 579 // to test 2 characters belong to the same grapheme.
587 #if defined(OS_LINUX) 580 #if defined(OS_LINUX)
588 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { 581 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) {
589 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 582 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
590 583
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8"); 692 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8");
700 693
701 struct { 694 struct {
702 string16 text; 695 string16 text;
703 base::i18n::TextDirection expected_text_direction; 696 base::i18n::TextDirection expected_text_direction;
704 } cases[] = { 697 } cases[] = {
705 { string16(), base::i18n::LEFT_TO_RIGHT }, 698 { string16(), base::i18n::LEFT_TO_RIGHT },
706 { kLatin, base::i18n::LEFT_TO_RIGHT }, 699 { kLatin, base::i18n::LEFT_TO_RIGHT },
707 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT }, 700 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT },
708 { kHindiLatin, base::i18n::LEFT_TO_RIGHT }, 701 { kHindiLatin, base::i18n::LEFT_TO_RIGHT },
709 #if defined(OS_LINUX)
710 // On Linux, the whole string is displayed RTL, rather than individual runs.
711 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT }, 702 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT },
712 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, 703 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT },
713 #else
714 { kRTLGrapheme, base::i18n::LEFT_TO_RIGHT },
715 { kHebrewLatin, base::i18n::LEFT_TO_RIGHT },
716 #endif
717 }; 704 };
718 705
719 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 706 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
720 // font support for some scripts - http://crbug.com/106450 707 // font support for some scripts - http://crbug.com/106450
721 #if defined(OS_WIN) 708 #if defined(OS_WIN)
722 if (base::win::GetVersion() < base::win::VERSION_VISTA) 709 if (base::win::GetVersion() < base::win::VERSION_VISTA)
723 return; 710 return;
724 #endif 711 #endif
725 712
726 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 713 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 // Ensure that the text will pan to fill its expanding display rectangle. 1167 // Ensure that the text will pan to fill its expanding display rectangle.
1181 render_text->SetDisplayRect(Rect(width - 5, 1)); 1168 render_text->SetDisplayRect(Rect(width - 5, 1));
1182 EXPECT_EQ(render_text->display_rect().width() - 1, 1169 EXPECT_EQ(render_text->display_rect().width() - 1,
1183 render_text->GetUpdatedCursorBounds().x()); 1170 render_text->GetUpdatedCursorBounds().x());
1184 1171
1185 // Ensure that a sufficiently large display rectangle shows all the text. 1172 // Ensure that a sufficiently large display rectangle shows all the text.
1186 render_text->SetDisplayRect(Rect(width + 10, 1)); 1173 render_text->SetDisplayRect(Rect(width + 10, 1));
1187 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x()); 1174 EXPECT_EQ(width, render_text->GetUpdatedCursorBounds().x());
1188 } 1175 }
1189 1176
1190 // TODO(asvitkine): This test fails on desktop Linux. http://crbug.com/134009
1191 #if !defined(OS_LINUX) || defined(OS_CHROMEOS)
1192 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) { 1177 TEST_F(RenderTextTest, DisplayRectShowsCursorRTL) {
1193 // Set the locale to Hebrew for RTL UI. 1178 // Set the application default text direction to RTL.
1194 std::string locale = l10n_util::GetApplicationLocale(""); 1179 SetRTL(true);
1195 base::i18n::SetICUDefaultLocale("he");
1196 1180
1197 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 1181 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
1198 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg")); 1182 render_text->SetText(WideToUTF16(L"abcdefghijklmnopqrstuvwxzyabcdefg"));
1199 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD)); 1183 render_text->MoveCursorTo(SelectionModel(0, CURSOR_FORWARD));
1200 int width = render_text->GetStringSize().width(); 1184 int width = render_text->GetStringSize().width();
1201 ASSERT_GT(width, 10); 1185 ASSERT_GT(width, 10);
1202 1186
1203 // Ensure that the cursor is placed at the width of its preceding text. 1187 // Ensure that the cursor is placed at the width of its preceding text.
1204 render_text->SetDisplayRect(Rect(width + 10, 1)); 1188 render_text->SetDisplayRect(Rect(width + 10, 1));
1205 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1189 EXPECT_EQ(render_text->display_rect().width() - width - 1,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1221
1238 // Ensure that the text will pan to fill its expanding display rectangle. 1222 // Ensure that the text will pan to fill its expanding display rectangle.
1239 render_text->SetDisplayRect(Rect(width - 5, 1)); 1223 render_text->SetDisplayRect(Rect(width - 5, 1));
1240 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x()); 1224 EXPECT_EQ(0, render_text->GetUpdatedCursorBounds().x());
1241 1225
1242 // Ensure that a sufficiently large display rectangle shows all the text. 1226 // Ensure that a sufficiently large display rectangle shows all the text.
1243 render_text->SetDisplayRect(Rect(width + 10, 1)); 1227 render_text->SetDisplayRect(Rect(width + 10, 1));
1244 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1228 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1245 render_text->GetUpdatedCursorBounds().x()); 1229 render_text->GetUpdatedCursorBounds().x());
1246 1230
1247 // Reset locale. 1231 // Reset the application default text direction to LTR.
1248 base::i18n::SetICUDefaultLocale(locale); 1232 SetRTL(false);
Alexei Svitkine (slow) 2012/07/04 15:05:33 I don't think that's right. You want to restore to
msw 2012/07/04 15:58:08 Done.
1249 } 1233 }
1250 #endif // !defined(OS_LINUX) || defined(OS_CHROMEOS)
1251 1234
1252 } // namespace gfx 1235 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698