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 #include "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 render_text->SetFontList(FontList("serif, Sans serif, 12px")); | 635 render_text->SetFontList(FontList("serif, Sans serif, 12px")); |
636 render_text->SetElideBehavior(ELIDE_TAIL); | 636 render_text->SetElideBehavior(ELIDE_TAIL); |
637 render_text->SetDisplayRect( | 637 render_text->SetDisplayRect( |
638 Rect(0, 0, expected_render_text->GetContentWidth(), 100)); | 638 Rect(0, 0, expected_render_text->GetContentWidth(), 100)); |
639 render_text->SetObscured(true); | 639 render_text->SetObscured(true); |
640 render_text->SetText(WideToUTF16(L"abcdef")); | 640 render_text->SetText(WideToUTF16(L"abcdef")); |
641 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); | 641 EXPECT_EQ(WideToUTF16(L"abcdef"), render_text->text()); |
642 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); | 642 EXPECT_EQ(WideToUTF16(L"**\x2026"), render_text->GetDisplayText()); |
643 } | 643 } |
644 | 644 |
| 645 TEST_F(RenderTextTest, ElidedEmail) { |
| 646 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 647 render_text->SetText(ASCIIToUTF16("test@example.com")); |
| 648 const gfx::Size size = render_text->GetStringSize(); |
| 649 |
| 650 const base::string16 long_email = |
| 651 ASCIIToUTF16("longemailaddresstest@example.com"); |
| 652 render_text->SetText(long_email); |
| 653 render_text->SetElideBehavior(ELIDE_EMAIL); |
| 654 render_text->SetDisplayRect(gfx::Rect(size)); |
| 655 EXPECT_GE(size.width(), render_text->GetStringSize().width()); |
| 656 EXPECT_GT(long_email.size(), render_text->GetDisplayText().size()); |
| 657 } |
| 658 |
645 TEST_F(RenderTextTest, TruncatedText) { | 659 TEST_F(RenderTextTest, TruncatedText) { |
646 struct { | 660 struct { |
647 const wchar_t* text; | 661 const wchar_t* text; |
648 const wchar_t* display_text; | 662 const wchar_t* display_text; |
649 } cases[] = { | 663 } cases[] = { |
650 // Strings shorter than the truncation length should be laid out in full. | 664 // Strings shorter than the truncation length should be laid out in full. |
651 { L"", L"" }, | 665 { L"", L"" }, |
652 { kWeak, kWeak }, | 666 { kWeak, kWeak }, |
653 { kLtr, kLtr }, | 667 { kLtr, kLtr }, |
654 { kLtrRtl, kLtrRtl }, | 668 { kLtrRtl, kLtrRtl }, |
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2872 string_size.set_width(string_size.width() / 2); | 2886 string_size.set_width(string_size.width() / 2); |
2873 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2887 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2874 render_text.EnsureLayout(); | 2888 render_text.EnsureLayout(); |
2875 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2889 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2876 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2890 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2877 EXPECT_NE(0, glyph_count); | 2891 EXPECT_NE(0, glyph_count); |
2878 } | 2892 } |
2879 #endif | 2893 #endif |
2880 | 2894 |
2881 } // namespace gfx | 2895 } // namespace gfx |
OLD | NEW |