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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 int row_count_; | 209 int row_count_; |
210 | 210 |
211 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer); | 211 DISALLOW_COPY_AND_ASSIGN(TestRectangleBuffer); |
212 }; | 212 }; |
213 | 213 |
214 } // namespace | 214 } // namespace |
215 | 215 |
216 class RenderTextTest : public testing::Test { | 216 class RenderTextTest : public testing::Test { |
217 }; | 217 }; |
218 | 218 |
219 TEST_F(RenderTextTest, AppendText) { | |
msw
2015/03/24 01:47:16
Move this test below ApplyStyles.
dschuyler
2015/03/24 19:37:08
Done.
| |
220 // Ensure AppendText maintains current text styles. | |
221 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
222 const SkColor color = SK_ColorRED; | |
223 render_text->SetColor(color); | |
msw
2015/03/24 01:47:16
This test should also ensure ranged values from Ap
| |
224 render_text->SetBaselineStyle(SUPERSCRIPT); | |
225 render_text->SetStyle(BOLD, true); | |
226 render_text->SetStyle(UNDERLINE, false); | |
227 const wchar_t* const cases[] = { L"Hello", L"", L" ", L"world" }; | |
228 size_t total_length = 0; | |
229 for (size_t i = 0; i < arraysize(cases); ++i) { | |
230 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(color)); | |
231 EXPECT_TRUE(render_text->baselines().EqualsValueForTesting(SUPERSCRIPT)); | |
232 EXPECT_TRUE(render_text->styles()[BOLD].EqualsValueForTesting(true)); | |
233 EXPECT_TRUE(render_text->styles()[UNDERLINE].EqualsValueForTesting(false)); | |
234 EXPECT_EQ(total_length, render_text->GetDisplayText().length()); | |
235 base::string16 str = WideToUTF16(cases[i]); | |
236 render_text->AppendText(str); | |
237 total_length += str.length(); | |
238 EXPECT_EQ(total_length, render_text->GetDisplayText().length()); | |
239 } | |
240 const base::string16 result_string = ASCIIToUTF16("Hello world"); | |
241 EXPECT_EQ(render_text->GetDisplayText(), result_string); | |
242 } | |
243 | |
219 TEST_F(RenderTextTest, DefaultStyles) { | 244 TEST_F(RenderTextTest, DefaultStyles) { |
220 // Check the default styles applied to new instances and adjusted text. | 245 // Check the default styles applied to new instances and adjusted text. |
221 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 246 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
222 EXPECT_TRUE(render_text->text().empty()); | 247 EXPECT_TRUE(render_text->text().empty()); |
223 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; | 248 const wchar_t* const cases[] = { kWeak, kLtr, L"Hello", kRtl, L"", L"" }; |
224 for (size_t i = 0; i < arraysize(cases); ++i) { | 249 for (size_t i = 0; i < arraysize(cases); ++i) { |
225 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); | 250 EXPECT_TRUE(render_text->colors().EqualsValueForTesting(SK_ColorBLACK)); |
226 EXPECT_TRUE( | 251 EXPECT_TRUE( |
227 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); | 252 render_text->baselines().EqualsValueForTesting(NORMAL_BASELINE)); |
228 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) | 253 for (size_t style = 0; style < NUM_TEXT_STYLES; ++style) |
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2822 string_size.set_width(string_size.width() / 2); | 2847 string_size.set_width(string_size.width() / 2); |
2823 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2848 render_text.SetDisplayRect(gfx::Rect(string_size)); |
2824 render_text.EnsureLayout(); | 2849 render_text.EnsureLayout(); |
2825 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2850 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
2826 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2851 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
2827 EXPECT_NE(0, glyph_count); | 2852 EXPECT_NE(0, glyph_count); |
2828 } | 2853 } |
2829 #endif | 2854 #endif |
2830 | 2855 |
2831 } // namespace gfx | 2856 } // namespace gfx |
OLD | NEW |