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 "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font.h" |
16 #include "ui/gfx/font_list.h" | 16 #include "ui/gfx/font_list.h" |
| 17 #include "ui/gfx/font_render_params.h" |
17 #include "ui/gfx/text_utils.h" | 18 #include "ui/gfx/text_utils.h" |
18 | 19 |
19 using base::ASCIIToUTF16; | 20 using base::ASCIIToUTF16; |
20 using base::UTF16ToUTF8; | 21 using base::UTF16ToUTF8; |
21 using base::UTF16ToWide; | 22 using base::UTF16ToWide; |
22 using base::UTF8ToUTF16; | 23 using base::UTF8ToUTF16; |
23 using base::WideToUTF16; | 24 using base::WideToUTF16; |
24 | 25 |
25 namespace gfx { | 26 namespace gfx { |
26 | 27 |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 font_list, | 670 font_list, |
670 kAvailableWidth, | 671 kAvailableWidth, |
671 kAvailableHeight, | 672 kAvailableHeight, |
672 WRAP_LONG_WORDS, | 673 WRAP_LONG_WORDS, |
673 &lines)); | 674 &lines)); |
674 ASSERT_EQ(2u, lines.size()); | 675 ASSERT_EQ(2u, lines.size()); |
675 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth); | 676 EXPECT_LE(GetStringWidthF(lines[0], font_list), kAvailableWidth); |
676 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth); | 677 EXPECT_LE(GetStringWidthF(lines[1], font_list), kAvailableWidth); |
677 } | 678 } |
678 | 679 |
| 680 #ifdef OS_CHROMEOS |
| 681 // This test was created specifically to test a message from crbug.com/415213. |
| 682 // It tests that width of concatenation of words equals sum of widths of the |
| 683 // words. |
| 684 TEST(TextEliderTest, ElideRectangleTextCheckConcatWidthEqualsSumOfWidths) { |
| 685 FontList font_list; |
| 686 font_list = FontList("Noto Sans UI,ui-sans, 12px"); |
| 687 SetFontRenderParamsDeviceScaleFactor(1.25f); |
| 688 #define WIDTH(x) GetStringWidthF(UTF8ToUTF16(x), font_list) |
| 689 EXPECT_EQ(WIDTH("The administrator for this account has"), |
| 690 WIDTH("The ") + WIDTH("administrator ") + WIDTH("for ") + |
| 691 WIDTH("this ") + WIDTH("account ") + WIDTH("has")); |
| 692 #undef WIDTH |
| 693 SetFontRenderParamsDeviceScaleFactor(1.0f); |
| 694 } |
| 695 #endif // OS_CHROMEOS |
| 696 |
679 TEST(TextEliderTest, ElideRectangleString) { | 697 TEST(TextEliderTest, ElideRectangleString) { |
680 struct TestData { | 698 struct TestData { |
681 const char* input; | 699 const char* input; |
682 int max_rows; | 700 int max_rows; |
683 int max_cols; | 701 int max_cols; |
684 bool result; | 702 bool result; |
685 const char* output; | 703 const char* output; |
686 } cases[] = { | 704 } cases[] = { |
687 { "", 0, 0, false, "" }, | 705 { "", 0, 0, false, "" }, |
688 { "", 1, 1, false, "" }, | 706 { "", 1, 1, false, "" }, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 // Test adds ... at right spot within a word. | 935 // Test adds ... at right spot within a word. |
918 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, | 936 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, |
919 CHARACTER_BREAK))); | 937 CHARACTER_BREAK))); |
920 | 938 |
921 // Test removes trailing whitespace if break falls between words. | 939 // Test removes trailing whitespace if break falls between words. |
922 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, | 940 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, |
923 CHARACTER_BREAK))); | 941 CHARACTER_BREAK))); |
924 } | 942 } |
925 | 943 |
926 } // namespace gfx | 944 } // namespace gfx |
OLD | NEW |