| 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..aa28b2459fe61e5631cb0dac61e3630ef0110ea2 100644
|
| --- a/ui/gfx/render_text_unittest.cc
|
| +++ b/ui/gfx/render_text_unittest.cc
|
| @@ -401,6 +401,92 @@ 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;
|
| + } cases[] = {
|
| + // Strings shorter than the elision width should be laid out in full.
|
| + { L"" , L"" },
|
| + { kWeak , kWeak },
|
| + { kLtr , kLtr },
|
| + { kLtrRtl , kLtrRtl },
|
| + { kLtrRtlLtr , kLtrRtlLtr },
|
| + { kRtl , kRtl },
|
| + { kRtlLtr , kRtlLtr },
|
| + { kRtlLtrRtl , kRtlLtrRtl },
|
| + // Strings as long as the elision width should be laid out in full.
|
| + { L"012ab", L"012ab" },
|
| + // Long strings should be elided with an ellipsis appended at the end.
|
| + { L"012" L"abc" , L"012a\x2026" },
|
| + { L"012" L"ab" L"\x5d0\x5d1" , L"012a\x2026" },
|
| + { L"012" L"a" L"\x5d1" L"b" , L"012a\x2026" },
|
| + // No RLM marker added as digits (012) have weak directionality.
|
| + { L"01" L"\x5d0\x5d1\x5d2" L"ab" , L"01\x5d0\x5d1\x2026" },
|
| + // RLM marker added as "ab" have strong LTR directionality.
|
| + { L"ab" L"\x5d0\x5d1\x5d2" L"ab" , L"ab\x5d0\x5d1\x2026\x200f" },
|
| + // 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"abcd" , L"0123\x0915\x2026" },
|
| + // Surrogate pairs should be elided reasonably enough.
|
| + { L"0\x05e9\x05bc\x05c1\x05b8" , L"0\x05e9\x05bc\x05c1\x05b8" },
|
| + { L"0\x05e9\x05bc\x05c1\x05b8" L"ab" , L"0\x05e9\x05bc\x2026" },
|
| + { L"01\x05e9\x05bc\x05c1\x05b8" L"ab" , L"01\x05e9\x2026" },
|
| + { L"012\x05e9\x05bc\x05c1\x05b8" L"ab" , L"012\x2026" },
|
| + { L"012\xF0\x9D\x84\x9E" , L"012\xF0\x2026" },
|
| + };
|
| +
|
| + 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 = 0; i < ARRAYSIZE_UNSAFE(cases); i++) {
|
| + expected_render_text->SetText(WideToUTF16(cases[i].layout_text));
|
| + int expected_width = expected_render_text->GetContentWidth();
|
| + render_text->SetText(WideToUTF16(cases[i].text));
|
| +#if defined(OS_WIN)
|
| + // TODO(skanuj): It seems in some cases (on Windows XP), the original text
|
| + // is shorter than the elided text. Those cases should be modified by
|
| + // adding extra chars in the end. Currently this problem happens for the
|
| + // following test case:
|
| + // { L"012\xF0\x9D\x84\x9E" , L"012\xF0\x2026" },
|
| + int original_width = render_text->GetContentWidth();
|
| + if ((base::win::GetVersion() < base::win::VERSION_VISTA) &&
|
| + (expected_width >= original_width))
|
| + continue;
|
| +#endif
|
| + render_text->SetDisplayRect(gfx::Rect(0, 0, expected_width, 100));
|
| + EXPECT_EQ(WideToUTF16(cases[i].text), 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;
|
|
|