OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/i18n/rtl.h" | 5 #include "base/i18n/rtl.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 label.SetBounds(0, 0, 0, 0); | 188 label.SetBounds(0, 0, 0, 0); |
189 gfx::Size required_size_with_border = label.GetPreferredSize(); | 189 gfx::Size required_size_with_border = label.GetPreferredSize(); |
190 EXPECT_EQ(required_size_with_border.height(), | 190 EXPECT_EQ(required_size_with_border.height(), |
191 required_size.height() + border.height()); | 191 required_size.height() + border.height()); |
192 EXPECT_EQ(required_size_with_border.width(), | 192 EXPECT_EQ(required_size_with_border.width(), |
193 required_size.width() + border.width()); | 193 required_size.width() + border.width()); |
194 } | 194 } |
195 | 195 |
196 TEST(LabelTest, MultiLineSizing) { | 196 TEST(LabelTest, MultiLineSizing) { |
197 Label label; | 197 Label label; |
198 label.SetFocusable(false); | 198 label.set_focusable(false); |
199 std::wstring test_text(L"A random string\nwith multiple lines\nand returns!"); | 199 std::wstring test_text(L"A random string\nwith multiple lines\nand returns!"); |
200 label.SetText(test_text); | 200 label.SetText(test_text); |
201 label.SetMultiLine(true); | 201 label.SetMultiLine(true); |
202 | 202 |
203 // GetPreferredSize | 203 // GetPreferredSize |
204 gfx::Size required_size = label.GetPreferredSize(); | 204 gfx::Size required_size = label.GetPreferredSize(); |
205 EXPECT_GT(required_size.height(), kMinTextDimension); | 205 EXPECT_GT(required_size.height(), kMinTextDimension); |
206 EXPECT_GT(required_size.width(), kMinTextDimension); | 206 EXPECT_GT(required_size.width(), kMinTextDimension); |
207 | 207 |
208 // SizeToFit with unlimited width. | 208 // SizeToFit with unlimited width. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 label.SetBounds(0, 0, 0, 0); | 271 label.SetBounds(0, 0, 0, 0); |
272 gfx::Size required_size_with_border = label.GetPreferredSize(); | 272 gfx::Size required_size_with_border = label.GetPreferredSize(); |
273 EXPECT_EQ(required_size_with_border.height(), | 273 EXPECT_EQ(required_size_with_border.height(), |
274 required_size.height() + border.height()); | 274 required_size.height() + border.height()); |
275 EXPECT_EQ(required_size_with_border.width(), | 275 EXPECT_EQ(required_size_with_border.width(), |
276 required_size.width() + border.width()); | 276 required_size.width() + border.width()); |
277 } | 277 } |
278 | 278 |
279 TEST(LabelTest, DrawSingleLineString) { | 279 TEST(LabelTest, DrawSingleLineString) { |
280 Label label; | 280 Label label; |
281 label.SetFocusable(false); | 281 label.set_focusable(false); |
282 | 282 |
283 // Turn off mirroring so that we don't need to figure out if | 283 // Turn off mirroring so that we don't need to figure out if |
284 // align right really means align left. | 284 // align right really means align left. |
285 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); | 285 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); |
286 | 286 |
287 std::wstring test_text(L"Here's a string with no returns."); | 287 std::wstring test_text(L"Here's a string with no returns."); |
288 label.SetText(test_text); | 288 label.SetText(test_text); |
289 gfx::Size required_size(label.GetPreferredSize()); | 289 gfx::Size required_size(label.GetPreferredSize()); |
290 gfx::Size extra(22, 8); | 290 gfx::Size extra(22, 8); |
291 label.SetBounds(0, | 291 label.SetBounds(0, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 EXPECT_EQ(required_size.width(), text_bounds.width()); | 389 EXPECT_EQ(required_size.width(), text_bounds.width()); |
390 EXPECT_EQ(required_size.height(), text_bounds.height()); | 390 EXPECT_EQ(required_size.height(), text_bounds.height()); |
391 EXPECT_EQ(0, flags); | 391 EXPECT_EQ(0, flags); |
392 } | 392 } |
393 | 393 |
394 // On Linux the underlying pango routines require a max height in order to | 394 // On Linux the underlying pango routines require a max height in order to |
395 // ellide multiline text. So until that can be resolved, we set all | 395 // ellide multiline text. So until that can be resolved, we set all |
396 // multiline lables to not ellide in Linux only. | 396 // multiline lables to not ellide in Linux only. |
397 TEST(LabelTest, DrawMultiLineString) { | 397 TEST(LabelTest, DrawMultiLineString) { |
398 Label label; | 398 Label label; |
399 label.SetFocusable(false); | 399 label.set_focusable(false); |
400 | 400 |
401 // Turn off mirroring so that we don't need to figure out if | 401 // Turn off mirroring so that we don't need to figure out if |
402 // align right really means align left. | 402 // align right really means align left. |
403 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); | 403 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); |
404 | 404 |
405 std::wstring test_text(L"Another string\nwith returns\n\n!"); | 405 std::wstring test_text(L"Another string\nwith returns\n\n!"); |
406 label.SetText(test_text); | 406 label.SetText(test_text); |
407 label.SetMultiLine(true); | 407 label.SetMultiLine(true); |
408 label.SizeToFit(0); | 408 label.SizeToFit(0); |
409 gfx::Size extra(50, 10); | 409 gfx::Size extra(50, 10); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 EXPECT_EQ( | 536 EXPECT_EQ( |
537 gfx::Canvas::MULTI_LINE | | 537 gfx::Canvas::MULTI_LINE | |
538 gfx::Canvas::TEXT_ALIGN_RIGHT | | 538 gfx::Canvas::TEXT_ALIGN_RIGHT | |
539 gfx::Canvas::NO_ELLIPSIS, | 539 gfx::Canvas::NO_ELLIPSIS, |
540 flags); | 540 flags); |
541 #endif | 541 #endif |
542 } | 542 } |
543 | 543 |
544 TEST(LabelTest, DrawSingleLineStringInRTL) { | 544 TEST(LabelTest, DrawSingleLineStringInRTL) { |
545 Label label; | 545 Label label; |
546 label.SetFocusable(false); | 546 label.set_focusable(false); |
547 | 547 |
548 std::string locale = l10n_util::GetApplicationLocale(""); | 548 std::string locale = l10n_util::GetApplicationLocale(""); |
549 base::i18n::SetICUDefaultLocale("he"); | 549 base::i18n::SetICUDefaultLocale("he"); |
550 | 550 |
551 std::wstring test_text(L"Here's a string with no returns."); | 551 std::wstring test_text(L"Here's a string with no returns."); |
552 label.SetText(test_text); | 552 label.SetText(test_text); |
553 gfx::Size required_size(label.GetPreferredSize()); | 553 gfx::Size required_size(label.GetPreferredSize()); |
554 gfx::Size extra(22, 8); | 554 gfx::Size extra(22, 8); |
555 label.SetBounds(0, | 555 label.SetBounds(0, |
556 0, | 556 0, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 657 |
658 // Reset locale. | 658 // Reset locale. |
659 base::i18n::SetICUDefaultLocale(locale); | 659 base::i18n::SetICUDefaultLocale(locale); |
660 } | 660 } |
661 | 661 |
662 // On Linux the underlying pango routines require a max height in order to | 662 // On Linux the underlying pango routines require a max height in order to |
663 // ellide multiline text. So until that can be resolved, we set all | 663 // ellide multiline text. So until that can be resolved, we set all |
664 // multiline lables to not ellide in Linux only. | 664 // multiline lables to not ellide in Linux only. |
665 TEST(LabelTest, DrawMultiLineStringInRTL) { | 665 TEST(LabelTest, DrawMultiLineStringInRTL) { |
666 Label label; | 666 Label label; |
667 label.SetFocusable(false); | 667 label.set_focusable(false); |
668 | 668 |
669 // Test for RTL. | 669 // Test for RTL. |
670 std::string locale = l10n_util::GetApplicationLocale(""); | 670 std::string locale = l10n_util::GetApplicationLocale(""); |
671 base::i18n::SetICUDefaultLocale("he"); | 671 base::i18n::SetICUDefaultLocale("he"); |
672 | 672 |
673 std::wstring test_text(L"Another string\nwith returns\n\n!"); | 673 std::wstring test_text(L"Another string\nwith returns\n\n!"); |
674 label.SetText(test_text); | 674 label.SetText(test_text); |
675 label.SetMultiLine(true); | 675 label.SetMultiLine(true); |
676 label.SizeToFit(0); | 676 label.SizeToFit(0); |
677 gfx::Size extra(50, 10); | 677 gfx::Size extra(50, 10); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 gfx::Canvas::TEXT_ALIGN_LEFT | | 806 gfx::Canvas::TEXT_ALIGN_LEFT | |
807 gfx::Canvas::NO_ELLIPSIS, | 807 gfx::Canvas::NO_ELLIPSIS, |
808 flags); | 808 flags); |
809 #endif | 809 #endif |
810 | 810 |
811 // Reset Locale | 811 // Reset Locale |
812 base::i18n::SetICUDefaultLocale(locale); | 812 base::i18n::SetICUDefaultLocale(locale); |
813 } | 813 } |
814 | 814 |
815 } // namespace views | 815 } // namespace views |
OLD | NEW |