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

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

Issue 259073004: Revert of retry r266042: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
19 17
20 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
21 19
22 namespace views { 20 namespace views {
23 21
24 class StyledLabelTest : public ViewsTestBase, public StyledLabelListener { 22 class StyledLabelTest : public testing::Test, public StyledLabelListener {
25 public: 23 public:
26 StyledLabelTest() {} 24 StyledLabelTest() {}
27 virtual ~StyledLabelTest() {} 25 virtual ~StyledLabelTest() {}
28 26
29 // StyledLabelListener implementation. 27 // StyledLabelListener implementation.
30 virtual void StyledLabelLinkClicked(const gfx::Range& range, 28 virtual void StyledLabelLinkClicked(const gfx::Range& range,
31 int event_flags) OVERRIDE {} 29 int event_flags) OVERRIDE {}
32 30
33 protected: 31 protected:
34 StyledLabel* styled() { return styled_.get(); } 32 StyledLabel* styled() { return styled_.get(); }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 StyledLabel::RangeStyleInfo style_info_red; 285 StyledLabel::RangeStyleInfo style_info_red;
288 style_info_red.color = SK_ColorRED; 286 style_info_red.color = SK_ColorRED;
289 styled()->AddStyleRange(gfx::Range(0, text_red.size()), style_info_red); 287 styled()->AddStyleRange(gfx::Range(0, text_red.size()), style_info_red);
290 288
291 StyledLabel::RangeStyleInfo style_info_link = 289 StyledLabel::RangeStyleInfo style_info_link =
292 StyledLabel::RangeStyleInfo::CreateForLink(); 290 StyledLabel::RangeStyleInfo::CreateForLink();
293 styled()->AddStyleRange(gfx::Range(text_red.size(), 291 styled()->AddStyleRange(gfx::Range(text_red.size(),
294 text_red.size() + text_link.size()), 292 text_red.size() + text_link.size()),
295 style_info_link); 293 style_info_link);
296 294
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
297 styled()->SetBounds(0, 0, 1000, 1000); 303 styled()->SetBounds(0, 0, 1000, 1000);
298 styled()->Layout(); 304 styled()->Layout();
299 305
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
317 EXPECT_EQ(SK_ColorRED, 306 EXPECT_EQ(SK_ColorRED,
318 static_cast<Label*>(styled()->child_at(0))->enabled_color()); 307 static_cast<Label*>(styled()->child_at(0))->enabled_color());
319 EXPECT_EQ(kDefaultLinkColor, 308 EXPECT_EQ(kDefaultLinkColor,
320 static_cast<Label*>(styled()->child_at(1))->enabled_color()); 309 static_cast<Label*>(styled()->child_at(1))->enabled_color());
321 EXPECT_EQ(kDefaultTextColor, 310 EXPECT_EQ(kDefaultTextColor,
322 static_cast<Label*>(styled()->child_at(2))->enabled_color()); 311 static_cast<Label*>(styled()->child_at(2))->enabled_color());
312 }
323 313
324 // Test adjusted color readability. 314 TEST_F(StyledLabelTest, ColorReadability) {
315 const std::string text(
316 "This is a block of text that needs color adjustment.");
317 InitStyledLabel(text);
325 styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK); 318 styled()->SetDisplayedOnBackgroundColor(SK_ColorBLACK);
319
320 // Obtain the text color if it were a pure label.
321 Label label(ASCIIToUTF16(text));
322 label.SetBackgroundColor(SK_ColorBLACK);
323
324 styled()->SetBounds(0, 0, 1000, 1000);
326 styled()->Layout(); 325 styled()->Layout();
327 label->SetBackgroundColor(SK_ColorBLACK);
328 326
329 const SkColor kAdjustedTextColor = label->enabled_color(); 327 EXPECT_EQ(label.enabled_color(),
330 EXPECT_NE(kAdjustedTextColor, kDefaultTextColor); 328 static_cast<Label*>(styled()->child_at(0))->enabled_color());
331 EXPECT_EQ(kAdjustedTextColor,
332 static_cast<Label*>(styled()->child_at(2))->enabled_color());
333
334 widget->CloseNow();
335 } 329 }
336 330
337 TEST_F(StyledLabelTest, StyledRangeWithTooltip) { 331 TEST_F(StyledLabelTest, StyledRangeWithTooltip) {
338 const std::string text("This is a test block of text, "); 332 const std::string text("This is a test block of text, ");
339 const std::string tooltip_text("this should have a tooltip,"); 333 const std::string tooltip_text("this should have a tooltip,");
340 const std::string normal_text(" this should not have a tooltip, "); 334 const std::string normal_text(" this should not have a tooltip, ");
341 const std::string link_text("and this should be a link"); 335 const std::string link_text("and this should be a link");
342 336
343 const size_t tooltip_start = text.size(); 337 const size_t tooltip_start = text.size();
344 const size_t link_start = 338 const size_t link_start =
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 EXPECT_EQ(label.GetPreferredSize().width(), styled()->width()); 399 EXPECT_EQ(label.GetPreferredSize().width(), styled()->width());
406 } 400 }
407 401
408 TEST_F(StyledLabelTest, HandleEmptyLayout) { 402 TEST_F(StyledLabelTest, HandleEmptyLayout) {
409 const std::string text("This is a test block of text."); 403 const std::string text("This is a test block of text.");
410 InitStyledLabel(text); 404 InitStyledLabel(text);
411 styled()->Layout(); 405 styled()->Layout();
412 EXPECT_EQ(0, styled()->child_count()); 406 EXPECT_EQ(0, styled()->child_count());
413 } 407 }
414 408
415 } // namespace views 409 } // namespace
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