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

Side by Side Diff: ui/views/controls/styled_label_unittest.cc

Issue 258063009: retry r266622: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert Label changes completely Created 6 years, 7 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/views/controls/scroll_view.cc ('k') | ui/views/controls/textfield/textfield.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 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 "third_party/skia/include/core/SkColor.h"
12 #include "ui/gfx/font_list.h" 12 #include "ui/gfx/font_list.h"
13 #include "ui/views/border.h" 13 #include "ui/views/border.h"
14 #include "ui/views/controls/link.h" 14 #include "ui/views/controls/link.h"
15 #include "ui/views/controls/styled_label.h" 15 #include "ui/views/controls/styled_label.h"
16 #include "ui/views/controls/styled_label_listener.h" 16 #include "ui/views/controls/styled_label_listener.h"
17 #include "ui/views/test/views_test_base.h"
18 #include "ui/views/widget/widget.h"
17 19
18 using base::ASCIIToUTF16; 20 using base::ASCIIToUTF16;
19 21
20 namespace views { 22 namespace views {
21 23
22 class StyledLabelTest : public testing::Test, public StyledLabelListener { 24 class StyledLabelTest : public ViewsTestBase, public StyledLabelListener {
23 public: 25 public:
24 StyledLabelTest() {} 26 StyledLabelTest() {}
25 virtual ~StyledLabelTest() {} 27 virtual ~StyledLabelTest() {}
26 28
27 // StyledLabelListener implementation. 29 // StyledLabelListener implementation.
28 virtual void StyledLabelLinkClicked(const gfx::Range& range, 30 virtual void StyledLabelLinkClicked(const gfx::Range& range,
29 int event_flags) OVERRIDE {} 31 int event_flags) OVERRIDE {}
30 32
31 protected: 33 protected:
32 StyledLabel* styled() { return styled_.get(); } 34 StyledLabel* styled() { return styled_.get(); }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 StyledLabel::RangeStyleInfo style_info_red; 287 StyledLabel::RangeStyleInfo style_info_red;
286 style_info_red.color = SK_ColorRED; 288 style_info_red.color = SK_ColorRED;
287 styled()->AddStyleRange(gfx::Range(0, text_red.size()), style_info_red); 289 styled()->AddStyleRange(gfx::Range(0, text_red.size()), style_info_red);
288 290
289 StyledLabel::RangeStyleInfo style_info_link = 291 StyledLabel::RangeStyleInfo style_info_link =
290 StyledLabel::RangeStyleInfo::CreateForLink(); 292 StyledLabel::RangeStyleInfo::CreateForLink();
291 styled()->AddStyleRange(gfx::Range(text_red.size(), 293 styled()->AddStyleRange(gfx::Range(text_red.size(),
292 text_red.size() + text_link.size()), 294 text_red.size() + text_link.size()),
293 style_info_link); 295 style_info_link);
294 296
295 // Obtain the default text color for a label.
296 Label label(ASCIIToUTF16(text));
297 const SkColor kDefaultTextColor = label.enabled_color();
298
299 // Obtain the default text color for a link;
300 Link link(ASCIIToUTF16(text_link));
301 const SkColor kDefaultLinkColor = link.enabled_color();
302
303 styled()->SetBounds(0, 0, 1000, 1000); 297 styled()->SetBounds(0, 0, 1000, 1000);
304 styled()->Layout(); 298 styled()->Layout();
305 299
300 Widget* widget = new Widget();
301 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
302 widget->Init(params);
303 View* container = new View();
304 widget->SetContentsView(container);
305 container->AddChildView(styled());
306
307 // Obtain the default text color for a label.
308 Label* label = new Label(ASCIIToUTF16(text));
309 container->AddChildView(label);
310 const SkColor kDefaultTextColor = label->enabled_color();
311
312 // Obtain the default text color for a link;
313 Link* link = new Link(ASCIIToUTF16(text_link));
314 container->AddChildView(link);
315 const SkColor kDefaultLinkColor = link->enabled_color();
316
306 EXPECT_EQ(SK_ColorRED, 317 EXPECT_EQ(SK_ColorRED,
307 static_cast<Label*>(styled()->child_at(0))->enabled_color()); 318 static_cast<Label*>(styled()->child_at(0))->enabled_color());
308 EXPECT_EQ(kDefaultLinkColor, 319 EXPECT_EQ(kDefaultLinkColor,
309 static_cast<Label*>(styled()->child_at(1))->enabled_color()); 320 static_cast<Label*>(styled()->child_at(1))->enabled_color());
310 EXPECT_EQ(kDefaultTextColor, 321 EXPECT_EQ(kDefaultTextColor,
311 static_cast<Label*>(styled()->child_at(2))->enabled_color()); 322 static_cast<Label*>(styled()->child_at(2))->enabled_color());
312 }
313 323
314 TEST_F(StyledLabelTest, ColorReadability) { 324 // Test adjusted color readability.
315 const std::string text(
316 "This is a block of text that needs color adjustment.");
317 InitStyledLabel(text);
318 styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK); 325 styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK);
326 styled()->Layout();
327 label->SetBackgroundColor(SK_ColorBLACK);
319 328
320 // Obtain the text color if it were a pure label. 329 const SkColor kAdjustedTextColor = label->enabled_color();
321 Label label(ASCIIToUTF16(text)); 330 EXPECT_NE(kAdjustedTextColor, kDefaultTextColor);
322 label.SetBackgroundColor(SK_ColorBLACK); 331 EXPECT_EQ(kAdjustedTextColor,
332 static_cast<Label*>(styled()->child_at(2))->enabled_color());
323 333
324 styled()->SetBounds(0, 0, 1000, 1000); 334 widget->CloseNow();
325 styled()->Layout();
326
327 EXPECT_EQ(label.enabled_color(),
328 static_cast<Label*>(styled()->child_at(0))->enabled_color());
329 } 335 }
330 336
331 TEST_F(StyledLabelTest, StyledRangeWithTooltip) { 337 TEST_F(StyledLabelTest, StyledRangeWithTooltip) {
332 const std::string text("This is a test block of text, "); 338 const std::string text("This is a test block of text, ");
333 const std::string tooltip_text("this should have a tooltip,"); 339 const std::string tooltip_text("this should have a tooltip,");
334 const std::string normal_text(" this should not have a tooltip, "); 340 const std::string normal_text(" this should not have a tooltip, ");
335 const std::string link_text("and this should be a link"); 341 const std::string link_text("and this should be a link");
336 342
337 const size_t tooltip_start = text.size(); 343 const size_t tooltip_start = text.size();
338 const size_t link_start = 344 const size_t link_start =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 EXPECT_EQ(label.GetPreferredSize().width(), styled()->width()); 405 EXPECT_EQ(label.GetPreferredSize().width(), styled()->width());
400 } 406 }
401 407
402 TEST_F(StyledLabelTest, HandleEmptyLayout) { 408 TEST_F(StyledLabelTest, HandleEmptyLayout) {
403 const std::string text("This is a test block of text."); 409 const std::string text("This is a test block of text.");
404 InitStyledLabel(text); 410 InitStyledLabel(text);
405 styled()->Layout(); 411 styled()->Layout();
406 EXPECT_EQ(0, styled()->child_count()); 412 EXPECT_EQ(0, styled()->child_count());
407 } 413 }
408 414
409 } // namespace 415 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | ui/views/controls/textfield/textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698