OLD | NEW |
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 <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 for (size_t i = 0; i < arraysize(cases); ++i) { | 661 for (size_t i = 0; i < arraysize(cases); ++i) { |
662 std::vector<base::string16> lines; | 662 std::vector<base::string16> lines; |
663 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, | 663 EXPECT_EQ(cases[i].truncated_y ? INSUFFICIENT_SPACE_VERTICAL : 0, |
664 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 664 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
665 font_list, | 665 font_list, |
666 cases[i].available_pixel_width, | 666 cases[i].available_pixel_width, |
667 cases[i].available_pixel_height, | 667 cases[i].available_pixel_height, |
668 TRUNCATE_LONG_WORDS, | 668 TRUNCATE_LONG_WORDS, |
669 &lines)); | 669 &lines)); |
670 if (cases[i].output) { | 670 if (cases[i].output) { |
671 const std::string result = | 671 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
672 UTF16ToUTF8(base::JoinString(lines, ASCIIToUTF16("|"))); | |
673 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; | 672 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; |
674 } else { | 673 } else { |
675 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; | 674 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; |
676 } | 675 } |
677 } | 676 } |
678 } | 677 } |
679 | 678 |
680 // TODO(338784): Enable this on android. | 679 // TODO(338784): Enable this on android. |
681 #if defined(OS_ANDROID) | 680 #if defined(OS_ANDROID) |
682 #define MAYBE_ElideRectangleTextPunctuation \ | 681 #define MAYBE_ElideRectangleTextPunctuation \ |
(...skipping 26 matching lines...) Expand all Loading... |
709 const WordWrapBehavior wrap_behavior = | 708 const WordWrapBehavior wrap_behavior = |
710 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); | 709 (cases[i].wrap_words ? WRAP_LONG_WORDS : TRUNCATE_LONG_WORDS); |
711 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, | 710 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, |
712 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 711 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
713 font_list, | 712 font_list, |
714 cases[i].available_pixel_width, | 713 cases[i].available_pixel_width, |
715 cases[i].available_pixel_height, | 714 cases[i].available_pixel_height, |
716 wrap_behavior, | 715 wrap_behavior, |
717 &lines)); | 716 &lines)); |
718 if (cases[i].output) { | 717 if (cases[i].output) { |
719 const std::string result = | 718 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
720 UTF16ToUTF8(base::JoinString(lines, base::ASCIIToUTF16("|"))); | |
721 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; | 719 EXPECT_EQ(cases[i].output, result) << "Case " << i << " failed!"; |
722 } else { | 720 } else { |
723 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; | 721 EXPECT_TRUE(lines.empty()) << "Case " << i << " failed!"; |
724 } | 722 } |
725 } | 723 } |
726 } | 724 } |
727 | 725 |
728 // TODO(338784): Enable this on android. | 726 // TODO(338784): Enable this on android. |
729 #if defined(OS_ANDROID) | 727 #if defined(OS_ANDROID) |
730 #define MAYBE_ElideRectangleTextLongWords DISABLED_ElideRectangleTextLongWords | 728 #define MAYBE_ElideRectangleTextLongWords DISABLED_ElideRectangleTextLongWords |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 std::vector<base::string16> lines; | 777 std::vector<base::string16> lines; |
780 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, | 778 EXPECT_EQ(cases[i].truncated_x ? INSUFFICIENT_SPACE_HORIZONTAL : 0, |
781 ElideRectangleText(UTF8ToUTF16(cases[i].input), | 779 ElideRectangleText(UTF8ToUTF16(cases[i].input), |
782 font_list, | 780 font_list, |
783 cases[i].available_pixel_width, | 781 cases[i].available_pixel_width, |
784 kAvailableHeight, | 782 kAvailableHeight, |
785 cases[i].wrap_behavior, | 783 cases[i].wrap_behavior, |
786 &lines)); | 784 &lines)); |
787 std::string expected_output(cases[i].output); | 785 std::string expected_output(cases[i].output); |
788 base::ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); | 786 base::ReplaceSubstringsAfterOffset(&expected_output, 0, "...", kEllipsis); |
789 const std::string result = | 787 const std::string result = UTF16ToUTF8(JoinString(lines, '|')); |
790 UTF16ToUTF8(base::JoinString(lines, base::ASCIIToUTF16("|"))); | |
791 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; | 788 EXPECT_EQ(expected_output, result) << "Case " << i << " failed!"; |
792 } | 789 } |
793 } | 790 } |
794 | 791 |
795 // This test is to make sure that the width of each wrapped line does not | 792 // This test is to make sure that the width of each wrapped line does not |
796 // exceed the available width. On some platform like Mac, this test used to | 793 // exceed the available width. On some platform like Mac, this test used to |
797 // fail because the truncated integer width is returned for the string | 794 // fail because the truncated integer width is returned for the string |
798 // and the accumulation of the truncated values causes the elide function | 795 // and the accumulation of the truncated values causes the elide function |
799 // to wrap incorrectly. | 796 // to wrap incorrectly. |
800 // TODO(338784): Enable this on android. | 797 // TODO(338784): Enable this on android. |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 // Test adds ... at right spot within a word. | 1111 // Test adds ... at right spot within a word. |
1115 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, | 1112 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, |
1116 CHARACTER_BREAK))); | 1113 CHARACTER_BREAK))); |
1117 | 1114 |
1118 // Test removes trailing whitespace if break falls between words. | 1115 // Test removes trailing whitespace if break falls between words. |
1119 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, | 1116 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, |
1120 CHARACTER_BREAK))); | 1117 CHARACTER_BREAK))); |
1121 } | 1118 } |
1122 | 1119 |
1123 } // namespace gfx | 1120 } // namespace gfx |
OLD | NEW |