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

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: Rebased. 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
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/message_center/message_center_constants.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 <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 class CanvasTest : public testing::Test {
13 const string16 text = UTF8ToUTF16("Test"); 15 protected:
14 const int width = Canvas::GetStringWidth(text, Font()); 16 int GetStringWidth(const char *text) {
17 return Canvas::GetStringWidth(UTF8ToUTF16(text), font_);
18 }
15 19
16 EXPECT_GT(width, 0); 20 gfx::Size SizeStringInt(const char *text, int width, int line_height) {
21 string16 text16 = UTF8ToUTF16(text);
22 int height = 0;
23 int flags = (text16.find('\n') != string16::npos) ? Canvas::MULTI_LINE : 0;
24 Canvas::SizeStringInt(text16, font_, &width, &height, line_height, flags);
25 return gfx::Size(width, height);
26 }
27
28 private:
29 gfx::Font font_;
30 };
31
32 TEST_F(CanvasTest, StringWidth) {
33 EXPECT_GT(GetStringWidth("Test"), 0);
17 } 34 }
18 35
19 TEST(CanvasTest, StringWidthEmptyString) { 36 TEST_F(CanvasTest, StringWidthEmptyString) {
20 const string16 text = UTF8ToUTF16(""); 37 EXPECT_EQ(0, GetStringWidth(""));
21 const int width = Canvas::GetStringWidth(text, Font());
22
23 EXPECT_EQ(0, width);
24 } 38 }
25 39
26 TEST(CanvasTest, StringSizeEmptyString) { 40 TEST_F(CanvasTest, StringSizeEmptyString) {
27 const Font font; 41 gfx::Size size = SizeStringInt("", 0, 0);
28 const string16 text = UTF8ToUTF16(""); 42 EXPECT_EQ(0, size.width());
29 int width = 0; 43 EXPECT_GT(size.height(), 0);
30 int height = 0; 44 }
31 Canvas::SizeStringInt(text, font, &width, &height, 0);
32 45
33 EXPECT_EQ(0, width); 46 // Line height is only supported on Skia.
34 EXPECT_GT(height, 0); 47 #if defined(OS_MACOSX) || defined(OS_ANDROID)
48 #define MAYBE_StringSizeWithLineHeight DISABLED_StringSizeWithLineHeight
49 #else
50 #define MAYBE_StringSizeWithLineHeight StringSizeWithLineHeight
51 #endif
52
53 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) {
54 gfx::Size one_line_size = SizeStringInt("Q", 0, 0);
55 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000);
56 EXPECT_EQ(one_line_size.width(), four_line_size.width());
57 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height());
35 } 58 }
36 59
37 } // namespace gfx 60 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/message_center/message_center_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698