Chromium Code Reviews| Index: ui/gfx/render_text_unittest.cc |
| diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc |
| index c8c50d428141cf2be2af4ae08c33b522a9befff6..c471622d08bfdab5204cb84ef91d43d2a5e5905c 100644 |
| --- a/ui/gfx/render_text_unittest.cc |
| +++ b/ui/gfx/render_text_unittest.cc |
| @@ -401,6 +401,91 @@ TEST_F(RenderTextTest, RevealObscuredText) { |
| EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
| } |
| +TEST_F(RenderTextTest, ElidedText) { |
| + // TODO(skanuj) : Add more test cases for following |
| + // - RenderText styles. |
| + // - Cross interaction of truncate, elide and obscure. |
| + // - ElideText tests from text_elider.cc. |
| + struct { |
| + const wchar_t* text; |
| + const wchar_t* layout_text; |
| + const bool elision_expected; |
| + } cases[] = { |
| + // Strings shorter than the elision width should be laid out in full. |
| + { L"", L"" , false }, |
| + { L" . ", L" . " , false }, |
|
msw
2013/12/27 22:54:33
nit: this case is equivalent to kWeak, right? Remo
Anuj
2013/12/30 22:46:58
Done.
|
| + { kWeak, kWeak , false }, |
| + { kLtr, kLtr , false }, |
| + { kLtrRtl, kLtrRtl , false }, |
| + { kLtrRtlLtr, kLtrRtlLtr, false }, |
| + { kRtl, kRtl , false }, |
| + { kRtlLtr, kRtlLtr , false }, |
| + { kRtlLtrRtl, kRtlLtrRtl, false }, |
| + // Strings as long as the elision width should be laid out in full. |
| + { L"012ab", L"012ab" , false }, |
| + // Long strings should be elided with an ellipsis appended at the end. |
| + { L"012abc", L"012a\x2026", true }, |
| + { L"012ab" L"\x5d0\x5d1", L"012a\x2026", true }, |
| + { L"012a" L"\x5d1" L"b", L"012a\x2026", true }, |
| + // No RLM marker added as digits (012) have weak directionality. |
| + { L"01" L"\x5d0\x5d1\x5d2", L"01\x5d0\x5d1\x2026", true }, |
| + // RLM marker added as "ab" have strong LTR directionality. |
| + { L"ab" L"\x5d0\x5d1\x5d2", L"ab\x5d0\x5d1\x2026\x200f", true }, |
| + // Complex script is not handled. In this example, the "\x0915\x093f" is a |
| + // compound glyph, but only half of it is elided. |
| + { L"0123\x0915\x093f", L"0123\x0915\x2026", true }, |
| + // Surrogate pairs should be elided reasonably enough. |
| + { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8", false }, |
| + { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x2026" , true }, |
| + { L"01\x05e9\x05bc\x05c1\x05b8", L"01\x05e9\x2026" , true }, |
| + { L"012\x05e9\x05bc\x05c1\x05b8", L"012\x2026" , true }, |
| + { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , true }, |
| + }; |
| + |
| + scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); |
| + expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); |
| + expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); |
| + |
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| + render_text->SetFontList(FontList("serif, Sans serif, 12px")); |
| + render_text->SetElideBehavior(gfx::ELIDE_AT_END); |
| + |
| + for (size_t i = 1; i < ARRAYSIZE_UNSAFE(cases); i++) { |
|
msw
2013/12/27 22:54:33
Why do you skip the first test case of an empty st
Anuj
2013/12/30 22:46:58
Fixed. I was skipping it for testing the testcases
|
| + // Compute expected width |
| + expected_render_text->SetText(WideToUTF16(cases[i].layout_text)); |
| + int expected_width = expected_render_text->GetContentWidth(); |
| + |
| + base::string16 input = WideToUTF16(cases[i].text); |
| + // Extend input to always be wide enough to be elided. |
|
msw
2013/12/27 22:54:33
nit: add to this comment ", otherwise the layout t
Anuj
2013/12/30 22:46:58
Reworded the comment. I think this is a reasonable
|
| + if (cases[i].elision_expected) |
| + input += WideToUTF16(L" MMMMMMMMMMM"); |
|
msw
2013/12/27 22:54:33
Use append, and shouldn't this use characters with
Anuj
2013/12/30 22:46:58
I am curious about preference for append? The two
msw
2013/12/30 23:17:59
Don't you check the trailing directionality of the
Anuj
2013/12/31 00:04:03
I do. But the string which remains matters. This p
msw
2013/12/31 00:24:52
Ah, good point, thanks for clarifying.
Anuj
2013/12/31 00:42:03
Done.
|
| + |
| + render_text->SetText(input); |
| + render_text->SetDisplayRect(gfx::Rect(0, 0, expected_width, 100)); |
| + EXPECT_EQ(input, render_text->text()); |
| + EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText()) |
| + << "->For case " << i << ": " << cases[i].text << "\n"; |
| + expected_render_text->SetText(base::string16()); |
| + } |
| +} |
| + |
| +TEST_F(RenderTextTest, ElidedObscuredText) { |
| + scoped_ptr<RenderText> expected_render_text(RenderText::CreateInstance()); |
| + expected_render_text->SetFontList(FontList("serif, Sans serif, 12px")); |
| + expected_render_text->SetDisplayRect(gfx::Rect(0, 0, 9999, 100)); |
| + expected_render_text->SetText(WideToUTF16(L"**\x2026")); |
| + |
| + scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| + render_text->SetFontList(FontList("serif, Sans serif, 12px")); |
| + render_text->SetElideBehavior(gfx::ELIDE_AT_END); |
| + render_text->SetDisplayRect( |
| + gfx::Rect(0, 0, expected_render_text->GetContentWidth(), 100)); |
| + render_text->SetObscured(true); |
| + render_text->SetText(WideToUTF16(L"abcdef")); |
| + EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); |
| + EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetLayoutText()); |
| +} |
| + |
| TEST_F(RenderTextTest, TruncatedText) { |
| struct { |
| const wchar_t* text; |