| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/views/controls/link.h" | 12 #include "ui/views/controls/link.h" |
| 12 #include "ui/views/controls/styled_label.h" | 13 #include "ui/views/controls/styled_label.h" |
| 13 #include "ui/views/controls/styled_label_listener.h" | 14 #include "ui/views/controls/styled_label_listener.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 class StyledLabelTest : public testing::Test, public StyledLabelListener { | 18 class StyledLabelTest : public testing::Test, public StyledLabelListener { |
| 18 public: | 19 public: |
| 19 StyledLabelTest() {} | 20 StyledLabelTest() {} |
| 20 virtual ~StyledLabelTest() {} | 21 virtual ~StyledLabelTest() {} |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 EXPECT_EQ(gfx::Font::NORMAL, | 250 EXPECT_EQ(gfx::Font::NORMAL, |
| 250 static_cast<Label*>(styled()->child_at(2))->font().GetStyle()); | 251 static_cast<Label*>(styled()->child_at(2))->font().GetStyle()); |
| 251 | 252 |
| 252 // The second bold part should start on a new line. | 253 // The second bold part should start on a new line. |
| 253 EXPECT_EQ(0, styled()->child_at(0)->bounds().x()); | 254 EXPECT_EQ(0, styled()->child_at(0)->bounds().x()); |
| 254 EXPECT_EQ(0, styled()->child_at(1)->bounds().x()); | 255 EXPECT_EQ(0, styled()->child_at(1)->bounds().x()); |
| 255 EXPECT_EQ(styled()->child_at(1)->bounds().right() - 2, | 256 EXPECT_EQ(styled()->child_at(1)->bounds().right() - 2, |
| 256 styled()->child_at(2)->bounds().x()); | 257 styled()->child_at(2)->bounds().x()); |
| 257 } | 258 } |
| 258 | 259 |
| 260 TEST_F(StyledLabelTest, Color) { |
| 261 const std::string text_red("RED"); |
| 262 const std::string text_link("link"); |
| 263 const std::string text("word"); |
| 264 InitStyledLabel(text_red + text_link + text); |
| 265 |
| 266 StyledLabel::RangeStyleInfo style_info_red; |
| 267 style_info_red.color = SK_ColorRED; |
| 268 styled()->AddStyleRange(ui::Range(0, text_red.size()), style_info_red); |
| 269 |
| 270 StyledLabel::RangeStyleInfo style_info_link = |
| 271 StyledLabel::RangeStyleInfo::CreateForLink(); |
| 272 styled()->AddStyleRange(ui::Range(text_red.size(), |
| 273 text_red.size() + text_link.size()), |
| 274 style_info_link); |
| 275 |
| 276 // Obtain the default text color for a label. |
| 277 Label label(ASCIIToUTF16(text)); |
| 278 const SkColor kDefaultTextColor = label.enabled_color(); |
| 279 |
| 280 // Obtain the default text color for a link; |
| 281 Link link(ASCIIToUTF16(text_link)); |
| 282 const SkColor kDefaultLinkColor = link.enabled_color(); |
| 283 |
| 284 styled()->SetBounds(0, 0, 1000, 1000); |
| 285 styled()->Layout(); |
| 286 |
| 287 EXPECT_EQ(SK_ColorRED, |
| 288 static_cast<Label*>(styled()->child_at(0))->enabled_color()); |
| 289 EXPECT_EQ(kDefaultLinkColor, |
| 290 static_cast<Label*>(styled()->child_at(1))->enabled_color()); |
| 291 EXPECT_EQ(kDefaultTextColor, |
| 292 static_cast<Label*>(styled()->child_at(2))->enabled_color()); |
| 293 } |
| 294 |
| 295 TEST_F(StyledLabelTest, ColorReadability) { |
| 296 const std::string text( |
| 297 "This is a block of text that needs color adjustment."); |
| 298 InitStyledLabel(text); |
| 299 styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK); |
| 300 |
| 301 // Obtain the text color if it were a pure label. |
| 302 Label label(ASCIIToUTF16(text)); |
| 303 label.SetBackgroundColor(SK_ColorBLACK); |
| 304 |
| 305 styled()->SetBounds(0, 0, 1000, 1000); |
| 306 styled()->Layout(); |
| 307 |
| 308 EXPECT_EQ(label.enabled_color(), |
| 309 static_cast<Label*>(styled()->child_at(0))->enabled_color()); |
| 310 } |
| 311 |
| 259 TEST_F(StyledLabelTest, StyledRangeWithTooltip) { | 312 TEST_F(StyledLabelTest, StyledRangeWithTooltip) { |
| 260 const std::string text("This is a test block of text, "); | 313 const std::string text("This is a test block of text, "); |
| 261 const std::string tooltip_text("this should have a tooltip,"); | 314 const std::string tooltip_text("this should have a tooltip,"); |
| 262 const std::string normal_text(" this should not have a tooltip, "); | 315 const std::string normal_text(" this should not have a tooltip, "); |
| 263 const std::string link_text("and this should be a link"); | 316 const std::string link_text("and this should be a link"); |
| 264 | 317 |
| 265 const size_t tooltip_start = text.size(); | 318 const size_t tooltip_start = text.size(); |
| 266 const size_t link_start = | 319 const size_t link_start = |
| 267 text.size() + tooltip_text.size() + normal_text.size(); | 320 text.size() + tooltip_text.size() + normal_text.size(); |
| 268 | 321 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 360 } |
| 308 | 361 |
| 309 TEST_F(StyledLabelTest, HandleEmptyLayout) { | 362 TEST_F(StyledLabelTest, HandleEmptyLayout) { |
| 310 const std::string text("This is a test block of text, "); | 363 const std::string text("This is a test block of text, "); |
| 311 InitStyledLabel(text); | 364 InitStyledLabel(text); |
| 312 styled()->Layout(); | 365 styled()->Layout(); |
| 313 ASSERT_EQ(0, styled()->child_count()); | 366 ASSERT_EQ(0, styled()->child_count()); |
| 314 } | 367 } |
| 315 | 368 |
| 316 } // namespace | 369 } // namespace |
| OLD | NEW |