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"); |
| 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()->SetBounds( |
| 136 0, 0, styled()->GetInsets().width() + label_preferred_size.width(), |
| 137 styled()->GetInsets().height() + 2 * label_preferred_size.height()); |
| 138 styled()->Layout(); |
| 139 |
| 140 ASSERT_EQ(2, styled()->child_count()); |
| 141 ASSERT_EQ(gfx::Point(), styled()->bounds().origin()); |
| 142 EXPECT_EQ(gfx::Point(), styled()->child_at(0)->bounds().origin()); |
| 143 EXPECT_EQ(gfx::Point(0, styled()->height() / 2), |
| 144 styled()->child_at(1)->bounds().origin()); |
| 145 |
| 146 EXPECT_FALSE(static_cast<Label*>(styled()->child_at(0))->text().empty()); |
| 147 EXPECT_FALSE(static_cast<Label*>(styled()->child_at(1))->text().empty()); |
| 148 EXPECT_EQ(ASCIIToUTF16(text), |
| 149 static_cast<Label*>(styled()->child_at(0))->text() + |
| 150 static_cast<Label*>(styled()->child_at(1))->text()); |
| 151 } |
| 152 |
127 TEST_F(StyledLabelTest, CreateLinks) { | 153 TEST_F(StyledLabelTest, CreateLinks) { |
128 const std::string text("This is a test block of text."); | 154 const std::string text("This is a test block of text."); |
129 InitStyledLabel(text); | 155 InitStyledLabel(text); |
130 | 156 |
131 // Without links, there should be no focus border. | 157 // Without links, there should be no focus border. |
132 EXPECT_TRUE(styled()->GetInsets().empty()); | 158 EXPECT_TRUE(styled()->GetInsets().empty()); |
133 | 159 |
134 // Now let's add some links. | 160 // Now let's add some links. |
135 styled()->AddStyleRange(gfx::Range(0, 1), | 161 styled()->AddStyleRange(gfx::Range(0, 1), |
136 StyledLabel::RangeStyleInfo::CreateForLink()); | 162 StyledLabel::RangeStyleInfo::CreateForLink()); |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 // all controls should be recreated | 486 // all controls should be recreated |
461 styled()->SetText(another_text); | 487 styled()->SetText(another_text); |
462 int updated_height = styled()->GetHeightForWidth(styled()->width()); | 488 int updated_height = styled()->GetHeightForWidth(styled()->width()); |
463 EXPECT_NE(updated_height, real_height); | 489 EXPECT_NE(updated_height, real_height); |
464 View* first_child_after_text_update = styled()->has_children() ? | 490 View* first_child_after_text_update = styled()->has_children() ? |
465 styled()->child_at(0) : nullptr; | 491 styled()->child_at(0) : nullptr; |
466 EXPECT_NE(first_child_after_text_update, first_child_after_layout); | 492 EXPECT_NE(first_child_after_text_update, first_child_after_layout); |
467 } | 493 } |
468 | 494 |
469 } // namespace views | 495 } // namespace views |
OLD | NEW |