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

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

Issue 6121004: Remove wstring from gfx. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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/menu/menu_item_view.cc » ('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) 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 "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "base/i18n/rtl.h" 6 #include "base/i18n/rtl.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "gfx/canvas.h" 8 #include "gfx/canvas.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "views/border.h" 10 #include "views/border.h"
11 #include "views/controls/label.h" 11 #include "views/controls/label.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 // All text sizing measurements (width and height) should be greater than this. 15 // All text sizing measurements (width and height) should be greater than this.
16 const int kMinTextDimension = 4; 16 const int kMinTextDimension = 4;
17 17
18 #if defined(WIN_OS) 18 #if defined(OS_WIN)
19 // Courier is failing on linux because it's non scalable. 19 // Courier is failing on linux because it's non scalable.
20 TEST(LabelTest, FontPropertyCourier) { 20 TEST(LabelTest, FontPropertyCourier) {
21 Label label; 21 Label label;
22 std::wstring font_name(L"courier"); 22 string16 font_name(ASCIIToUTF16("courier"));
23 gfx::Font font = gfx::Font::CreateFont(font_name, 30); 23 gfx::Font font = gfx::Font::CreateFont(font_name, 30);
24 label.SetFont(font); 24 label.SetFont(font);
25 gfx::Font font_used = label.font(); 25 gfx::Font font_used = label.font();
26 EXPECT_EQ(font_name, font_used.FontName()); 26 EXPECT_EQ(font_name, font_used.FontName());
27 EXPECT_EQ(30, font_used.FontSize()); 27 EXPECT_EQ(30, font_used.FontSize());
28 } 28 }
29 #endif 29 #endif
30 30
31 TEST(LabelTest, FontPropertyArial) { 31 TEST(LabelTest, FontPropertyArial) {
32 Label label; 32 Label label;
33 std::wstring font_name(L"arial"); 33 string16 font_name(ASCIIToUTF16("arial"));
34 gfx::Font font(font_name, 30); 34 gfx::Font font(font_name, 30);
35 label.SetFont(font); 35 label.SetFont(font);
36 gfx::Font font_used = label.font(); 36 gfx::Font font_used = label.font();
37 EXPECT_EQ(font_name, font_used.GetFontName()); 37 EXPECT_EQ(font_name, font_used.GetFontName());
38 EXPECT_EQ(30, font_used.GetFontSize()); 38 EXPECT_EQ(30, font_used.GetFontSize());
39 } 39 }
40 40
41 TEST(LabelTest, TextProperty) { 41 TEST(LabelTest, TextProperty) {
42 Label label; 42 Label label;
43 std::wstring test_text(L"A random string."); 43 std::wstring test_text(L"A random string.");
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 EXPECT_GT(required_size.width(), kMinTextDimension); 207 EXPECT_GT(required_size.width(), kMinTextDimension);
208 208
209 // SizeToFit with unlimited width. 209 // SizeToFit with unlimited width.
210 label.SizeToFit(0); 210 label.SizeToFit(0);
211 int required_width = label.GetLocalBounds(true).width(); 211 int required_width = label.GetLocalBounds(true).width();
212 EXPECT_GT(required_width, kMinTextDimension); 212 EXPECT_GT(required_width, kMinTextDimension);
213 213
214 // SizeToFit with limited width. 214 // SizeToFit with limited width.
215 label.SizeToFit(required_width - 1); 215 label.SizeToFit(required_width - 1);
216 int constrained_width = label.GetLocalBounds(true).width(); 216 int constrained_width = label.GetLocalBounds(true).width();
217 #if defined(WIN_OS) 217 #if defined(OS_WIN)
218 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc) 218 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc)
219 // has to be fixed to return the size that fits to given width/height. 219 // has to be fixed to return the size that fits to given width/height.
220 EXPECT_LT(constrained_width, required_width); 220 EXPECT_LT(constrained_width, required_width);
221 #endif 221 #endif
222 EXPECT_GT(constrained_width, kMinTextDimension); 222 EXPECT_GT(constrained_width, kMinTextDimension);
223 223
224 // Change the width back to the desire width. 224 // Change the width back to the desire width.
225 label.SizeToFit(required_width); 225 label.SizeToFit(required_width);
226 EXPECT_EQ(required_width, label.GetLocalBounds(true).width()); 226 EXPECT_EQ(required_width, label.GetLocalBounds(true).width());
227 227
228 // General tests for GetHeightForWidth. 228 // General tests for GetHeightForWidth.
229 int required_height = label.GetHeightForWidth(required_width); 229 int required_height = label.GetHeightForWidth(required_width);
230 EXPECT_GT(required_height, kMinTextDimension); 230 EXPECT_GT(required_height, kMinTextDimension);
231 int height_for_constrained_width = label.GetHeightForWidth(constrained_width); 231 int height_for_constrained_width = label.GetHeightForWidth(constrained_width);
232 #if defined(WIN_OS) 232 #if defined(OS_WIN)
233 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc) 233 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc)
234 // has to be fixed to return the size that fits to given width/height. 234 // has to be fixed to return the size that fits to given width/height.
235 EXPECT_GT(height_for_constrained_width, required_height); 235 EXPECT_GT(height_for_constrained_width, required_height);
236 #endif 236 #endif
237 // Using the constrained width or the required_width - 1 should give the 237 // Using the constrained width or the required_width - 1 should give the
238 // same result for the height because the constrainted width is the tight 238 // same result for the height because the constrainted width is the tight
239 // width when given "required_width - 1" as the max width. 239 // width when given "required_width - 1" as the max width.
240 EXPECT_EQ(height_for_constrained_width, 240 EXPECT_EQ(height_for_constrained_width,
241 label.GetHeightForWidth(required_width - 1)); 241 label.GetHeightForWidth(required_width - 1));
242 242
(...skipping 11 matching lines...) Expand all
254 254
255 // GetHeightForWidth and borders. 255 // GetHeightForWidth and borders.
256 int required_height_with_border = 256 int required_height_with_border =
257 label.GetHeightForWidth(required_width_with_border); 257 label.GetHeightForWidth(required_width_with_border);
258 EXPECT_EQ(required_height_with_border, required_height + border.height()); 258 EXPECT_EQ(required_height_with_border, required_height + border.height());
259 259
260 // Test that the border width is subtracted before doing the height 260 // Test that the border width is subtracted before doing the height
261 // calculation. If it is, then the height will grow when width 261 // calculation. If it is, then the height will grow when width
262 // is shrunk. 262 // is shrunk.
263 int height1 = label.GetHeightForWidth(required_width_with_border - 1); 263 int height1 = label.GetHeightForWidth(required_width_with_border - 1);
264 #if defined(WIN_OS) 264 #if defined(OS_WIN)
265 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc) 265 // Canvas::SizeStringInt (in app/gfx/canvas_linux.cc)
266 // has to be fixed to return the size that fits to given width/height. 266 // has to be fixed to return the size that fits to given width/height.
267 EXPECT_GT(height1, required_height_with_border); 267 EXPECT_GT(height1, required_height_with_border);
268 #endif 268 #endif
269 EXPECT_EQ(height1, height_for_constrained_width + border.height()); 269 EXPECT_EQ(height1, height_for_constrained_width + border.height());
270 270
271 // GetPreferredSize and borders. 271 // GetPreferredSize and borders.
272 label.SetBounds(0, 0, 0, 0); 272 label.SetBounds(0, 0, 0, 0);
273 gfx::Size required_size_with_border = label.GetPreferredSize(); 273 gfx::Size required_size_with_border = label.GetPreferredSize();
274 EXPECT_EQ(required_size_with_border.height(), 274 EXPECT_EQ(required_size_with_border.height(),
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 gfx::Canvas::TEXT_ALIGN_LEFT | 807 gfx::Canvas::TEXT_ALIGN_LEFT |
808 gfx::Canvas::NO_ELLIPSIS, 808 gfx::Canvas::NO_ELLIPSIS,
809 flags); 809 flags);
810 #endif 810 #endif
811 811
812 // Reset Locale 812 // Reset Locale
813 base::i18n::SetICUDefaultLocale(locale); 813 base::i18n::SetICUDefaultLocale(locale);
814 } 814 }
815 815
816 } // namespace views 816 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/label.cc ('k') | views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698