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

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

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/controls/link.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/controls/label.h" 5 #include "ui/views/controls/label.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
(...skipping 21 matching lines...) Expand all
32 std::string font_name("arial"); 32 std::string font_name("arial");
33 gfx::Font font(font_name, 30); 33 gfx::Font font(font_name, 30);
34 label.SetFontList(gfx::FontList(font)); 34 label.SetFontList(gfx::FontList(font));
35 gfx::Font font_used = label.font_list().GetPrimaryFont(); 35 gfx::Font font_used = label.font_list().GetPrimaryFont();
36 EXPECT_EQ(font_name, font_used.GetFontName()); 36 EXPECT_EQ(font_name, font_used.GetFontName());
37 EXPECT_EQ(30, font_used.GetFontSize()); 37 EXPECT_EQ(30, font_used.GetFontSize());
38 } 38 }
39 39
40 TEST(LabelTest, TextProperty) { 40 TEST(LabelTest, TextProperty) {
41 Label label; 41 Label label;
42 string16 test_text(ASCIIToUTF16("A random string.")); 42 base::string16 test_text(ASCIIToUTF16("A random string."));
43 label.SetText(test_text); 43 label.SetText(test_text);
44 EXPECT_EQ(test_text, label.text()); 44 EXPECT_EQ(test_text, label.text());
45 } 45 }
46 46
47 TEST(LabelTest, ColorProperty) { 47 TEST(LabelTest, ColorProperty) {
48 Label label; 48 Label label;
49 SkColor color = SkColorSetARGB(20, 40, 10, 5); 49 SkColor color = SkColorSetARGB(20, 40, 10, 5);
50 label.SetAutoColorReadabilityEnabled(false); 50 label.SetAutoColorReadabilityEnabled(false);
51 label.SetEnabledColor(color); 51 label.SetEnabledColor(color);
52 EXPECT_EQ(color, label.enabled_color()); 52 EXPECT_EQ(color, label.enabled_color());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 Label label; 91 Label label;
92 EXPECT_FALSE(label.is_multi_line()); 92 EXPECT_FALSE(label.is_multi_line());
93 label.SetMultiLine(true); 93 label.SetMultiLine(true);
94 EXPECT_TRUE(label.is_multi_line()); 94 EXPECT_TRUE(label.is_multi_line());
95 label.SetMultiLine(false); 95 label.SetMultiLine(false);
96 EXPECT_FALSE(label.is_multi_line()); 96 EXPECT_FALSE(label.is_multi_line());
97 } 97 }
98 98
99 TEST(LabelTest, TooltipProperty) { 99 TEST(LabelTest, TooltipProperty) {
100 Label label; 100 Label label;
101 string16 test_text(ASCIIToUTF16("My cool string.")); 101 base::string16 test_text(ASCIIToUTF16("My cool string."));
102 label.SetText(test_text); 102 label.SetText(test_text);
103 103
104 string16 tooltip; 104 base::string16 tooltip;
105 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 105 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
106 EXPECT_EQ(test_text, tooltip); 106 EXPECT_EQ(test_text, tooltip);
107 107
108 string16 tooltip_text(ASCIIToUTF16("The tooltip!")); 108 base::string16 tooltip_text(ASCIIToUTF16("The tooltip!"));
109 label.SetTooltipText(tooltip_text); 109 label.SetTooltipText(tooltip_text);
110 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 110 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
111 EXPECT_EQ(tooltip_text, tooltip); 111 EXPECT_EQ(tooltip_text, tooltip);
112 112
113 string16 empty_text; 113 base::string16 empty_text;
114 label.SetTooltipText(empty_text); 114 label.SetTooltipText(empty_text);
115 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 115 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
116 EXPECT_EQ(test_text, tooltip); 116 EXPECT_EQ(test_text, tooltip);
117 117
118 // Make the label big enough to hold the text 118 // Make the label big enough to hold the text
119 // and expect there to be no tooltip. 119 // and expect there to be no tooltip.
120 label.SetBounds(0, 0, 1000, 40); 120 label.SetBounds(0, 0, 1000, 40);
121 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); 121 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip));
122 122
123 // Verify that setting the tooltip still shows it. 123 // Verify that setting the tooltip still shows it.
(...skipping 14 matching lines...) Expand all
138 // Verify that setting the tooltip still shows it. 138 // Verify that setting the tooltip still shows it.
139 label.SetTooltipText(tooltip_text); 139 label.SetTooltipText(tooltip_text);
140 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 140 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
141 EXPECT_EQ(tooltip_text, tooltip); 141 EXPECT_EQ(tooltip_text, tooltip);
142 // Clear out the tooltip. 142 // Clear out the tooltip.
143 label.SetTooltipText(empty_text); 143 label.SetTooltipText(empty_text);
144 } 144 }
145 145
146 TEST(LabelTest, Accessibility) { 146 TEST(LabelTest, Accessibility) {
147 Label label; 147 Label label;
148 string16 test_text(ASCIIToUTF16("My special text.")); 148 base::string16 test_text(ASCIIToUTF16("My special text."));
149 label.SetText(test_text); 149 label.SetText(test_text);
150 150
151 ui::AccessibleViewState state; 151 ui::AccessibleViewState state;
152 label.GetAccessibleState(&state); 152 label.GetAccessibleState(&state);
153 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); 153 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role);
154 EXPECT_EQ(test_text, state.name); 154 EXPECT_EQ(test_text, state.name);
155 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); 155 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state);
156 } 156 }
157 157
158 TEST(LabelTest, SingleLineSizing) { 158 TEST(LabelTest, SingleLineSizing) {
159 Label label; 159 Label label;
160 string16 test_text(ASCIIToUTF16("A not so random string in one line.")); 160 base::string16 test_text(ASCIIToUTF16("A not so random string in one line."));
161 label.SetText(test_text); 161 label.SetText(test_text);
162 162
163 // GetPreferredSize 163 // GetPreferredSize
164 gfx::Size required_size = label.GetPreferredSize(); 164 gfx::Size required_size = label.GetPreferredSize();
165 EXPECT_GT(required_size.height(), kMinTextDimension); 165 EXPECT_GT(required_size.height(), kMinTextDimension);
166 EXPECT_GT(required_size.width(), kMinTextDimension); 166 EXPECT_GT(required_size.width(), kMinTextDimension);
167 167
168 // Test everything with borders. 168 // Test everything with borders.
169 gfx::Insets border(10, 20, 30, 40); 169 gfx::Insets border(10, 20, 30, 40);
170 label.set_border(Border::CreateEmptyBorder(border.top(), 170 label.set_border(Border::CreateEmptyBorder(border.top(),
171 border.left(), 171 border.left(),
172 border.bottom(), 172 border.bottom(),
173 border.right())); 173 border.right()));
174 174
175 // GetPreferredSize and borders. 175 // GetPreferredSize and borders.
176 label.SetBounds(0, 0, 0, 0); 176 label.SetBounds(0, 0, 0, 0);
177 gfx::Size required_size_with_border = label.GetPreferredSize(); 177 gfx::Size required_size_with_border = label.GetPreferredSize();
178 EXPECT_EQ(required_size_with_border.height(), 178 EXPECT_EQ(required_size_with_border.height(),
179 required_size.height() + border.height()); 179 required_size.height() + border.height());
180 EXPECT_EQ(required_size_with_border.width(), 180 EXPECT_EQ(required_size_with_border.width(),
181 required_size.width() + border.width()); 181 required_size.width() + border.width());
182 } 182 }
183 183
184 TEST(LabelTest, MultilineSmallAvailableWidthSizing) { 184 TEST(LabelTest, MultilineSmallAvailableWidthSizing) {
185 Label label; 185 Label label;
186 string16 test_text(ASCIIToUTF16("Too Wide.")); 186 base::string16 test_text(ASCIIToUTF16("Too Wide."));
187 187
188 label.SetMultiLine(true); 188 label.SetMultiLine(true);
189 label.SetAllowCharacterBreak(true); 189 label.SetAllowCharacterBreak(true);
190 label.SetElideBehavior(Label::ELIDE_AT_END); 190 label.SetElideBehavior(Label::ELIDE_AT_END);
191 label.SetText(test_text); 191 label.SetText(test_text);
192 192
193 // Check that Label can be laid out at a variety of small sizes, 193 // Check that Label can be laid out at a variety of small sizes,
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.SetFocusable(false); 204 label.SetFocusable(false);
205 string16 test_text( 205 base::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
215 // SizeToFit with unlimited width. 215 // SizeToFit with unlimited width.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 required_size.height() + border.height()); 281 required_size.height() + border.height());
282 EXPECT_EQ(required_size_with_border.width(), 282 EXPECT_EQ(required_size_with_border.width(),
283 required_size.width() + border.width()); 283 required_size.width() + border.width());
284 } 284 }
285 285
286 TEST(LabelTest, AutoDetectDirectionality) { 286 TEST(LabelTest, AutoDetectDirectionality) {
287 Label label; 287 Label label;
288 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); 288 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
289 289
290 // Test text starts with RTL character. 290 // Test text starts with RTL character.
291 string16 test_text(WideToUTF16(L" \x5d0\x5d1\x5d2 abc")); 291 base::string16 test_text(WideToUTF16(L" \x5d0\x5d1\x5d2 abc"));
292 label.SetText(test_text); 292 label.SetText(test_text);
293 gfx::Size required_size(label.GetPreferredSize()); 293 gfx::Size required_size(label.GetPreferredSize());
294 gfx::Size extra(22, 8); 294 gfx::Size extra(22, 8);
295 label.SetBounds(0, 295 label.SetBounds(0,
296 0, 296 0,
297 required_size.width() + extra.width(), 297 required_size.width() + extra.width(),
298 required_size.height() + extra.height()); 298 required_size.height() + extra.height());
299 299
300 string16 paint_text; 300 base::string16 paint_text;
301 gfx::Rect text_bounds; 301 gfx::Rect text_bounds;
302 int flags; 302 int flags;
303 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 303 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
304 EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, 304 EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY,
305 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | 305 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY |
306 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); 306 gfx::Canvas::FORCE_LTR_DIRECTIONALITY));
307 307
308 // Test text starts with LTR character. 308 // Test text starts with LTR character.
309 test_text = (WideToUTF16(L"ltr \x5d0\x5d1\x5d2 abc")); 309 test_text = (WideToUTF16(L"ltr \x5d0\x5d1\x5d2 abc"));
310 label.SetText(test_text); 310 label.SetText(test_text);
(...skipping 10 matching lines...) Expand all
321 } 321 }
322 322
323 TEST(LabelTest, DrawSingleLineString) { 323 TEST(LabelTest, DrawSingleLineString) {
324 Label label; 324 Label label;
325 label.SetFocusable(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 base::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,
336 0, 336 0,
337 required_size.width() + extra.width(), 337 required_size.width() + extra.width(),
338 required_size.height() + extra.height()); 338 required_size.height() + extra.height());
339 339
340 // Do some basic verifications for all three alignments. 340 // Do some basic verifications for all three alignments.
341 string16 paint_text; 341 base::string16 paint_text;
342 gfx::Rect text_bounds; 342 gfx::Rect text_bounds;
343 int flags; 343 int flags;
344 344
345 // Centered text. 345 // Centered text.
346 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 346 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
347 EXPECT_EQ(test_text, paint_text); 347 EXPECT_EQ(test_text, paint_text);
348 // The text should be centered horizontally and vertically. 348 // The text should be centered horizontally and vertically.
349 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 349 EXPECT_EQ(extra.width() / 2, text_bounds.x());
350 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 350 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
351 EXPECT_EQ(required_size.width(), text_bounds.width()); 351 EXPECT_EQ(required_size.width(), text_bounds.width());
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.SetFocusable(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 base::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);
472 label.SetBounds(label.x(), 472 label.SetBounds(label.x(),
473 label.y(), 473 label.y(),
474 label.width() + extra.width(), 474 label.width() + extra.width(),
475 label.height() + extra.height()); 475 label.height() + extra.height());
476 476
477 // Do some basic verifications for all three alignments. 477 // Do some basic verifications for all three alignments.
478 string16 paint_text; 478 base::string16 paint_text;
479 gfx::Rect text_bounds; 479 gfx::Rect text_bounds;
480 int flags; 480 int flags;
481 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 481 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
482 EXPECT_EQ(test_text, paint_text); 482 EXPECT_EQ(test_text, paint_text);
483 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 483 EXPECT_EQ(extra.width() / 2, text_bounds.x());
484 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 484 EXPECT_EQ(extra.height() / 2, text_bounds.y());
485 EXPECT_GT(text_bounds.width(), kMinTextDimension); 485 EXPECT_GT(text_bounds.width(), kMinTextDimension);
486 EXPECT_GT(text_bounds.height(), kMinTextDimension); 486 EXPECT_GT(text_bounds.height(), kMinTextDimension);
487 int expected_flags = gfx::Canvas::MULTI_LINE | 487 int expected_flags = gfx::Canvas::MULTI_LINE |
488 gfx::Canvas::TEXT_ALIGN_CENTER | 488 gfx::Canvas::TEXT_ALIGN_CENTER |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 #endif 597 #endif
598 } 598 }
599 599
600 TEST(LabelTest, DrawSingleLineStringInRTL) { 600 TEST(LabelTest, DrawSingleLineStringInRTL) {
601 Label label; 601 Label label;
602 label.SetFocusable(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 base::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,
613 required_size.width() + extra.width(), 613 required_size.width() + extra.width(),
614 required_size.height() + extra.height()); 614 required_size.height() + extra.height());
615 615
616 // Do some basic verifications for all three alignments. 616 // Do some basic verifications for all three alignments.
617 string16 paint_text; 617 base::string16 paint_text;
618 gfx::Rect text_bounds; 618 gfx::Rect text_bounds;
619 int flags; 619 int flags;
620 620
621 // Centered text. 621 // Centered text.
622 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 622 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
623 EXPECT_EQ(test_text, paint_text); 623 EXPECT_EQ(test_text, paint_text);
624 // The text should be centered horizontally and vertically. 624 // The text should be centered horizontally and vertically.
625 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 625 EXPECT_EQ(extra.width() / 2, text_bounds.x());
626 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 626 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
627 EXPECT_EQ(required_size.width(), text_bounds.width()); 627 EXPECT_EQ(required_size.width(), text_bounds.width());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.SetFocusable(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 base::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);
752 label.SetBounds(label.x(), 752 label.SetBounds(label.x(),
753 label.y(), 753 label.y(),
754 label.width() + extra.width(), 754 label.width() + extra.width(),
755 label.height() + extra.height()); 755 label.height() + extra.height());
756 756
757 // Do some basic verifications for all three alignments. 757 // Do some basic verifications for all three alignments.
758 string16 paint_text; 758 base::string16 paint_text;
759 gfx::Rect text_bounds; 759 gfx::Rect text_bounds;
760 int flags; 760 int flags;
761 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 761 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
762 EXPECT_EQ(test_text, paint_text); 762 EXPECT_EQ(test_text, paint_text);
763 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 763 EXPECT_EQ(extra.width() / 2, text_bounds.x());
764 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 764 EXPECT_EQ(extra.height() / 2, text_bounds.y());
765 EXPECT_GT(text_bounds.width(), kMinTextDimension); 765 EXPECT_GT(text_bounds.width(), kMinTextDimension);
766 EXPECT_GT(text_bounds.height(), kMinTextDimension); 766 EXPECT_GT(text_bounds.height(), kMinTextDimension);
767 #if defined(OS_WIN) 767 #if defined(OS_WIN)
768 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); 768 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags);
(...skipping 154 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
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/controls/link.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698