Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ui/views/controls/label_unittest.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted to common code into FocusManager class Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // splitting the words into up to one character per line if necessary. 194 // splitting the words into up to one character per line if necessary.
195 // Incorrect word splitting may cause infinite loops in text layout. 195 // Incorrect word splitting may cause infinite loops in text layout.
196 gfx::Size required_size = label.GetPreferredSize(); 196 gfx::Size required_size = label.GetPreferredSize();
197 for (int i = 1; i < required_size.width(); ++i) { 197 for (int i = 1; i < required_size.width(); ++i) {
198 EXPECT_GT(label.GetHeightForWidth(i), 0); 198 EXPECT_GT(label.GetHeightForWidth(i), 0);
199 } 199 }
200 } 200 }
201 201
202 TEST(LabelTest, MultiLineSizing) { 202 TEST(LabelTest, MultiLineSizing) {
203 Label label; 203 Label label;
204 label.set_focusable(false); 204 label.SetFocusable(false);
205 string16 test_text( 205 string16 test_text(
206 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); 206 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"));
207 label.SetText(test_text); 207 label.SetText(test_text);
208 label.SetMultiLine(true); 208 label.SetMultiLine(true);
209 209
210 // GetPreferredSize 210 // GetPreferredSize
211 gfx::Size required_size = label.GetPreferredSize(); 211 gfx::Size required_size = label.GetPreferredSize();
212 EXPECT_GT(required_size.height(), kMinTextDimension); 212 EXPECT_GT(required_size.height(), kMinTextDimension);
213 EXPECT_GT(required_size.width(), kMinTextDimension); 213 EXPECT_GT(required_size.width(), kMinTextDimension);
214 214
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 required_size.height() + extra.height()); 315 required_size.height() + extra.height());
316 316
317 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 317 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
318 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, 318 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY,
319 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | 319 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY |
320 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); 320 gfx::Canvas::FORCE_LTR_DIRECTIONALITY));
321 } 321 }
322 322
323 TEST(LabelTest, DrawSingleLineString) { 323 TEST(LabelTest, DrawSingleLineString) {
324 Label label; 324 Label label;
325 label.set_focusable(false); 325 label.SetFocusable(false);
326 326
327 // Turn off mirroring so that we don't need to figure out if 327 // Turn off mirroring so that we don't need to figure out if
328 // align right really means align left. 328 // align right really means align left.
329 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); 329 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
330 330
331 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); 331 string16 test_text(ASCIIToUTF16("Here's a string with no returns."));
332 label.SetText(test_text); 332 label.SetText(test_text);
333 gfx::Size required_size(label.GetPreferredSize()); 333 gfx::Size required_size(label.GetPreferredSize());
334 gfx::Size extra(22, 8); 334 gfx::Size extra(22, 8);
335 label.SetBounds(0, 335 label.SetBounds(0,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | 451 flags & (gfx::Canvas::TEXT_ALIGN_LEFT |
452 gfx::Canvas::TEXT_ALIGN_CENTER | 452 gfx::Canvas::TEXT_ALIGN_CENTER |
453 gfx::Canvas::TEXT_ALIGN_RIGHT)); 453 gfx::Canvas::TEXT_ALIGN_RIGHT));
454 } 454 }
455 455
456 // On Linux the underlying pango routines require a max height in order to 456 // On Linux the underlying pango routines require a max height in order to
457 // ellide multiline text. So until that can be resolved, we set all 457 // ellide multiline text. So until that can be resolved, we set all
458 // multiline lables to not ellide in Linux only. 458 // multiline lables to not ellide in Linux only.
459 TEST(LabelTest, DrawMultiLineString) { 459 TEST(LabelTest, DrawMultiLineString) {
460 Label label; 460 Label label;
461 label.set_focusable(false); 461 label.SetFocusable(false);
462 462
463 // Turn off mirroring so that we don't need to figure out if 463 // Turn off mirroring so that we don't need to figure out if
464 // align right really means align left. 464 // align right really means align left.
465 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); 465 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
466 466
467 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); 467 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!"));
468 label.SetText(test_text); 468 label.SetText(test_text);
469 label.SetMultiLine(true); 469 label.SetMultiLine(true);
470 label.SizeToFit(0); 470 label.SizeToFit(0);
471 gfx::Size extra(50, 10); 471 gfx::Size extra(50, 10);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; 592 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
593 #if defined(OS_WIN) 593 #if defined(OS_WIN)
594 EXPECT_EQ(expected_flags, flags); 594 EXPECT_EQ(expected_flags, flags);
595 #else 595 #else
596 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 596 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
597 #endif 597 #endif
598 } 598 }
599 599
600 TEST(LabelTest, DrawSingleLineStringInRTL) { 600 TEST(LabelTest, DrawSingleLineStringInRTL) {
601 Label label; 601 Label label;
602 label.set_focusable(false); 602 label.SetFocusable(false);
603 603
604 std::string locale = l10n_util::GetApplicationLocale(""); 604 std::string locale = l10n_util::GetApplicationLocale("");
605 base::i18n::SetICUDefaultLocale("he"); 605 base::i18n::SetICUDefaultLocale("he");
606 606
607 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); 607 string16 test_text(ASCIIToUTF16("Here's a string with no returns."));
608 label.SetText(test_text); 608 label.SetText(test_text);
609 gfx::Size required_size(label.GetPreferredSize()); 609 gfx::Size required_size(label.GetPreferredSize());
610 gfx::Size extra(22, 8); 610 gfx::Size extra(22, 8);
611 label.SetBounds(0, 611 label.SetBounds(0,
612 0, 612 0,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 731
732 // Reset locale. 732 // Reset locale.
733 base::i18n::SetICUDefaultLocale(locale); 733 base::i18n::SetICUDefaultLocale(locale);
734 } 734 }
735 735
736 // On Linux the underlying pango routines require a max height in order to 736 // On Linux the underlying pango routines require a max height in order to
737 // ellide multiline text. So until that can be resolved, we set all 737 // ellide multiline text. So until that can be resolved, we set all
738 // multiline lables to not ellide in Linux only. 738 // multiline lables to not ellide in Linux only.
739 TEST(LabelTest, DrawMultiLineStringInRTL) { 739 TEST(LabelTest, DrawMultiLineStringInRTL) {
740 Label label; 740 Label label;
741 label.set_focusable(false); 741 label.SetFocusable(false);
742 742
743 // Test for RTL. 743 // Test for RTL.
744 std::string locale = l10n_util::GetApplicationLocale(""); 744 std::string locale = l10n_util::GetApplicationLocale("");
745 base::i18n::SetICUDefaultLocale("he"); 745 base::i18n::SetICUDefaultLocale("he");
746 746
747 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); 747 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!"));
748 label.SetText(test_text); 748 label.SetText(test_text);
749 label.SetMultiLine(true); 749 label.SetMultiLine(true);
750 label.SizeToFit(0); 750 label.SizeToFit(0);
751 gfx::Size extra(50, 10); 751 gfx::Size extra(50, 10);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); 923 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51)));
924 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); 924 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20)));
925 925
926 // GetTooltipHandlerForPoint works should work in child bounds. 926 // GetTooltipHandlerForPoint works should work in child bounds.
927 label.SetBounds(2, 2, 10, 10); 927 label.SetBounds(2, 2, 10, 10);
928 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); 928 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5)));
929 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); 929 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11)));
930 } 930 }
931 931
932 } // namespace views 932 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698