| OLD | NEW |
| 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/gfx/canvas.h" |
| 6 |
| 5 #include <limits> | 7 #include <limits> |
| 6 | 8 |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/font_list.h" |
| 10 #include "ui/gfx/font.h" | |
| 11 | 12 |
| 12 namespace gfx { | 13 namespace gfx { |
| 13 | 14 |
| 14 class CanvasTest : public testing::Test { | 15 class CanvasTest : public testing::Test { |
| 15 protected: | 16 protected: |
| 16 int GetStringWidth(const char *text) { | 17 int GetStringWidth(const char *text) { |
| 17 return Canvas::GetStringWidth(base::UTF8ToUTF16(text), font_); | 18 return Canvas::GetStringWidth(base::UTF8ToUTF16(text), font_list_); |
| 18 } | 19 } |
| 19 | 20 |
| 20 gfx::Size SizeStringInt(const char *text, int width, int line_height) { | 21 gfx::Size SizeStringInt(const char *text, int width, int line_height) { |
| 21 base::string16 text16 = base::UTF8ToUTF16(text); | 22 base::string16 text16 = base::UTF8ToUTF16(text); |
| 22 int height = 0; | 23 int height = 0; |
| 23 int flags = | 24 int flags = |
| 24 (text16.find('\n') != base::string16::npos) ? Canvas::MULTI_LINE : 0; | 25 (text16.find('\n') != base::string16::npos) ? Canvas::MULTI_LINE : 0; |
| 25 Canvas::SizeStringInt(text16, font_, &width, &height, line_height, flags); | 26 Canvas::SizeStringInt(text16, font_list_, &width, &height, line_height, |
| 27 flags); |
| 26 return gfx::Size(width, height); | 28 return gfx::Size(width, height); |
| 27 } | 29 } |
| 28 | 30 |
| 29 private: | 31 private: |
| 30 gfx::Font font_; | 32 FontList font_list_; |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 TEST_F(CanvasTest, StringWidth) { | 35 TEST_F(CanvasTest, StringWidth) { |
| 34 EXPECT_GT(GetStringWidth("Test"), 0); | 36 EXPECT_GT(GetStringWidth("Test"), 0); |
| 35 } | 37 } |
| 36 | 38 |
| 37 TEST_F(CanvasTest, StringWidthEmptyString) { | 39 TEST_F(CanvasTest, StringWidthEmptyString) { |
| 38 EXPECT_EQ(0, GetStringWidth("")); | 40 EXPECT_EQ(0, GetStringWidth("")); |
| 39 } | 41 } |
| 40 | 42 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 #endif | 54 #endif |
| 53 | 55 |
| 54 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) { | 56 TEST_F(CanvasTest, MAYBE_StringSizeWithLineHeight) { |
| 55 gfx::Size one_line_size = SizeStringInt("Q", 0, 0); | 57 gfx::Size one_line_size = SizeStringInt("Q", 0, 0); |
| 56 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000); | 58 gfx::Size four_line_size = SizeStringInt("Q\nQ\nQ\nQ", 1000000, 1000); |
| 57 EXPECT_EQ(one_line_size.width(), four_line_size.width()); | 59 EXPECT_EQ(one_line_size.width(), four_line_size.width()); |
| 58 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height()); | 60 EXPECT_EQ(3 * 1000 + one_line_size.height(), four_line_size.height()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 } // namespace gfx | 63 } // namespace gfx |
| OLD | NEW |