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

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

Issue 614103007: Error in popup on Link (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 // Unit tests for eliding and formatting utility functions. 5 // Unit tests for eliding and formatting utility functions.
6 6
7 #include "ui/gfx/text_elider.h" 7 #include "ui/gfx/text_elider.h"
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 }; 513 };
514 514
515 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 515 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
516 std::vector<base::string16> lines; 516 std::vector<base::string16> lines;
517 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, 517 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0,
518 ElideRectangleText(UTF8ToUTF16(cases[i].input), 518 ElideRectangleText(UTF8ToUTF16(cases[i].input),
519 font_list, 519 font_list,
520 cases[i].available_pixel_width, 520 cases[i].available_pixel_width,
521 cases[i].available_pixel_height, 521 cases[i].available_pixel_height,
522 TRUNCATE_LONG_WORDS, 522 TRUNCATE_LONG_WORDS,
523 &lines)); 523 &lines,
524 nullptr));
524 if (cases[i].output) { 525 if (cases[i].output) {
525 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 526 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
526 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; 527 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
527 } else { 528 } else {
528 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; 529 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
529 } 530 }
530 } 531 }
531 } 532 }
532 533
533 // TODO(338784): Enable this on android. 534 // TODO(338784): Enable this on android.
(...skipping 26 matching lines...) Expand all
560 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 561 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
561 std::vector<base::string16> lines; 562 std::vector<base::string16> lines;
562 const WordWrapBehavior wrap_behavior = 563 const WordWrapBehavior wrap_behavior =
563 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); 564 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS);
564 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, 565 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0,
565 ElideRectangleText(UTF8ToUTF16(cases[i].input), 566 ElideRectangleText(UTF8ToUTF16(cases[i].input),
566 font_list, 567 font_list,
567 cases[i].available_pixel_width, 568 cases[i].available_pixel_width,
568 cases[i].available_pixel_height, 569 cases[i].available_pixel_height,
569 wrap_behavior, 570 wrap_behavior,
570 &lines)); 571 &lines,
572 nullptr));
571 if (cases[i].output) { 573 if (cases[i].output) {
572 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 574 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
573 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; 575 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!";
574 } else { 576 } else {
575 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; 577 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!";
576 } 578 }
577 } 579 }
578 } 580 }
579 581
580 // TODO(338784): Enable this on android. 582 // TODO(338784): Enable this on android.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 }; 630 };
629 631
630 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { 632 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
631 std::vector<base::string16> lines; 633 std::vector<base::string16> lines;
632 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, 634 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0,
633 ElideRectangleText(UTF8ToUTF16(cases[i].input), 635 ElideRectangleText(UTF8ToUTF16(cases[i].input),
634 font_list, 636 font_list,
635 cases[i].available_pixel_width, 637 cases[i].available_pixel_width,
636 kAvailableHeight, 638 kAvailableHeight,
637 cases[i].wrap_behavior, 639 cases[i].wrap_behavior,
638 &lines)); 640 &lines,
641 nullptr));
639 std::string expected_output(cases[i].output); 642 std::string expected_output(cases[i].output);
640 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); 643 ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis);
641 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); 644 const std::string result = UTF16ToUTF8(JoinString(lines, '|'));
642 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; 645 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!";
643 } 646 }
644 } 647 }
645 648
646 // This test is to make sure that the width of each wrapped line does not 649 // This test is to make sure that the width of each wrapped line does not
647 // exceed the available width. On some platform like Mac, this test used to 650 // exceed the available width. On some platform like Mac, this test used to
648 // fail because the truncated integer width is returned for the string 651 // fail because the truncated integer width is returned for the string
649 // and the accumulation of the truncated values causes the elide function 652 // and the accumulation of the truncated values causes the elide function
650 // to wrap incorrectly. 653 // to wrap incorrectly.
651 // TODO(338784): Enable this on android. 654 // TODO(338784): Enable this on android.
652 #if defined(OS_ANDROID) 655 #if defined(OS_ANDROID)
653 #define MAYBE_ElideRectangleTextCheckLineWidth \ 656 #define MAYBE_ElideRectangleTextCheckLineWidth \
654 DISABLED_ElideRectangleTextCheckLineWidth 657 DISABLED_ElideRectangleTextCheckLineWidth
655 #else 658 #else
656 #define MAYBE_ElideRectangleTextCheckLineWidth ElideRectangleTextCheckLineWidth 659 #define MAYBE_ElideRectangleTextCheckLineWidth ElideRectangleTextCheckLineWidth
657 #endif 660 #endif
658 TEST(TextEliderTest, MAYBE_ElideRectangleTextCheckLineWidth) { 661 TEST(TextEliderTest, MAYBE_ElideRectangleTextCheckLineWidth) {
659 FontList font_list; 662 FontList font_list;
660 #if defined(OS_MACOSX) && !defined(OS_IOS) 663 #if defined(OS_MACOSX) && !defined(OS_IOS)
661 // Use a specific font to expose the line width exceeding problem. 664 // Use a specific font to expose the line width exceeding problem.
662 font_list = FontList(Font("LucidaGrande", 12)); 665 font_list = FontList(Font("LucidaGrande", 12));
663 #endif 666 #endif
664 const float kAvailableWidth = 235; 667 const float kAvailableWidth = 235;
665 const int kAvailableHeight = 1000; 668 const int kAvailableHeight = 1000;
666 const char text[] = "that Russian place we used to go to after fencing"; 669 const char text[] = "that Russian place we used to go to after fencing";
667 std::vector<base::string16> lines; 670 std::vector<base::string16> lines;
668 EXPECT_EQ(0, ElideRectangleText(UTF8ToUTF16(text), 671 EXPECT_EQ(0,
669 font_list, 672 ElideRectangleText(UTF8ToUTF16(text),
670 kAvailableWidth, 673 font_list,
671 kAvailableHeight, 674 kAvailableWidth,
672 WRAP_LONG_WORDS, 675 kAvailableHeight,
673 &lines)); 676 WRAP_LONG_WORDS,
677 &lines,
678 nullptr));
674 ASSERT_EQ(2u, lines.size()); 679 ASSERT_EQ(2u, lines.size());
675 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth); 680 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth);
676 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth); 681 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth);
677 } 682 }
678 683
679 TEST(TextEliderTest, ElideRectangleString) { 684 TEST(TextEliderTest, ElideRectangleString) {
680 struct TestData { 685 struct TestData {
681 const char* input; 686 const char* input;
682 int max_rows; 687 int max_rows;
683 int max_cols; 688 int max_cols;
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 // Test adds ... at right spot within a word. 922 // Test adds ... at right spot within a word.
918 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, 923 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2,
919 CHARACTER_BREAK))); 924 CHARACTER_BREAK)));
920 925
921 // Test removes trailing whitespace if break falls between words. 926 // Test removes trailing whitespace if break falls between words.
922 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, 927 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12,
923 CHARACTER_BREAK))); 928 CHARACTER_BREAK)));
924 } 929 }
925 930
926 } // namespace gfx 931 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698