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 // This test was created specifically to test a message from crbug.com/415213. | |
681 // It tests that width of concatenation of words equals sum of widths of the | |
682 // words. | |
683 #if defined(OS_CHROMEOS) | |
684 #define MAYBE_ElideRectangleTextCheckConcatWidthEqualsSumOfWidths \ | |
685 ElideRectangleTextCheckConcatWidthEqualsSumOfWidths | |
686 #else | |
687 #define MAYBE_ElideRectangleTextCheckConcatWidthEqualsSumOfWidths \ | |
688 DISABLED_ElideRectangleTextCheckConcatWidthEqualsSumOfWidths | |
Alexei Svitkine (slow)
2014/11/06 15:05:46
Does this mean it fails on other platforms?
Roman Sorokin (ftl)
2014/11/06 15:10:07
I think no, (have not checked yet). I guess I coul
| |
689 #endif | |
690 TEST(TextEliderTest, | |
691 MAYBE_ElideRectangleTextCheckConcatWidthEqualsSumOfWidths) { | |
692 FontList font_list; | |
693 font_list = FontList("Noto Sans UI,ui-sans, 12px"); | |
694 SetFontRenderParamsDeviceScaleFactor(1.25f); | |
695 #define WIDTH(x) GetStringWidthF(UTF8ToUTF16(x), font_list) | |
696 EXPECT_EQ(WIDTH("The administrator for this account has"), | |
697 WIDTH("The ") + WIDTH("administrator ") + WIDTH("for ") + | |
698 WIDTH("this ") + WIDTH("account ") + WIDTH("has")); | |
699 #undef WIDTH | |
700 SetFontRenderParamsDeviceScaleFactor(1.0f); | |
701 } | |
702 | |
679 TEST(TextEliderTest, ElideRectangleString) { | 703 TEST(TextEliderTest, ElideRectangleString) { |
680 struct TestData { | 704 struct TestData { |
681 const char* input; | 705 const char* input; |
682 int max_rows; | 706 int max_rows; |
683 int max_cols; | 707 int max_cols; |
684 bool result; | 708 bool result; |
685 const char* output; | 709 const char* output; |
686 } cases[] = { | 710 } cases[] = { |
687 { "", 0, 0, false, "" }, | 711 { "", 0, 0, false, "" }, |
688 { "", 1, 1, false, "" }, | 712 { "", 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. | 941 // Test adds ... at right spot within a word. |
918 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, | 942 EXPECT_EQ(L"f\x2026", UTF16ToWide(TruncateString(string, 2, |
919 CHARACTER_BREAK))); | 943 CHARACTER_BREAK))); |
920 | 944 |
921 // Test removes trailing whitespace if break falls between words. | 945 // Test removes trailing whitespace if break falls between words. |
922 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, | 946 EXPECT_EQ(L"foooooey\x2026", UTF16ToWide(TruncateString(string, 12, |
923 CHARACTER_BREAK))); | 947 CHARACTER_BREAK))); |
924 } | 948 } |
925 | 949 |
926 } // namespace gfx | 950 } // namespace gfx |
OLD | NEW |