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

Side by Side Diff: ui/gfx/canvas_unittest.cc

Issue 14322007: Add line height setting to views::Label & use it for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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 <limits>
6
5 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
6 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/font.h" 10 #include "ui/gfx/font.h"
9 11
10 namespace gfx { 12 namespace gfx {
11 13
12 TEST(CanvasTest, StringWidth) { 14 /* Test fixture ***************************************************************/
msw 2013/04/17 20:12:59 nit: this doesn't seem terribly common or helpful,
dharcourt 2013/04/17 23:29:40 And now it's gone :-).
13 const string16 text = UTF8ToUTF16("Test");
14 const int width = Canvas::GetStringWidth(text, Font());
15 15
16 EXPECT_GT(width, 0); 16 class CanvasTest : public testing::Test {
17 protected:
18 int GetStringWidth(const char *text) {
19 return Canvas::GetStringWidth(UTF8ToUTF16(text), font_);
20 }
21
22 gfx::Size SizeStringInt(const char *text, int width, int line_height) {
23 string16 text16 = UTF8ToUTF16(text);
24 int height = 0;
25 int flags = (text16.find('\n') != string16::npos) ? Canvas::MULTI_LINE : 0;
26 Canvas::SizeStringInt(text16, font_, &width, &height, line_height, flags);
27 return gfx::Size(width, height);
28 }
29
30 private:
31 gfx::Font font_;
32 };
33
34 /* Test cases *****************************************************************/
msw 2013/04/17 20:12:59 nit: this doesn't seem terribly common or helpful,
dharcourt 2013/04/17 23:29:40 Done.
35
36 TEST_F(CanvasTest, StringWidth) {
37 EXPECT_GT(GetStringWidth("Test"), 0);
17 } 38 }
18 39
19 TEST(CanvasTest, StringWidthEmptyString) { 40 TEST_F(CanvasTest, StringWidthEmptyString) {
20 const string16 text = UTF8ToUTF16(""); 41 EXPECT_EQ(0, GetStringWidth(""));
21 const int width = Canvas::GetStringWidth(text, Font());
22
23 EXPECT_EQ(0, width);
24 } 42 }
25 43
26 TEST(CanvasTest, StringSizeEmptyString) { 44 TEST_F(CanvasTest, StringSizeEmptyString) {
27 const Font font; 45 gfx::Size size = SizeStringInt("", 0, -1);
28 const string16 text = UTF8ToUTF16(""); 46 EXPECT_EQ(0, size.width());
29 int width = 0; 47 EXPECT_GT(size.height(), 0);
30 int height = 0; 48 }
31 Canvas::SizeStringInt(text, font, &width, &height, 0);
32 49
33 EXPECT_EQ(0, width); 50 // Line height only supported on Skia.
msw 2013/04/17 20:12:59 nit: "Line height *is* only..."
dharcourt 2013/04/17 23:29:40 Done.
34 EXPECT_GT(height, 0); 51 #if defined(OS_MACOSX) || defined(OS_ANDROID)
52 #define MAYBE_StringSizeWithLineHeight DISABLED_StringSizeWithLineHeight
msw 2013/04/17 20:12:59 It seems more common to just wrap the test in #if
dharcourt 2013/04/17 23:29:40 I'm glad my ignorance in this regard led to better
53 #else
54 #define MAYBE_StringSizeWithLineHeight StringSizeWithLineHeight
55 #endif
56
57 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) {
58 gfx::Size one_line_size = SizeStringInt("Q", 0, -1);
59 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000);
60 EXPECT_EQ(one_line_size.width(), four_line_size.width());
61 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height());
35 } 62 }
36 63
37 } // namespace gfx 64 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698