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

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

Issue 2348433002: Make styled-label trimming less agressive, allowing whitespace (Closed)
Patch Set: Added test coverage, fixed empty line output for styled_label Created 4 years 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
« no previous file with comments | « ui/views/controls/styled_label.cc ('k') | no next file » | 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 "ui/views/controls/styled_label.h" 5 #include "ui/views/controls/styled_label.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 styled()->SetBounds(0, 0, 1000, 1000); 82 styled()->SetBounds(0, 0, 1000, 1000);
83 styled()->Layout(); 83 styled()->Layout();
84 84
85 ASSERT_EQ(1, styled()->child_count()); 85 ASSERT_EQ(1, styled()->child_count());
86 ASSERT_EQ(std::string(Label::kViewClassName), 86 ASSERT_EQ(std::string(Label::kViewClassName),
87 styled()->child_at(0)->GetClassName()); 87 styled()->child_at(0)->GetClassName());
88 EXPECT_EQ(ASCIIToUTF16(" This is a test block of text"), 88 EXPECT_EQ(ASCIIToUTF16(" This is a test block of text"),
89 static_cast<Label*>(styled()->child_at(0))->text()); 89 static_cast<Label*>(styled()->child_at(0))->text());
90 } 90 }
91 91
92 TEST_F(StyledLabelTest, RespectLeadingSpacesInNonFirstLine) {
93 const std::string indented_line = " indented with space line";
94 const std::string text(std::string("First line\n") + indented_line);
95 InitStyledLabel(text);
96 styled()->SetBounds(0, 0, 1000, 1000);
97 styled()->Layout();
98 ASSERT_EQ(2, styled()->child_count());
99 ASSERT_EQ(std::string(Label::kViewClassName),
100 styled()->child_at(0)->GetClassName());
101 EXPECT_EQ(ASCIIToUTF16(indented_line),
Evan Stade 2016/12/05 17:12:14 can you test what would happen if we naturally wra
102 static_cast<Label*>(styled()->child_at(1))->text());
103 }
104
92 TEST_F(StyledLabelTest, FirstLineNotEmptyWhenLeadingWhitespaceTooLong) { 105 TEST_F(StyledLabelTest, FirstLineNotEmptyWhenLeadingWhitespaceTooLong) {
93 const std::string text(" a"); 106 const std::string text(" a");
94 InitStyledLabel(text); 107 InitStyledLabel(text);
95 108
96 Label label(ASCIIToUTF16(text)); 109 Label label(ASCIIToUTF16(text));
97 gfx::Size label_preferred_size = label.GetPreferredSize(); 110 gfx::Size label_preferred_size = label.GetPreferredSize();
98 111
99 styled()->SetBounds(0, 0, label_preferred_size.width() / 2, 1000); 112 styled()->SetBounds(0, 0, label_preferred_size.width() / 2, 1000);
100 styled()->Layout(); 113 styled()->Layout();
101 114
(...skipping 19 matching lines...) Expand all
121 0, 134 0,
122 styled()->GetInsets().width() + label_preferred_size.width(), 135 styled()->GetInsets().width() + label_preferred_size.width(),
123 styled()->GetInsets().height() + 2 * label_preferred_size.height()); 136 styled()->GetInsets().height() + 2 * label_preferred_size.height());
124 styled()->Layout(); 137 styled()->Layout();
125 ASSERT_EQ(2, styled()->child_count()); 138 ASSERT_EQ(2, styled()->child_count());
126 EXPECT_EQ(3, styled()->child_at(0)->x()); 139 EXPECT_EQ(3, styled()->child_at(0)->x());
127 EXPECT_EQ(3, styled()->child_at(0)->y()); 140 EXPECT_EQ(3, styled()->child_at(0)->y());
128 EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom()); 141 EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom());
129 } 142 }
130 143
144 TEST_F(StyledLabelTest, AllowEmptyLines) {
145 const std::string text("one");
146 InitStyledLabel(text);
147 int default_height = styled()->GetHeightForWidth(1000);
148 const std::string multiline_text("one\n\nthree");
149 InitStyledLabel(multiline_text);
150 styled()->SetBounds(0, 0, 1000, 1000);
151 styled()->Layout();
152 EXPECT_EQ(3 * default_height, styled()->GetHeightForWidth(1000));
153 ASSERT_EQ(2, styled()->child_count());
154 EXPECT_EQ(styled()->GetHeightForWidth(1000),
155 styled()->child_at(1)->bounds().bottom());
156 }
157
131 TEST_F(StyledLabelTest, WrapLongWords) { 158 TEST_F(StyledLabelTest, WrapLongWords) {
132 const std::string text("ThisIsTextAsASingleWord"); 159 const std::string text("ThisIsTextAsASingleWord");
133 InitStyledLabel(text); 160 InitStyledLabel(text);
134 Label label(ASCIIToUTF16(text.substr(0, text.size() * 2 / 3))); 161 Label label(ASCIIToUTF16(text.substr(0, text.size() * 2 / 3)));
135 gfx::Size label_preferred_size = label.GetPreferredSize(); 162 gfx::Size label_preferred_size = label.GetPreferredSize();
136 EXPECT_EQ(label_preferred_size.height() * 2, 163 EXPECT_EQ(label_preferred_size.height() * 2,
137 StyledLabelContentHeightForWidth(label_preferred_size.width())); 164 StyledLabelContentHeightForWidth(label_preferred_size.width()));
138 165
139 styled()->SetBounds( 166 styled()->SetBounds(
140 0, 0, styled()->GetInsets().width() + label_preferred_size.width(), 167 0, 0, styled()->GetInsets().width() + label_preferred_size.width(),
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // all controls should be recreated 539 // all controls should be recreated
513 styled()->SetText(another_text); 540 styled()->SetText(another_text);
514 int updated_height = styled()->GetHeightForWidth(styled()->width()); 541 int updated_height = styled()->GetHeightForWidth(styled()->width());
515 EXPECT_NE(updated_height, real_height); 542 EXPECT_NE(updated_height, real_height);
516 View* first_child_after_text_update = styled()->has_children() ? 543 View* first_child_after_text_update = styled()->has_children() ?
517 styled()->child_at(0) : nullptr; 544 styled()->child_at(0) : nullptr;
518 EXPECT_NE(first_child_after_text_update, first_child_after_layout); 545 EXPECT_NE(first_child_after_text_update, first_child_after_layout);
519 } 546 }
520 547
521 } // namespace views 548 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/styled_label.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698