Chromium Code Reviews| 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 "base/i18n/rtl.h" | 5 #include "base/i18n/rtl.h" |
| 6 #include "base/message_loop.h" | |
| 6 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 11 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
| 12 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 | 16 |
| 16 // All text sizing measurements (width and height) should be greater than this. | 17 // All text sizing measurements (width and height) should be greater than this. |
| 17 const int kMinTextDimension = 4; | 18 const int kMinTextDimension = 4; |
| 18 | 19 |
| 19 TEST(LabelTest, FontPropertyCourier) { | 20 class LabelTest : public testing::Test { |
|
Evan Stade
2013/05/23 21:45:58
some views_unittests will now need a message loop
| |
| 21 public: | |
| 22 LabelTest() {} | |
| 23 virtual ~LabelTest() {} | |
| 24 | |
| 25 private: | |
| 26 base::MessageLoopForUI loop_; | |
| 27 }; | |
| 28 | |
| 29 TEST_F(LabelTest, FontPropertyCourier) { | |
| 20 Label label; | 30 Label label; |
| 21 std::string font_name("courier"); | 31 std::string font_name("courier"); |
| 22 // Note: This test is size dependent since Courier does not support all sizes. | 32 // Note: This test is size dependent since Courier does not support all sizes. |
| 23 gfx::Font font(font_name, 26); | 33 gfx::Font font(font_name, 26); |
| 24 label.SetFont(font); | 34 label.SetFont(font); |
| 25 gfx::Font font_used = label.font(); | 35 gfx::Font font_used = label.font(); |
| 26 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 27 // On Linux, this results in "Sans" instead of "courier". | 37 // On Linux, this results in "Sans" instead of "courier". |
| 28 EXPECT_EQ(font_name, font_used.GetFontName()); | 38 EXPECT_EQ(font_name, font_used.GetFontName()); |
| 29 #endif | 39 #endif |
| 30 EXPECT_EQ(26, font_used.GetFontSize()); | 40 EXPECT_EQ(26, font_used.GetFontSize()); |
| 31 } | 41 } |
| 32 | 42 |
| 33 TEST(LabelTest, FontPropertyArial) { | 43 TEST_F(LabelTest, FontPropertyArial) { |
| 34 Label label; | 44 Label label; |
| 35 std::string font_name("arial"); | 45 std::string font_name("arial"); |
| 36 gfx::Font font(font_name, 30); | 46 gfx::Font font(font_name, 30); |
| 37 label.SetFont(font); | 47 label.SetFont(font); |
| 38 gfx::Font font_used = label.font(); | 48 gfx::Font font_used = label.font(); |
| 39 EXPECT_EQ(font_name, font_used.GetFontName()); | 49 EXPECT_EQ(font_name, font_used.GetFontName()); |
| 40 EXPECT_EQ(30, font_used.GetFontSize()); | 50 EXPECT_EQ(30, font_used.GetFontSize()); |
| 41 } | 51 } |
| 42 | 52 |
| 43 TEST(LabelTest, TextProperty) { | 53 TEST_F(LabelTest, TextProperty) { |
| 44 Label label; | 54 Label label; |
| 45 string16 test_text(ASCIIToUTF16("A random string.")); | 55 string16 test_text(ASCIIToUTF16("A random string.")); |
| 46 label.SetText(test_text); | 56 label.SetText(test_text); |
| 47 EXPECT_EQ(test_text, label.text()); | 57 EXPECT_EQ(test_text, label.text()); |
| 48 } | 58 } |
| 49 | 59 |
| 50 TEST(LabelTest, ColorProperty) { | 60 TEST_F(LabelTest, ColorProperty) { |
| 51 Label label; | 61 Label label; |
| 52 SkColor color = SkColorSetARGB(20, 40, 10, 5); | 62 SkColor color = SkColorSetARGB(20, 40, 10, 5); |
| 53 label.SetAutoColorReadabilityEnabled(false); | 63 label.SetAutoColorReadabilityEnabled(false); |
| 54 label.SetEnabledColor(color); | 64 label.SetEnabledColor(color); |
| 55 EXPECT_EQ(color, label.enabled_color()); | 65 EXPECT_EQ(color, label.enabled_color()); |
| 56 } | 66 } |
| 57 | 67 |
| 58 TEST(LabelTest, AlignmentProperty) { | 68 TEST_F(LabelTest, AlignmentProperty) { |
| 59 Label label; | 69 Label label; |
| 60 bool reverse_alignment = base::i18n::IsRTL(); | 70 bool reverse_alignment = base::i18n::IsRTL(); |
| 61 | 71 |
| 62 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 72 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 63 EXPECT_EQ(reverse_alignment ? gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT, | 73 EXPECT_EQ(reverse_alignment ? gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT, |
| 64 label.horizontal_alignment()); | 74 label.horizontal_alignment()); |
| 65 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 75 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 66 EXPECT_EQ(reverse_alignment ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT, | 76 EXPECT_EQ(reverse_alignment ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT, |
| 67 label.horizontal_alignment()); | 77 label.horizontal_alignment()); |
| 68 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 78 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 69 EXPECT_EQ(gfx::ALIGN_CENTER, label.horizontal_alignment()); | 79 EXPECT_EQ(gfx::ALIGN_CENTER, label.horizontal_alignment()); |
| 70 | 80 |
| 71 // The label's alignment should not be flipped if the directionality mode is | 81 // The label's alignment should not be flipped if the directionality mode is |
| 72 // AUTO_DETECT_DIRECTIONALITY. | 82 // AUTO_DETECT_DIRECTIONALITY. |
| 73 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 83 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 74 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 84 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 75 EXPECT_EQ(gfx::ALIGN_RIGHT, label.horizontal_alignment()); | 85 EXPECT_EQ(gfx::ALIGN_RIGHT, label.horizontal_alignment()); |
| 76 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 86 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 77 EXPECT_EQ(gfx::ALIGN_LEFT, label.horizontal_alignment()); | 87 EXPECT_EQ(gfx::ALIGN_LEFT, label.horizontal_alignment()); |
| 78 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 88 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 79 EXPECT_EQ(gfx::ALIGN_CENTER, label.horizontal_alignment()); | 89 EXPECT_EQ(gfx::ALIGN_CENTER, label.horizontal_alignment()); |
| 80 } | 90 } |
| 81 | 91 |
| 82 TEST(LabelTest, DirectionalityModeProperty) { | 92 TEST_F(LabelTest, DirectionalityModeProperty) { |
| 83 Label label; | 93 Label label; |
| 84 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode()); | 94 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode()); |
| 85 | 95 |
| 86 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 96 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 87 EXPECT_EQ(Label::AUTO_DETECT_DIRECTIONALITY, label.directionality_mode()); | 97 EXPECT_EQ(Label::AUTO_DETECT_DIRECTIONALITY, label.directionality_mode()); |
| 88 | 98 |
| 89 label.set_directionality_mode(Label::USE_UI_DIRECTIONALITY); | 99 label.set_directionality_mode(Label::USE_UI_DIRECTIONALITY); |
| 90 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode()); | 100 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode()); |
| 91 } | 101 } |
| 92 | 102 |
| 93 TEST(LabelTest, MultiLineProperty) { | 103 TEST_F(LabelTest, MultiLineProperty) { |
| 94 Label label; | 104 Label label; |
| 95 EXPECT_FALSE(label.is_multi_line()); | 105 EXPECT_FALSE(label.is_multi_line()); |
| 96 label.SetMultiLine(true); | 106 label.SetMultiLine(true); |
| 97 EXPECT_TRUE(label.is_multi_line()); | 107 EXPECT_TRUE(label.is_multi_line()); |
| 98 label.SetMultiLine(false); | 108 label.SetMultiLine(false); |
| 99 EXPECT_FALSE(label.is_multi_line()); | 109 EXPECT_FALSE(label.is_multi_line()); |
| 100 } | 110 } |
| 101 | 111 |
| 102 TEST(LabelTest, TooltipProperty) { | 112 TEST_F(LabelTest, TooltipProperty) { |
| 103 Label label; | 113 Label label; |
| 104 string16 test_text(ASCIIToUTF16("My cool string.")); | 114 string16 test_text(ASCIIToUTF16("My cool string.")); |
| 105 label.SetText(test_text); | 115 label.SetText(test_text); |
| 106 | 116 |
| 107 string16 tooltip; | 117 string16 tooltip; |
| 108 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 118 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 109 EXPECT_EQ(test_text, tooltip); | 119 EXPECT_EQ(test_text, tooltip); |
| 110 | 120 |
| 111 string16 tooltip_text(ASCIIToUTF16("The tooltip!")); | 121 string16 tooltip_text(ASCIIToUTF16("The tooltip!")); |
| 112 label.SetTooltipText(tooltip_text); | 122 label.SetTooltipText(tooltip_text); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 139 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); | 149 EXPECT_FALSE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 140 | 150 |
| 141 // Verify that setting the tooltip still shows it. | 151 // Verify that setting the tooltip still shows it. |
| 142 label.SetTooltipText(tooltip_text); | 152 label.SetTooltipText(tooltip_text); |
| 143 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); | 153 EXPECT_TRUE(label.GetTooltipText(gfx::Point(), &tooltip)); |
| 144 EXPECT_EQ(tooltip_text, tooltip); | 154 EXPECT_EQ(tooltip_text, tooltip); |
| 145 // Clear out the tooltip. | 155 // Clear out the tooltip. |
| 146 label.SetTooltipText(empty_text); | 156 label.SetTooltipText(empty_text); |
| 147 } | 157 } |
| 148 | 158 |
| 149 TEST(LabelTest, Accessibility) { | 159 TEST_F(LabelTest, Accessibility) { |
| 150 Label label; | 160 Label label; |
| 151 string16 test_text(ASCIIToUTF16("My special text.")); | 161 string16 test_text(ASCIIToUTF16("My special text.")); |
| 152 label.SetText(test_text); | 162 label.SetText(test_text); |
| 153 | 163 |
| 154 ui::AccessibleViewState state; | 164 ui::AccessibleViewState state; |
| 155 label.GetAccessibleState(&state); | 165 label.GetAccessibleState(&state); |
| 156 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); | 166 EXPECT_EQ(ui::AccessibilityTypes::ROLE_STATICTEXT, state.role); |
| 157 EXPECT_EQ(test_text, state.name); | 167 EXPECT_EQ(test_text, state.name); |
| 158 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); | 168 EXPECT_TRUE(ui::AccessibilityTypes::STATE_READONLY & state.state); |
| 159 } | 169 } |
| 160 | 170 |
| 161 TEST(LabelTest, SingleLineSizing) { | 171 TEST_F(LabelTest, SingleLineSizing) { |
| 162 Label label; | 172 Label label; |
| 163 string16 test_text(ASCIIToUTF16("A not so random string in one line.")); | 173 string16 test_text(ASCIIToUTF16("A not so random string in one line.")); |
| 164 label.SetText(test_text); | 174 label.SetText(test_text); |
| 165 | 175 |
| 166 // GetPreferredSize | 176 // GetPreferredSize |
| 167 gfx::Size required_size = label.GetPreferredSize(); | 177 gfx::Size required_size = label.GetPreferredSize(); |
| 168 EXPECT_GT(required_size.height(), kMinTextDimension); | 178 EXPECT_GT(required_size.height(), kMinTextDimension); |
| 169 EXPECT_GT(required_size.width(), kMinTextDimension); | 179 EXPECT_GT(required_size.width(), kMinTextDimension); |
| 170 | 180 |
| 171 // Test everything with borders. | 181 // Test everything with borders. |
| 172 gfx::Insets border(10, 20, 30, 40); | 182 gfx::Insets border(10, 20, 30, 40); |
| 173 label.set_border(Border::CreateEmptyBorder(border.top(), | 183 label.set_border(Border::CreateEmptyBorder(border.top(), |
| 174 border.left(), | 184 border.left(), |
| 175 border.bottom(), | 185 border.bottom(), |
| 176 border.right())); | 186 border.right())); |
| 177 | 187 |
| 178 // GetPreferredSize and borders. | 188 // GetPreferredSize and borders. |
| 179 label.SetBounds(0, 0, 0, 0); | 189 label.SetBounds(0, 0, 0, 0); |
| 180 gfx::Size required_size_with_border = label.GetPreferredSize(); | 190 gfx::Size required_size_with_border = label.GetPreferredSize(); |
| 181 EXPECT_EQ(required_size_with_border.height(), | 191 EXPECT_EQ(required_size_with_border.height(), |
| 182 required_size.height() + border.height()); | 192 required_size.height() + border.height()); |
| 183 EXPECT_EQ(required_size_with_border.width(), | 193 EXPECT_EQ(required_size_with_border.width(), |
| 184 required_size.width() + border.width()); | 194 required_size.width() + border.width()); |
| 185 } | 195 } |
| 186 | 196 |
| 187 TEST(LabelTest, MultilineSmallAvailableWidthSizing) { | 197 TEST_F(LabelTest, MultilineSmallAvailableWidthSizing) { |
| 188 Label label; | 198 Label label; |
| 189 string16 test_text(ASCIIToUTF16("Too Wide.")); | 199 string16 test_text(ASCIIToUTF16("Too Wide.")); |
| 190 | 200 |
| 191 label.SetMultiLine(true); | 201 label.SetMultiLine(true); |
| 192 label.SetAllowCharacterBreak(true); | 202 label.SetAllowCharacterBreak(true); |
| 193 label.SetElideBehavior(Label::ELIDE_AT_END); | 203 label.SetElideBehavior(Label::ELIDE_AT_END); |
| 194 label.SetText(test_text); | 204 label.SetText(test_text); |
| 195 | 205 |
| 196 // Check that Label can be laid out at a variety of small sizes, | 206 // Check that Label can be laid out at a variety of small sizes, |
| 197 // splitting the words into up to one character per line if necessary. | 207 // splitting the words into up to one character per line if necessary. |
| 198 // Incorrect word splitting may cause infinite loops in text layout. | 208 // Incorrect word splitting may cause infinite loops in text layout. |
| 199 gfx::Size required_size = label.GetPreferredSize(); | 209 gfx::Size required_size = label.GetPreferredSize(); |
| 200 for (int i = 1; i < required_size.width(); ++i) { | 210 for (int i = 1; i < required_size.width(); ++i) { |
| 201 EXPECT_GT(label.GetHeightForWidth(i), 0); | 211 EXPECT_GT(label.GetHeightForWidth(i), 0); |
| 202 } | 212 } |
| 203 } | 213 } |
| 204 | 214 |
| 205 TEST(LabelTest, MultiLineSizing) { | 215 TEST_F(LabelTest, MultiLineSizing) { |
| 206 Label label; | 216 Label label; |
| 207 label.set_focusable(false); | 217 label.set_focusable(false); |
| 208 string16 test_text( | 218 string16 test_text( |
| 209 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); | 219 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); |
| 210 label.SetText(test_text); | 220 label.SetText(test_text); |
| 211 label.SetMultiLine(true); | 221 label.SetMultiLine(true); |
| 212 | 222 |
| 213 // GetPreferredSize | 223 // GetPreferredSize |
| 214 gfx::Size required_size = label.GetPreferredSize(); | 224 gfx::Size required_size = label.GetPreferredSize(); |
| 215 EXPECT_GT(required_size.height(), kMinTextDimension); | 225 EXPECT_GT(required_size.height(), kMinTextDimension); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 | 289 |
| 280 // GetPreferredSize and borders. | 290 // GetPreferredSize and borders. |
| 281 label.SetBounds(0, 0, 0, 0); | 291 label.SetBounds(0, 0, 0, 0); |
| 282 gfx::Size required_size_with_border = label.GetPreferredSize(); | 292 gfx::Size required_size_with_border = label.GetPreferredSize(); |
| 283 EXPECT_EQ(required_size_with_border.height(), | 293 EXPECT_EQ(required_size_with_border.height(), |
| 284 required_size.height() + border.height()); | 294 required_size.height() + border.height()); |
| 285 EXPECT_EQ(required_size_with_border.width(), | 295 EXPECT_EQ(required_size_with_border.width(), |
| 286 required_size.width() + border.width()); | 296 required_size.width() + border.width()); |
| 287 } | 297 } |
| 288 | 298 |
| 289 TEST(LabelTest, AutoDetectDirectionality) { | 299 TEST_F(LabelTest, AutoDetectDirectionality) { |
| 290 Label label; | 300 Label label; |
| 291 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 301 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 292 | 302 |
| 293 // Test text starts with RTL character. | 303 // Test text starts with RTL character. |
| 294 string16 test_text(WideToUTF16(L" \x5d0\x5d1\x5d2 abc")); | 304 string16 test_text(WideToUTF16(L" \x5d0\x5d1\x5d2 abc")); |
| 295 label.SetText(test_text); | 305 label.SetText(test_text); |
| 296 gfx::Size required_size(label.GetPreferredSize()); | 306 gfx::Size required_size(label.GetPreferredSize()); |
| 297 gfx::Size extra(22, 8); | 307 gfx::Size extra(22, 8); |
| 298 label.SetBounds(0, | 308 label.SetBounds(0, |
| 299 0, | 309 0, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 316 0, | 326 0, |
| 317 required_size.width() + extra.width(), | 327 required_size.width() + extra.width(), |
| 318 required_size.height() + extra.height()); | 328 required_size.height() + extra.height()); |
| 319 | 329 |
| 320 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 330 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 321 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, | 331 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, |
| 322 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | | 332 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | |
| 323 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); | 333 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); |
| 324 } | 334 } |
| 325 | 335 |
| 326 TEST(LabelTest, DrawSingleLineString) { | 336 TEST_F(LabelTest, DrawSingleLineString) { |
| 327 Label label; | 337 Label label; |
| 328 label.set_focusable(false); | 338 label.set_focusable(false); |
| 329 | 339 |
| 330 // Turn off mirroring so that we don't need to figure out if | 340 // Turn off mirroring so that we don't need to figure out if |
| 331 // align right really means align left. | 341 // align right really means align left. |
| 332 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 342 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 333 | 343 |
| 334 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); | 344 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); |
| 335 label.SetText(test_text); | 345 label.SetText(test_text); |
| 336 gfx::Size required_size(label.GetPreferredSize()); | 346 gfx::Size required_size(label.GetPreferredSize()); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 EXPECT_EQ(required_size.height(), text_bounds.height()); | 462 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 453 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, | 463 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 454 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | | 464 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 455 gfx::Canvas::TEXT_ALIGN_CENTER | | 465 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 456 gfx::Canvas::TEXT_ALIGN_RIGHT)); | 466 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 457 } | 467 } |
| 458 | 468 |
| 459 // On Linux the underlying pango routines require a max height in order to | 469 // On Linux the underlying pango routines require a max height in order to |
| 460 // ellide multiline text. So until that can be resolved, we set all | 470 // ellide multiline text. So until that can be resolved, we set all |
| 461 // multiline lables to not ellide in Linux only. | 471 // multiline lables to not ellide in Linux only. |
| 462 TEST(LabelTest, DrawMultiLineString) { | 472 TEST_F(LabelTest, DrawMultiLineString) { |
| 463 Label label; | 473 Label label; |
| 464 label.set_focusable(false); | 474 label.set_focusable(false); |
| 465 | 475 |
| 466 // Turn off mirroring so that we don't need to figure out if | 476 // Turn off mirroring so that we don't need to figure out if |
| 467 // align right really means align left. | 477 // align right really means align left. |
| 468 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 478 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 469 | 479 |
| 470 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); | 480 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); |
| 471 label.SetText(test_text); | 481 label.SetText(test_text); |
| 472 label.SetMultiLine(true); | 482 label.SetMultiLine(true); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 expected_flags = gfx::Canvas::MULTI_LINE | | 603 expected_flags = gfx::Canvas::MULTI_LINE | |
| 594 gfx::Canvas::TEXT_ALIGN_RIGHT | | 604 gfx::Canvas::TEXT_ALIGN_RIGHT | |
| 595 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 605 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 596 #if defined(OS_WIN) | 606 #if defined(OS_WIN) |
| 597 EXPECT_EQ(expected_flags, flags); | 607 EXPECT_EQ(expected_flags, flags); |
| 598 #else | 608 #else |
| 599 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | 609 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); |
| 600 #endif | 610 #endif |
| 601 } | 611 } |
| 602 | 612 |
| 603 TEST(LabelTest, DrawSingleLineStringInRTL) { | 613 TEST_F(LabelTest, DrawSingleLineStringInRTL) { |
| 604 Label label; | 614 Label label; |
| 605 label.set_focusable(false); | 615 label.set_focusable(false); |
| 606 | 616 |
| 607 std::string locale = l10n_util::GetApplicationLocale(""); | 617 std::string locale = l10n_util::GetApplicationLocale(""); |
| 608 base::i18n::SetICUDefaultLocale("he"); | 618 base::i18n::SetICUDefaultLocale("he"); |
| 609 | 619 |
| 610 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); | 620 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); |
| 611 label.SetText(test_text); | 621 label.SetText(test_text); |
| 612 gfx::Size required_size(label.GetPreferredSize()); | 622 gfx::Size required_size(label.GetPreferredSize()); |
| 613 gfx::Size extra(22, 8); | 623 gfx::Size extra(22, 8); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 gfx::Canvas::TEXT_ALIGN_CENTER | | 742 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 733 gfx::Canvas::TEXT_ALIGN_RIGHT)); | 743 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 734 | 744 |
| 735 // Reset locale. | 745 // Reset locale. |
| 736 base::i18n::SetICUDefaultLocale(locale); | 746 base::i18n::SetICUDefaultLocale(locale); |
| 737 } | 747 } |
| 738 | 748 |
| 739 // On Linux the underlying pango routines require a max height in order to | 749 // On Linux the underlying pango routines require a max height in order to |
| 740 // ellide multiline text. So until that can be resolved, we set all | 750 // ellide multiline text. So until that can be resolved, we set all |
| 741 // multiline lables to not ellide in Linux only. | 751 // multiline lables to not ellide in Linux only. |
| 742 TEST(LabelTest, DrawMultiLineStringInRTL) { | 752 TEST_F(LabelTest, DrawMultiLineStringInRTL) { |
| 743 Label label; | 753 Label label; |
| 744 label.set_focusable(false); | 754 label.set_focusable(false); |
| 745 | 755 |
| 746 // Test for RTL. | 756 // Test for RTL. |
| 747 std::string locale = l10n_util::GetApplicationLocale(""); | 757 std::string locale = l10n_util::GetApplicationLocale(""); |
| 748 base::i18n::SetICUDefaultLocale("he"); | 758 base::i18n::SetICUDefaultLocale("he"); |
| 749 | 759 |
| 750 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); | 760 string16 test_text(ASCIIToUTF16("Another string\nwith returns\n\n!")); |
| 751 label.SetText(test_text); | 761 label.SetText(test_text); |
| 752 label.SetMultiLine(true); | 762 label.SetMultiLine(true); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 gfx::Canvas::NO_ELLIPSIS, | 894 gfx::Canvas::NO_ELLIPSIS, |
| 885 flags); | 895 flags); |
| 886 #endif | 896 #endif |
| 887 | 897 |
| 888 // Reset Locale | 898 // Reset Locale |
| 889 base::i18n::SetICUDefaultLocale(locale); | 899 base::i18n::SetICUDefaultLocale(locale); |
| 890 } | 900 } |
| 891 | 901 |
| 892 // Check that we disable subpixel rendering when a transparent background is | 902 // Check that we disable subpixel rendering when a transparent background is |
| 893 // being used. | 903 // being used. |
| 894 TEST(LabelTest, DisableSubpixelRendering) { | 904 TEST_F(LabelTest, DisableSubpixelRendering) { |
| 895 Label label; | 905 Label label; |
| 896 label.SetBackgroundColor(SK_ColorWHITE); | 906 label.SetBackgroundColor(SK_ColorWHITE); |
| 897 EXPECT_EQ( | 907 EXPECT_EQ( |
| 898 0, label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); | 908 0, label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); |
| 899 | 909 |
| 900 label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255)); | 910 label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255)); |
| 901 EXPECT_EQ( | 911 EXPECT_EQ( |
| 902 gfx::Canvas::NO_SUBPIXEL_RENDERING, | 912 gfx::Canvas::NO_SUBPIXEL_RENDERING, |
| 903 label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); | 913 label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); |
| 904 } | 914 } |
| 905 | 915 |
| 906 // Check that labels support GetTooltipHandlerForPoint. | 916 // Check that labels support GetTooltipHandlerForPoint. |
| 907 TEST(LabelTest, GetTooltipHandlerForPoint) { | 917 TEST_F(LabelTest, GetTooltipHandlerForPoint) { |
| 908 Label label; | 918 Label label; |
| 909 label.SetText( | 919 label.SetText( |
| 910 ASCIIToUTF16("A string that's long enough to exceed the bounds")); | 920 ASCIIToUTF16("A string that's long enough to exceed the bounds")); |
| 911 label.SetBounds(0, 0, 10, 10); | 921 label.SetBounds(0, 0, 10, 10); |
| 912 // There's a default tooltip if the text is too big to fit. | 922 // There's a default tooltip if the text is too big to fit. |
| 913 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); | 923 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); |
| 914 | 924 |
| 915 // If there's no default tooltip, this should return NULL. | 925 // If there's no default tooltip, this should return NULL. |
| 916 label.SetBounds(0, 0, 500, 50); | 926 label.SetBounds(0, 0, 500, 50); |
| 917 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); | 927 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); |
| 918 | 928 |
| 919 label.SetTooltipText(ASCIIToUTF16("a tooltip")); | 929 label.SetTooltipText(ASCIIToUTF16("a tooltip")); |
| 920 // If the point hits the label, and tooltip is set, the label should be | 930 // If the point hits the label, and tooltip is set, the label should be |
| 921 // returned as its tooltip handler. | 931 // returned as its tooltip handler. |
| 922 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); | 932 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(2, 2))); |
| 923 | 933 |
| 924 // Additionally, GetTooltipHandlerForPoint should verify that the label | 934 // Additionally, GetTooltipHandlerForPoint should verify that the label |
| 925 // actually contains the point. | 935 // actually contains the point. |
| 926 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 936 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 927 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 937 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 928 | 938 |
| 929 // GetTooltipHandlerForPoint works should work in child bounds. | 939 // GetTooltipHandlerForPoint works should work in child bounds. |
| 930 label.SetBounds(2, 2, 10, 10); | 940 label.SetBounds(2, 2, 10, 10); |
| 931 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 941 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 932 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 942 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 933 } | 943 } |
| 934 | 944 |
| 935 } // namespace views | 945 } // namespace views |
| OLD | NEW |