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

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: Sync and rebase. 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 | « no previous file | ui/gfx/render_text_win.cc » ('j') | ui/gfx/render_text_win.cc » ('J')
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"
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 render_text->SetText(seuss); 328 render_text->SetText(seuss);
329 render_text->SetObscured(true); 329 render_text->SetObscured(true);
330 EXPECT_EQ(seuss, render_text->text()); 330 EXPECT_EQ(seuss, render_text->text());
331 EXPECT_EQ(no_seuss, render_text->GetDisplayText()); 331 EXPECT_EQ(no_seuss, render_text->GetDisplayText());
332 render_text->SetObscured(false); 332 render_text->SetObscured(false);
333 EXPECT_EQ(seuss, render_text->text()); 333 EXPECT_EQ(seuss, render_text->text());
334 EXPECT_EQ(seuss, render_text->GetDisplayText()); 334 EXPECT_EQ(seuss, render_text->GetDisplayText());
335 335
336 // TODO(benrg): No Windows implementation yet. 336 // TODO(benrg): No Windows implementation yet.
337 #if !defined(OS_WIN) 337 #if !defined(OS_WIN)
338
339 render_text->SetObscured(true); 338 render_text->SetObscured(true);
340 339
341 // Surrogate pairs are counted as one code point. 340 // Surrogate pairs are counted as one code point.
342 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0}; 341 const char16 invalid_surrogates[] = {0xDC00, 0xD800, 0};
343 render_text->SetText(invalid_surrogates); 342 render_text->SetText(invalid_surrogates);
344 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText()); 343 EXPECT_EQ(ASCIIToUTF16("**"), render_text->GetDisplayText());
345 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0}; 344 const char16 valid_surrogates[] = {0xD800, 0xDC00, 0};
346 render_text->SetText(valid_surrogates); 345 render_text->SetText(valid_surrogates);
347 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText()); 346 EXPECT_EQ(ASCIIToUTF16("*"), render_text->GetDisplayText());
348 EXPECT_EQ(0U, render_text->cursor_position()); 347 EXPECT_EQ(0U, render_text->cursor_position());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT); 451 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
453 } 452 }
454 453
455 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) { 454 TEST_F(RenderTextTest, MoveCursorLeftRightInRtl) {
456 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 455 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
457 // Pure RTL. 456 // Pure RTL.
458 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2")); 457 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"));
459 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 458 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
460 std::vector<SelectionModel> expected; 459 std::vector<SelectionModel> expected;
461 460
462 #if defined(OS_LINUX)
463 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 461 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)); 462 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
468 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 463 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
469 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 464 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
470 #if defined(OS_LINUX)
471 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 465 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); 466 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
476 467
477 expected.clear(); 468 expected.clear();
478 469
479 #if defined(OS_LINUX)
480 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 470 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)); 471 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
485 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 472 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
486 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 473 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
487 #if defined(OS_LINUX)
488 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 474 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); 475 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
493 } 476 }
494 477
495 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) { 478 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtr) {
496 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 479 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
497 // RTL-LTR 480 // RTL-LTR
498 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc")); 481 render_text->SetText(WideToUTF16(L"\x05d0\x05d1\x05d2"L"abc"));
499 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 482 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
500 std::vector<SelectionModel> expected; 483 std::vector<SelectionModel> expected;
501 #if defined(OS_LINUX)
502 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 484 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
503 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 485 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
504 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 486 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
505 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 487 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
506 expected.push_back(SelectionModel(5, CURSOR_FORWARD)); 488 expected.push_back(SelectionModel(5, CURSOR_FORWARD));
507 expected.push_back(SelectionModel(4, CURSOR_FORWARD)); 489 expected.push_back(SelectionModel(4, CURSOR_FORWARD));
508 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 490 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
509 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 491 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); 492 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
522 493
523 expected.clear(); 494 expected.clear();
524 #if defined(OS_LINUX)
525 expected.push_back(SelectionModel(6, CURSOR_FORWARD)); 495 expected.push_back(SelectionModel(6, CURSOR_FORWARD));
526 expected.push_back(SelectionModel(4, CURSOR_BACKWARD)); 496 expected.push_back(SelectionModel(4, CURSOR_BACKWARD));
527 expected.push_back(SelectionModel(5, CURSOR_BACKWARD)); 497 expected.push_back(SelectionModel(5, CURSOR_BACKWARD));
528 expected.push_back(SelectionModel(6, CURSOR_BACKWARD)); 498 expected.push_back(SelectionModel(6, CURSOR_BACKWARD));
529 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 499 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
530 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 500 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
531 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 501 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
532 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 502 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); 503 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
544 } 504 }
545 505
546 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) { 506 TEST_F(RenderTextTest, MoveCursorLeftRightInRtlLtrRtl) {
547 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 507 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
548 // RTL-LTR-RTL. 508 // RTL-LTR-RTL.
549 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1")); 509 render_text->SetText(WideToUTF16(L"\x05d0"L"a"L"\x05d1"));
550 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false); 510 render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, false);
551 std::vector<SelectionModel> expected; 511 std::vector<SelectionModel> expected;
552 #if defined(OS_LINUX)
553 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 512 expected.push_back(SelectionModel(0, CURSOR_BACKWARD));
554 expected.push_back(SelectionModel(1, CURSOR_BACKWARD)); 513 expected.push_back(SelectionModel(1, CURSOR_BACKWARD));
555 expected.push_back(SelectionModel(1, CURSOR_FORWARD)); 514 expected.push_back(SelectionModel(1, CURSOR_FORWARD));
556 expected.push_back(SelectionModel(3, CURSOR_BACKWARD)); 515 expected.push_back(SelectionModel(3, CURSOR_BACKWARD));
557 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 516 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); 517 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_LEFT);
566 518
567 expected.clear(); 519 expected.clear();
568 #if defined(OS_LINUX)
569 expected.push_back(SelectionModel(3, CURSOR_FORWARD)); 520 expected.push_back(SelectionModel(3, CURSOR_FORWARD));
570 expected.push_back(SelectionModel(2, CURSOR_FORWARD)); 521 expected.push_back(SelectionModel(2, CURSOR_FORWARD));
571 expected.push_back(SelectionModel(2, CURSOR_BACKWARD)); 522 expected.push_back(SelectionModel(2, CURSOR_BACKWARD));
572 expected.push_back(SelectionModel(0, CURSOR_FORWARD)); 523 expected.push_back(SelectionModel(0, CURSOR_FORWARD));
573 expected.push_back(SelectionModel(0, CURSOR_BACKWARD)); 524 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); 525 RunMoveCursorLeftRightTest(render_text.get(), expected, CURSOR_RIGHT);
582 } 526 }
583 527
584 // TODO(xji): temporarily disable in platform Win since the complex script 528 // TODO(xji): temporarily disable in platform Win since the complex script
585 // characters turned into empty square due to font regression. So, not able 529 // characters turned into empty square due to font regression. So, not able
586 // to test 2 characters belong to the same grapheme. 530 // to test 2 characters belong to the same grapheme.
587 #if defined(OS_LINUX) 531 #if defined(OS_LINUX)
588 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) { 532 TEST_F(RenderTextTest, MoveCursorLeftRight_ComplexScript) {
589 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 533 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
590 534
(...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"); 643 const string16 kHebrewLatin = WideToUTF16(L"\x05e0\x05b8"L"a"L"\x05e0\x05b8");
700 644
701 struct { 645 struct {
702 string16 text; 646 string16 text;
703 base::i18n::TextDirection expected_text_direction; 647 base::i18n::TextDirection expected_text_direction;
704 } cases[] = { 648 } cases[] = {
705 { string16(), base::i18n::LEFT_TO_RIGHT }, 649 { string16(), base::i18n::LEFT_TO_RIGHT },
706 { kLatin, base::i18n::LEFT_TO_RIGHT }, 650 { kLatin, base::i18n::LEFT_TO_RIGHT },
707 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT }, 651 { kLTRGrapheme, base::i18n::LEFT_TO_RIGHT },
708 { kHindiLatin, base::i18n::LEFT_TO_RIGHT }, 652 { 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 }, 653 { kRTLGrapheme, base::i18n::RIGHT_TO_LEFT },
712 { kHebrewLatin, base::i18n::RIGHT_TO_LEFT }, 654 { 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 }; 655 };
718 656
719 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 657 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
720 // font support for some scripts - http://crbug.com/106450 658 // font support for some scripts - http://crbug.com/106450
721 #if defined(OS_WIN) 659 #if defined(OS_WIN)
722 if (base::win::GetVersion() < base::win::VERSION_VISTA) 660 if (base::win::GetVersion() < base::win::VERSION_VISTA)
723 return; 661 return;
724 #endif 662 #endif
725 663
726 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); 664 scoped_ptr<RenderText> render_text(RenderText::CreateRenderText());
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 render_text->SetDisplayRect(Rect(width + 10, 1)); 1181 render_text->SetDisplayRect(Rect(width + 10, 1));
1244 EXPECT_EQ(render_text->display_rect().width() - width - 1, 1182 EXPECT_EQ(render_text->display_rect().width() - width - 1,
1245 render_text->GetUpdatedCursorBounds().x()); 1183 render_text->GetUpdatedCursorBounds().x());
1246 1184
1247 // Reset locale. 1185 // Reset locale.
1248 base::i18n::SetICUDefaultLocale(locale); 1186 base::i18n::SetICUDefaultLocale(locale);
1249 } 1187 }
1250 #endif // !defined(OS_LINUX) || defined(OS_CHROMEOS) 1188 #endif // !defined(OS_LINUX) || defined(OS_CHROMEOS)
1251 1189
1252 } // namespace gfx 1190 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text_win.cc » ('j') | ui/gfx/render_text_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698