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" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 0, | 117 0, |
118 styled()->GetInsets().width() + label_preferred_size.width(), | 118 styled()->GetInsets().width() + label_preferred_size.width(), |
119 styled()->GetInsets().height() + 2 * label_preferred_size.height()); | 119 styled()->GetInsets().height() + 2 * label_preferred_size.height()); |
120 styled()->Layout(); | 120 styled()->Layout(); |
121 ASSERT_EQ(2, styled()->child_count()); | 121 ASSERT_EQ(2, styled()->child_count()); |
122 EXPECT_EQ(3, styled()->child_at(0)->x()); | 122 EXPECT_EQ(3, styled()->child_at(0)->x()); |
123 EXPECT_EQ(3, styled()->child_at(0)->y()); | 123 EXPECT_EQ(3, styled()->child_at(0)->y()); |
124 EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom()); | 124 EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom()); |
125 } | 125 } |
126 | 126 |
127 TEST_F(StyledLabelTest, WrapLongWords) { | |
128 const std::string text("Thisistextasasingleword"); | |
msw
2015/05/13 23:05:39
nit: camel case words :)
tbarzic
2015/05/14 00:02:28
Done.
| |
129 InitStyledLabel(text); | |
130 Label label(ASCIIToUTF16(text.substr(0, text.size() * 2 / 3))); | |
131 gfx::Size label_preferred_size = label.GetPreferredSize(); | |
132 EXPECT_EQ(label_preferred_size.height() * 2, | |
133 StyledLabelContentHeightForWidth(label_preferred_size.width())); | |
134 | |
135 styled()->SetBorder(Border::CreateEmptyBorder(3, 3, 3, 3)); | |
msw
2015/05/13 23:05:40
Is this 3px border necessary? Would no border simp
tbarzic
2015/05/14 00:02:28
wouldn't really simplify it, but it's not essentia
| |
136 styled()->SetBounds( | |
137 0, 0, styled()->GetInsets().width() + label_preferred_size.width(), | |
138 styled()->GetInsets().height() + 2 * label_preferred_size.height()); | |
139 styled()->Layout(); | |
140 ASSERT_EQ(2, styled()->child_count()); | |
141 EXPECT_EQ(3, styled()->child_at(0)->x()); | |
msw
2015/05/13 23:05:40
nit: check if the origin is equal to gfx::Point()
tbarzic
2015/05/14 00:02:28
Done.
| |
142 EXPECT_EQ(3, styled()->child_at(0)->y()); | |
143 EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom()); | |
144 EXPECT_FALSE(static_cast<Label*>(styled()->child_at(0))->text().empty()); | |
145 EXPECT_FALSE(static_cast<Label*>(styled()->child_at(1))->text().empty()); | |
146 EXPECT_EQ(ASCIIToUTF16(text), | |
147 static_cast<Label*>(styled()->child_at(0))->text() + | |
148 static_cast<Label*>(styled()->child_at(1))->text()); | |
149 } | |
150 | |
127 TEST_F(StyledLabelTest, CreateLinks) { | 151 TEST_F(StyledLabelTest, CreateLinks) { |
128 const std::string text("This is a test block of text."); | 152 const std::string text("This is a test block of text."); |
129 InitStyledLabel(text); | 153 InitStyledLabel(text); |
130 | 154 |
131 // Without links, there should be no focus border. | 155 // Without links, there should be no focus border. |
132 EXPECT_TRUE(styled()->GetInsets().empty()); | 156 EXPECT_TRUE(styled()->GetInsets().empty()); |
133 | 157 |
134 // Now let's add some links. | 158 // Now let's add some links. |
135 styled()->AddStyleRange(gfx::Range(0, 1), | 159 styled()->AddStyleRange(gfx::Range(0, 1), |
136 StyledLabel::RangeStyleInfo::CreateForLink()); | 160 StyledLabel::RangeStyleInfo::CreateForLink()); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 // all controls should be recreated | 484 // all controls should be recreated |
461 styled()->SetText(another_text); | 485 styled()->SetText(another_text); |
462 int updated_height = styled()->GetHeightForWidth(styled()->width()); | 486 int updated_height = styled()->GetHeightForWidth(styled()->width()); |
463 EXPECT_NE(updated_height, real_height); | 487 EXPECT_NE(updated_height, real_height); |
464 View* first_child_after_text_update = styled()->has_children() ? | 488 View* first_child_after_text_update = styled()->has_children() ? |
465 styled()->child_at(0) : nullptr; | 489 styled()->child_at(0) : nullptr; |
466 EXPECT_NE(first_child_after_text_update, first_child_after_layout); | 490 EXPECT_NE(first_child_after_text_update, first_child_after_layout); |
467 } | 491 } |
468 | 492 |
469 } // namespace views | 493 } // namespace views |
OLD | NEW |