Index: ui/gfx/render_text_unittest.cc |
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc |
index ffa19174d28c18fa9a3b70e4a512778253a4d318..b06a04f21ba483cd1d234041ff8096d52b99b9af 100644 |
--- a/ui/gfx/render_text_unittest.cc |
+++ b/ui/gfx/render_text_unittest.cc |
@@ -400,6 +400,74 @@ TEST_F(RenderTextTest, RevealObscuredText) { |
EXPECT_EQ(valid_expect_5_and_6, render_text->GetLayoutText()); |
} |
+TEST_F(RenderTextTest, ElidedText) { |
msw
2013/12/12 19:28:29
I think this test might be too fragile with hard-c
Anuj
2013/12/13 01:23:50
Done.
|
+ // TODO(skanuj) : Add more test cases, possibly covering styles. |
+ // To add more test cases, add a new case with large expected width. |
+ // Uncomment the log statements below and find the actual width for |
+ // layout_text, and update the test case. |
+ struct { |
+ const wchar_t* text; |
+ const wchar_t* layout_text; |
+ const int width; |
+ } cases[] = { |
+ // Strings shorter than the elision width should be laid out in full. |
+ { L"", L"" , 30}, |
msw
2013/12/12 19:28:29
nit: align the comments after the preceding entry:
Anuj
2013/12/13 01:23:50
Didn't understand.
msw
2013/12/13 01:56:08
D'oh I meant "align the commas", so that the comma
Anuj
2013/12/13 02:23:45
Done.
|
+ { kWeak, kWeak , 30}, |
+ { kLtr, kLtr , 30}, |
+ { kLtrRtl, kLtrRtl , 30}, |
+ { kLtrRtlLtr, kLtrRtlLtr , 30}, |
+ { kRtl, kRtl , 30}, |
+ { kRtlLtr, kRtlLtr , 30}, |
+ { kRtlLtrRtl, kRtlLtrRtl , 30}, |
+ // Strings as long as the elision width should be laid out in full. |
+ { L"012ab", L"012ab" , 40}, |
+ // Long strings should be elided with an ellipsis appended at the end. |
+ { L"012" L"abc", L"012a\x2026" , 44}, |
msw
2013/12/12 19:28:29
nit: align the strings within each commented secti
Anuj
2013/12/13 01:23:50
For the record, I find this column formatting insa
msw
2013/12/13 01:56:08
I think it makes reading test cases easier :)
Anuj
2013/12/13 02:23:45
Looks like I have some motivation to hack on clang
|
+ { L"012" L"ab" L"\x5d0\x5d1", L"012a\x2026" , 44}, |
+ { L"012" L"a" L"\x5d1" L"b", L"012a\x2026" , 44}, |
+ { L"01" L"\x5d0\x5d1\x5d2" L"ab", L"01\x5d0\x5d1\x2026" , 37}, |
+ { L"ab" L"\x5d0\x5d1\x5d2" L"ab", L"ab\x5d0\x5d1\x2026\x200f" , 39}, |
+ // Surrogate pairs should be elided reasonably enough. |
+ { L"0123\x0915\x093f" L"abcd", L"0123\x0915\x2026" , 50}, |
+ { L"0\x05e9\x05bc\x05c1\x05b8", L"0\x05e9\x05bc\x05c1\x05b8" , 14}, |
+ { L"0\x05e9\x05bc\x05c1\x05b8" L"ab", L"0\x05e9\x05bc\x2026" , 26}, |
+ { L"01\x05e9\x05bc\x05c1\x05b8" L"ab", L"01\x05e9\x2026" , 32}, |
+ { L"012\x05e9\x05bc\x05c1\x05b8" L"ab", L"012\x2026" , 37}, |
+ { L"012\xF0\x9D\x84\x9E", L"012\xF0\x2026" , 44}, |
+ }; |
+ |
+ 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++) { |
+ render_text->SetDisplayRect(gfx::Rect(0, 0, cases[i].width, 100)); |
+ render_text->SetText(WideToUTF16(cases[i].text)); |
+ EXPECT_EQ(WideToUTF16(cases[i].text), render_text->text()); |
+ EXPECT_LE(render_text->GetContentWidth(), cases[i].width) |
+ << "->For case " << i << ": " << cases[i].text << "\n"; |
+ EXPECT_EQ(WideToUTF16(cases[i].layout_text), render_text->GetLayoutText()) |
+ << "->For case " << i << ": " << cases[i].text << "\n"; |
+ render_text->SetText(base::string16()); |
msw
2013/12/12 19:28:29
Why is this needed?
Anuj
2013/12/13 01:23:50
To clear the layout text.
|
+ |
+ // render_text->SetDisplayRect(gfx::Rect(0, 0, 9000, 100)); |
+ // render_text->SetText(WideToUTF16(cases[i].layout_text)); |
+ // LOG(ERROR) << "Expected ContentWidth:" << render_text->GetContentWidth() |
+ // << " case: " << i << ": " << render_text->GetLayoutText(); |
+ // render_text->SetText(base::string16()); |
+ } |
+} |
+ |
+TEST_F(RenderTextTest, ElidedObscuredText) { |
+ 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, 30, 100)); |
msw
2013/12/12 19:28:29
Ditto here, consider using the width of L"**\x2026
Anuj
2013/12/13 01:23:50
Done.
|
+ 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; |