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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 #endif // defined(OS_WIN) | 1260 #endif // defined(OS_WIN) |
1261 | 1261 |
1262 TEST_F(RenderTextTest, StringSizeSanity) { | 1262 TEST_F(RenderTextTest, StringSizeSanity) { |
1263 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1263 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1264 render_text->SetText(UTF8ToUTF16("Hello World")); | 1264 render_text->SetText(UTF8ToUTF16("Hello World")); |
1265 const Size string_size = render_text->GetStringSize(); | 1265 const Size string_size = render_text->GetStringSize(); |
1266 EXPECT_GT(string_size.width(), 0); | 1266 EXPECT_GT(string_size.width(), 0); |
1267 EXPECT_GT(string_size.height(), 0); | 1267 EXPECT_GT(string_size.height(), 0); |
1268 } | 1268 } |
1269 | 1269 |
| 1270 TEST_F(RenderTextTest, StringSizeLongStrings) { |
| 1271 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1272 Size previous_string_size; |
| 1273 for (size_t length = 10; length < 1000000; length *= 10) { |
| 1274 render_text->SetText(base::string16(length, 'a')); |
| 1275 const Size string_size = render_text->GetStringSize(); |
| 1276 EXPECT_GT(string_size.width(), previous_string_size.width()); |
| 1277 EXPECT_GT(string_size.height(), 0); |
| 1278 previous_string_size = string_size; |
| 1279 } |
| 1280 } |
| 1281 |
1270 // TODO(asvitkine): This test fails because PlatformFontMac uses point font | 1282 // TODO(asvitkine): This test fails because PlatformFontMac uses point font |
1271 // sizes instead of pixel sizes like other implementations. | 1283 // sizes instead of pixel sizes like other implementations. |
1272 #if !defined(OS_MACOSX) | 1284 #if !defined(OS_MACOSX) |
1273 TEST_F(RenderTextTest, StringSizeEmptyString) { | 1285 TEST_F(RenderTextTest, StringSizeEmptyString) { |
1274 // Ascent and descent of Arial and Symbol are different on most platforms. | 1286 // Ascent and descent of Arial and Symbol are different on most platforms. |
1275 const FontList font_list("Arial,Symbol, 16px"); | 1287 const FontList font_list("Arial,Symbol, 16px"); |
1276 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1288 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
1277 render_text->SetFontList(font_list); | 1289 render_text->SetFontList(font_list); |
1278 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight())); | 1290 render_text->SetDisplayRect(Rect(0, 0, 0, font_list.GetHeight())); |
1279 | 1291 |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2120 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
2109 render_text->SetText(WideToUTF16(kTestStrings[i])); | 2121 render_text->SetText(WideToUTF16(kTestStrings[i])); |
2110 render_text->EnsureLayout(); | 2122 render_text->EnsureLayout(); |
2111 | 2123 |
2112 for (size_t j = 0; j < render_text->text().length(); ++j) | 2124 for (size_t j = 0; j < render_text->text().length(); ++j) |
2113 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); | 2125 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); |
2114 } | 2126 } |
2115 } | 2127 } |
2116 | 2128 |
2117 } // namespace gfx | 2129 } // namespace gfx |
OLD | NEW |