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

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

Issue 8142026: Revert 104076 - Change std::wstring to string16 for views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 months 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 | « views/controls/label.cc ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 23 matching lines...) Expand all
34 string16 font_name(ASCIIToUTF16("arial")); 34 string16 font_name(ASCIIToUTF16("arial"));
35 gfx::Font font(font_name, 30); 35 gfx::Font font(font_name, 30);
36 label.SetFont(font); 36 label.SetFont(font);
37 gfx::Font font_used = label.font(); 37 gfx::Font font_used = label.font();
38 EXPECT_EQ(font_name, font_used.GetFontName()); 38 EXPECT_EQ(font_name, font_used.GetFontName());
39 EXPECT_EQ(30, font_used.GetFontSize()); 39 EXPECT_EQ(30, font_used.GetFontSize());
40 } 40 }
41 41
42 TEST(LabelTest, TextProperty) { 42 TEST(LabelTest, TextProperty) {
43 Label label; 43 Label label;
44 string16 test_text(ASCIIToUTF16("A random string.")); 44 std::wstring test_text(L"A random string.");
45 label.SetText(test_text); 45 label.SetText(test_text);
46 EXPECT_EQ(test_text, label.GetText()); 46 EXPECT_EQ(test_text, label.GetText());
47 } 47 }
48 48
49 TEST(LabelTest, UrlProperty) { 49 TEST(LabelTest, UrlProperty) {
50 Label label; 50 Label label;
51 std::string my_url("http://www.orkut.com/some/Random/path"); 51 std::string my_url("http://www.orkut.com/some/Random/path");
52 GURL url(my_url); 52 GURL url(my_url);
53 label.SetURL(url); 53 label.SetURL(url);
54 EXPECT_EQ(my_url, label.GetURL().spec()); 54 EXPECT_EQ(my_url, label.GetURL().spec());
55 EXPECT_EQ(UTF8ToUTF16(my_url), label.GetText()); 55 EXPECT_EQ(UTF8ToWide(my_url), label.GetText());
56 } 56 }
57 57
58 TEST(LabelTest, ColorProperty) { 58 TEST(LabelTest, ColorProperty) {
59 Label label; 59 Label label;
60 SkColor color = SkColorSetARGB(20, 40, 10, 5); 60 SkColor color = SkColorSetARGB(20, 40, 10, 5);
61 label.SetColor(color); 61 label.SetColor(color);
62 EXPECT_EQ(color, label.GetColor()); 62 EXPECT_EQ(color, label.GetColor());
63 } 63 }
64 64
65 TEST(LabelTest, AlignmentProperty) { 65 TEST(LabelTest, AlignmentProperty) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_FALSE(label.is_multi_line()); 104 EXPECT_FALSE(label.is_multi_line());
105 label.SetMultiLine(true); 105 label.SetMultiLine(true);
106 EXPECT_TRUE(label.is_multi_line()); 106 EXPECT_TRUE(label.is_multi_line());
107 label.SetMultiLine(false); 107 label.SetMultiLine(false);
108 EXPECT_FALSE(label.is_multi_line()); 108 EXPECT_FALSE(label.is_multi_line());
109 } 109 }
110 110
111 TEST(LabelTest, TooltipProperty) { 111 TEST(LabelTest, TooltipProperty) {
112 Label label; 112 Label label;
113 string16 test_text(ASCIIToUTF16("My cool string.")); 113 string16 test_text(ASCIIToUTF16("My cool string."));
114 label.SetText(test_text); 114 label.SetText(UTF16ToWideHack(test_text));
115 115
116 string16 tooltip; 116 string16 tooltip;
117 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 117 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
118 EXPECT_EQ(test_text, tooltip); 118 EXPECT_EQ(test_text, tooltip);
119 119
120 string16 tooltip_text(ASCIIToUTF16("The tooltip!")); 120 string16 tooltip_text(ASCIIToUTF16("The tooltip!"));
121 label.SetTooltipText(tooltip_text); 121 label.SetTooltipText(tooltip_text);
122 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 122 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
123 EXPECT_EQ(tooltip_text, tooltip); 123 EXPECT_EQ(tooltip_text, tooltip);
124 124
(...skipping 26 matching lines...) Expand all
151 label.SetTooltipText(tooltip_text); 151 label.SetTooltipText(tooltip_text);
152 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); 152 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip));
153 EXPECT_EQ(tooltip_text, tooltip); 153 EXPECT_EQ(tooltip_text, tooltip);
154 // Clear out the tooltip. 154 // Clear out the tooltip.
155 label.SetTooltipText(empty_text); 155 label.SetTooltipText(empty_text);
156 } 156 }
157 157
158 TEST(LabelTest, Accessibility) { 158 TEST(LabelTest, Accessibility) {
159 Label label; 159 Label label;
160 string16 test_text(ASCIIToUTF16("My special text.")); 160 string16 test_text(ASCIIToUTF16("My special text."));
161 label.SetText(test_text); 161 label.SetText(UTF16ToWideHack(test_text));
162 162
163 ui::AccessibleViewState state; 163 ui::AccessibleViewState state;
164 label.GetAccessibleState(&state); 164 label.GetAccessibleState(&state);
165 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); 165 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role);
166 EXPECT_EQ(test_text, state.name); 166 EXPECT_EQ(test_text, state.name);
167 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); 167 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state);
168 } 168 }
169 169
170 TEST(LabelTest, SingleLineSizing) { 170 TEST(LabelTest, SingleLineSizing) {
171 Label label; 171 Label label;
172 string16 test_text(ASCIIToUTF16("A not so random string in one line.")); 172 std::wstring test_text(L"A not so random string in one line.");
173 label.SetText(test_text); 173 label.SetText(test_text);
174 174
175 // GetPreferredSize 175 // GetPreferredSize
176 gfx::Size required_size = label.GetPreferredSize(); 176 gfx::Size required_size = label.GetPreferredSize();
177 EXPECT_GT(required_size.height(), kMinTextDimension); 177 EXPECT_GT(required_size.height(), kMinTextDimension);
178 EXPECT_GT(required_size.width(), kMinTextDimension); 178 EXPECT_GT(required_size.width(), kMinTextDimension);
179 179
180 // Test everything with borders. 180 // Test everything with borders.
181 gfx::Insets border(10, 20, 30, 40); 181 gfx::Insets border(10, 20, 30, 40);
182 label.set_border(Border::CreateEmptyBorder(border.top(), 182 label.set_border(Border::CreateEmptyBorder(border.top(),
183 border.left(), 183 border.left(),
184 border.bottom(), 184 border.bottom(),
185 border.right())); 185 border.right()));
186 186
187 // GetPreferredSize and borders. 187 // GetPreferredSize and borders.
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.set_focusable(false); 198 label.set_focusable(false);
199 string16 test_text( 199 std::wstring test_text(L"A random string\nwith multiple lines\nand returns!");
200 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"));
201 label.SetText(test_text); 200 label.SetText(test_text);
202 label.SetMultiLine(true); 201 label.SetMultiLine(true);
203 202
204 // GetPreferredSize 203 // GetPreferredSize
205 gfx::Size required_size = label.GetPreferredSize(); 204 gfx::Size required_size = label.GetPreferredSize();
206 EXPECT_GT(required_size.height(), kMinTextDimension); 205 EXPECT_GT(required_size.height(), kMinTextDimension);
207 EXPECT_GT(required_size.width(), kMinTextDimension); 206 EXPECT_GT(required_size.width(), kMinTextDimension);
208 207
209 // SizeToFit with unlimited width. 208 // SizeToFit with unlimited width.
210 label.SizeToFit(0); 209 label.SizeToFit(0);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 277 }
279 278
280 TEST(LabelTest, DrawSingleLineString) { 279 TEST(LabelTest, DrawSingleLineString) {
281 Label label; 280 Label label;
282 label.set_focusable(false); 281 label.set_focusable(false);
283 282
284 // 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
285 // align right really means align left. 284 // align right really means align left.
286 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); 285 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT);
287 286
288 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); 287 std::wstring test_text(L"Here's a string with no returns.");
289 label.SetText(test_text); 288 label.SetText(test_text);
290 gfx::Size required_size(label.GetPreferredSize()); 289 gfx::Size required_size(label.GetPreferredSize());
291 gfx::Size extra(22, 8); 290 gfx::Size extra(22, 8);
292 label.SetBounds(0, 291 label.SetBounds(0,
293 0, 292 0,
294 required_size.width() + extra.width(), 293 required_size.width() + extra.width(),
295 required_size.height() + extra.height()); 294 required_size.height() + extra.height());
296 295
297 // Do some basic verifications for all three alignments. 296 // Do some basic verifications for all three alignments.
298 string16 paint_text; 297 std::wstring paint_text;
299 gfx::Rect text_bounds; 298 gfx::Rect text_bounds;
300 int flags; 299 int flags;
301 300
302 // Centered text. 301 // Centered text.
303 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 302 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
304 EXPECT_EQ(test_text, paint_text); 303 EXPECT_EQ(test_text, paint_text);
305 // The text should be centered horizontally and vertically. 304 // The text should be centered horizontally and vertically.
306 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 305 EXPECT_EQ(extra.width() / 2, text_bounds.x());
307 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 306 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
308 EXPECT_EQ(required_size.width(), text_bounds.width()); 307 EXPECT_EQ(required_size.width(), text_bounds.width());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // 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
397 // multiline lables to not ellide in Linux only. 396 // multiline lables to not ellide in Linux only.
398 TEST(LabelTest, DrawMultiLineString) { 397 TEST(LabelTest, DrawMultiLineString) {
399 Label label; 398 Label label;
400 label.set_focusable(false); 399 label.set_focusable(false);
401 400
402 // 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
403 // align right really means align left. 402 // align right really means align left.
404 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT); 403 label.set_rtl_alignment_mode(Label::AUTO_DETECT_ALIGNMENT);
405 404
406 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); 405 std::wstring test_text(L"Another string\nwith returns\n\n!");
407 label.SetText(test_text); 406 label.SetText(test_text);
408 label.SetMultiLine(true); 407 label.SetMultiLine(true);
409 label.SizeToFit(0); 408 label.SizeToFit(0);
410 gfx::Size extra(50, 10); 409 gfx::Size extra(50, 10);
411 label.SetBounds(label.x(), 410 label.SetBounds(label.x(),
412 label.y(), 411 label.y(),
413 label.width() + extra.width(), 412 label.width() + extra.width(),
414 label.height() + extra.height()); 413 label.height() + extra.height());
415 414
416 // Do some basic verifications for all three alignments. 415 // Do some basic verifications for all three alignments.
417 string16 paint_text; 416 std::wstring paint_text;
418 gfx::Rect text_bounds; 417 gfx::Rect text_bounds;
419 int flags; 418 int flags;
420 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 419 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
421 EXPECT_EQ(test_text, paint_text); 420 EXPECT_EQ(test_text, paint_text);
422 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 421 EXPECT_EQ(extra.width() / 2, text_bounds.x());
423 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 422 EXPECT_EQ(extra.height() / 2, text_bounds.y());
424 EXPECT_GT(text_bounds.width(), kMinTextDimension); 423 EXPECT_GT(text_bounds.width(), kMinTextDimension);
425 EXPECT_GT(text_bounds.height(), kMinTextDimension); 424 EXPECT_GT(text_bounds.height(), kMinTextDimension);
426 int expected_flags = gfx::Canvas::MULTI_LINE | 425 int expected_flags = gfx::Canvas::MULTI_LINE |
427 gfx::Canvas::TEXT_ALIGN_CENTER | 426 gfx::Canvas::TEXT_ALIGN_CENTER |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 #endif 535 #endif
537 } 536 }
538 537
539 TEST(LabelTest, DrawSingleLineStringInRTL) { 538 TEST(LabelTest, DrawSingleLineStringInRTL) {
540 Label label; 539 Label label;
541 label.set_focusable(false); 540 label.set_focusable(false);
542 541
543 std::string locale = l10n_util::GetApplicationLocale(""); 542 std::string locale = l10n_util::GetApplicationLocale("");
544 base::i18n::SetICUDefaultLocale("he"); 543 base::i18n::SetICUDefaultLocale("he");
545 544
546 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); 545 std::wstring test_text(L"Here's a string with no returns.");
547 label.SetText(test_text); 546 label.SetText(test_text);
548 gfx::Size required_size(label.GetPreferredSize()); 547 gfx::Size required_size(label.GetPreferredSize());
549 gfx::Size extra(22, 8); 548 gfx::Size extra(22, 8);
550 label.SetBounds(0, 549 label.SetBounds(0,
551 0, 550 0,
552 required_size.width() + extra.width(), 551 required_size.width() + extra.width(),
553 required_size.height() + extra.height()); 552 required_size.height() + extra.height());
554 553
555 // Do some basic verifications for all three alignments. 554 // Do some basic verifications for all three alignments.
556 string16 paint_text; 555 std::wstring paint_text;
557 gfx::Rect text_bounds; 556 gfx::Rect text_bounds;
558 int flags; 557 int flags;
559 558
560 // Centered text. 559 // Centered text.
561 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 560 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
562 EXPECT_EQ(test_text, paint_text); 561 EXPECT_EQ(test_text, paint_text);
563 // The text should be centered horizontally and vertically. 562 // The text should be centered horizontally and vertically.
564 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 563 EXPECT_EQ(extra.width() / 2, text_bounds.x());
565 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 564 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
566 EXPECT_EQ(required_size.width(), text_bounds.width()); 565 EXPECT_EQ(required_size.width(), text_bounds.width());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // ellide multiline text. So until that can be resolved, we set all 657 // ellide multiline text. So until that can be resolved, we set all
659 // multiline lables to not ellide in Linux only. 658 // multiline lables to not ellide in Linux only.
660 TEST(LabelTest, DrawMultiLineStringInRTL) { 659 TEST(LabelTest, DrawMultiLineStringInRTL) {
661 Label label; 660 Label label;
662 label.set_focusable(false); 661 label.set_focusable(false);
663 662
664 // Test for RTL. 663 // Test for RTL.
665 std::string locale = l10n_util::GetApplicationLocale(""); 664 std::string locale = l10n_util::GetApplicationLocale("");
666 base::i18n::SetICUDefaultLocale("he"); 665 base::i18n::SetICUDefaultLocale("he");
667 666
668 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); 667 std::wstring test_text(L"Another string\nwith returns\n\n!");
669 label.SetText(test_text); 668 label.SetText(test_text);
670 label.SetMultiLine(true); 669 label.SetMultiLine(true);
671 label.SizeToFit(0); 670 label.SizeToFit(0);
672 gfx::Size extra(50, 10); 671 gfx::Size extra(50, 10);
673 label.SetBounds(label.x(), 672 label.SetBounds(label.x(),
674 label.y(), 673 label.y(),
675 label.width() + extra.width(), 674 label.width() + extra.width(),
676 label.height() + extra.height()); 675 label.height() + extra.height());
677 676
678 // Do some basic verifications for all three alignments. 677 // Do some basic verifications for all three alignments.
679 string16 paint_text; 678 std::wstring paint_text;
680 gfx::Rect text_bounds; 679 gfx::Rect text_bounds;
681 int flags; 680 int flags;
682 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 681 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
683 EXPECT_EQ(test_text, paint_text); 682 EXPECT_EQ(test_text, paint_text);
684 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 683 EXPECT_EQ(extra.width() / 2, text_bounds.x());
685 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 684 EXPECT_EQ(extra.height() / 2, text_bounds.y());
686 EXPECT_GT(text_bounds.width(), kMinTextDimension); 685 EXPECT_GT(text_bounds.width(), kMinTextDimension);
687 EXPECT_GT(text_bounds.height(), kMinTextDimension); 686 EXPECT_GT(text_bounds.height(), kMinTextDimension);
688 #if defined(OS_WIN) 687 #if defined(OS_WIN)
689 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); 688 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 gfx::Canvas::TEXT_ALIGN_LEFT | 800 gfx::Canvas::TEXT_ALIGN_LEFT |
802 gfx::Canvas::NO_ELLIPSIS, 801 gfx::Canvas::NO_ELLIPSIS,
803 flags); 802 flags);
804 #endif 803 #endif
805 804
806 // Reset Locale 805 // Reset Locale
807 base::i18n::SetICUDefaultLocale(locale); 806 base::i18n::SetICUDefaultLocale(locale);
808 } 807 }
809 808
810 } // namespace views 809 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/label.cc ('k') | views/controls/link.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698