OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/corewm/tooltip_aura.h" | 5 #include "ui/views/corewm/tooltip_aura.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
10 #include "ui/gfx/text_elider.h" | 10 #include "ui/gfx/text_elider.h" |
11 #include "ui/views/test/views_test_base.h" | 11 #include "ui/views/test/views_test_base.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 namespace corewm { | 14 namespace corewm { |
15 | 15 |
16 typedef ViewsTestBase TooltipAuraTest; | 16 typedef ViewsTestBase TooltipAuraTest; |
17 | 17 |
18 // TODO(sky): clean this up. | 18 // TODO(sky): clean this up. |
19 gfx::Font GetDefaultFont() { | 19 gfx::Font GetDefaultFont() { |
20 return ui::ResourceBundle::GetSharedInstance().GetFont( | 20 return ui::ResourceBundle::GetSharedInstance().GetFont( |
21 ui::ResourceBundle::BaseFont); | 21 ui::ResourceBundle::BaseFont); |
22 } | 22 } |
23 | 23 |
24 TEST_F(TooltipAuraTest, TrimTooltipToFitTests) { | 24 TEST_F(TooltipAuraTest, TrimTooltipToFitTests) { |
25 const int max_width = 4000; | 25 const int max_width = 4000; |
26 string16 tooltip; | 26 base::string16 tooltip; |
27 int width, line_count, expect_lines; | 27 int width, line_count, expect_lines; |
28 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc | 28 int max_pixel_width = 400; // copied from constants in tooltip_controller.cc |
29 int max_lines = 10; // copied from constants in tooltip_controller.cc | 29 int max_lines = 10; // copied from constants in tooltip_controller.cc |
30 gfx::Font font = GetDefaultFont(); | 30 gfx::Font font = GetDefaultFont(); |
31 size_t tooltip_len; | 31 size_t tooltip_len; |
32 | 32 |
33 // Error in computed size vs. expected size should not be greater than the | 33 // Error in computed size vs. expected size should not be greater than the |
34 // size of the longest word. | 34 // size of the longest word. |
35 int error_in_pixel_width = font.GetStringWidth(ASCIIToUTF16("tooltip")); | 35 int error_in_pixel_width = font.GetStringWidth(ASCIIToUTF16("tooltip")); |
36 | 36 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 width = line_count = -1; | 109 width = line_count = -1; |
110 tooltip = ASCIIToUTF16("Small Tool t\tip"); | 110 tooltip = ASCIIToUTF16("Small Tool t\tip"); |
111 TooltipAura::TrimTooltipToFit(max_width, &tooltip, &width, &line_count); | 111 TooltipAura::TrimTooltipToFit(max_width, &tooltip, &width, &line_count); |
112 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), width); | 112 EXPECT_EQ(font.GetStringWidth(ASCIIToUTF16("Small Tool t\tip")), width); |
113 EXPECT_EQ(1, line_count); | 113 EXPECT_EQ(1, line_count); |
114 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); | 114 EXPECT_EQ(ASCIIToUTF16("Small Tool t\tip"), tooltip); |
115 } | 115 } |
116 | 116 |
117 } // namespace corewm | 117 } // namespace corewm |
118 } // namespace views | 118 } // namespace views |
OLD | NEW |