| Index: ui/views/controls/styled_label_unittest.cc
|
| ===================================================================
|
| --- ui/views/controls/styled_label_unittest.cc (revision 239550)
|
| +++ ui/views/controls/styled_label_unittest.cc (working copy)
|
| @@ -7,15 +7,17 @@
|
| #include "base/basictypes.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkColor.h"
|
| #include "ui/views/controls/link.h"
|
| #include "ui/views/controls/styled_label.h"
|
| #include "ui/views/controls/styled_label_listener.h"
|
| +#include "ui/views/test/views_test_base.h"
|
| +#include "ui/views/widget/native_widget.h"
|
| +#include "ui/views/widget/root_view.h"
|
|
|
| namespace views {
|
|
|
| -class StyledLabelTest : public testing::Test, public StyledLabelListener {
|
| +class StyledLabelTest : public ViewsTestBase, public StyledLabelListener {
|
| public:
|
| StyledLabelTest() {}
|
| virtual ~StyledLabelTest() {}
|
| @@ -29,6 +31,7 @@
|
|
|
| void InitStyledLabel(const std::string& ascii_text) {
|
| styled_.reset(new StyledLabel(ASCIIToUTF16(ascii_text), this));
|
| + styled_->set_owned_by_client();
|
| }
|
|
|
| int StyledLabelContentHeightForWidth(int w) {
|
| @@ -112,15 +115,29 @@
|
| styled()->GetInsets().height() + 2 * label_preferred_size.height());
|
| styled()->Layout();
|
| ASSERT_EQ(2, styled()->child_count());
|
| - EXPECT_EQ(3, styled()->child_at(0)->bounds().x());
|
| - EXPECT_EQ(3, styled()->child_at(0)->bounds().y());
|
| - EXPECT_EQ(styled()->bounds().height() - 3,
|
| - styled()->child_at(1)->bounds().bottom());
|
| + EXPECT_EQ(3, styled()->child_at(0)->x());
|
| + EXPECT_EQ(3, styled()->child_at(0)->y());
|
| + EXPECT_EQ(styled()->height() - 3, styled()->child_at(1)->bounds().bottom());
|
| }
|
|
|
| TEST_F(StyledLabelTest, CreateLinks) {
|
| const std::string text("This is a test block of text.");
|
| InitStyledLabel(text);
|
| +
|
| + // By default styled() should not have a focus border because it's not drawn.
|
| + EXPECT_TRUE(styled()->GetInsets().empty());
|
| +
|
| + // Without links, there should be no focus border even when drawn.
|
| + scoped_ptr<Widget> widget(new Widget);
|
| + Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
|
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
| + widget->Init(params);
|
| + internal::RootView* root =
|
| + static_cast<internal::RootView*>(widget->GetRootView());
|
| + root->AddChildView(styled());
|
| + EXPECT_TRUE(styled()->GetInsets().empty());
|
| +
|
| + // Now let's add some links.
|
| styled()->AddStyleRange(gfx::Range(0, 1),
|
| StyledLabel::RangeStyleInfo::CreateForLink());
|
| styled()->AddStyleRange(gfx::Range(1, 2),
|
| @@ -130,9 +147,17 @@
|
| styled()->AddStyleRange(gfx::Range(12, 13),
|
| StyledLabel::RangeStyleInfo::CreateForLink());
|
|
|
| + // Now there should be a focus border because there are non-empty Links.
|
| + EXPECT_FALSE(styled()->GetInsets().empty());
|
| +
|
| + // Verify layout creates the right number of children.
|
| styled()->SetBounds(0, 0, 1000, 1000);
|
| styled()->Layout();
|
| - ASSERT_EQ(7, styled()->child_count());
|
| + EXPECT_EQ(7, styled()->child_count());
|
| +
|
| + // Removing styled() from the root should remove the focus border.
|
| + root->RemoveChildView(styled());
|
| + EXPECT_TRUE(styled()->GetInsets().empty());
|
| }
|
|
|
| TEST_F(StyledLabelTest, DontBreakLinks) {
|
| @@ -152,13 +177,13 @@
|
| styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height);
|
| styled()->Layout();
|
| ASSERT_EQ(2, styled()->child_count());
|
| - EXPECT_EQ(0, styled()->child_at(0)->bounds().x());
|
| - EXPECT_EQ(0, styled()->child_at(1)->bounds().x());
|
| + EXPECT_EQ(0, styled()->child_at(0)->x());
|
| + EXPECT_EQ(0, styled()->child_at(1)->x());
|
| }
|
|
|
| TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) {
|
| const std::string text("This is a test block of text, ");
|
| - const std::string unbreakable_text("and this should not be breaked");
|
| + const std::string unbreakable_text("and this should not be broken");
|
| InitStyledLabel(text + unbreakable_text);
|
| StyledLabel::RangeStyleInfo style_info;
|
| style_info.disable_line_wrapping = true;
|
| @@ -176,8 +201,8 @@
|
| styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height);
|
| styled()->Layout();
|
| ASSERT_EQ(2, styled()->child_count());
|
| - EXPECT_EQ(0, styled()->child_at(0)->bounds().x());
|
| - EXPECT_EQ(0, styled()->child_at(1)->bounds().x());
|
| + EXPECT_EQ(0, styled()->child_at(0)->x());
|
| + EXPECT_EQ(0, styled()->child_at(1)->x());
|
| }
|
|
|
| TEST_F(StyledLabelTest, StyledRangeUnderlined) {
|
| @@ -229,7 +254,7 @@
|
| StyledLabel unstyled(ASCIIToUTF16(bold_text), this);
|
| unstyled.SetBounds(0, 0, styled_width, pref_height);
|
| unstyled.Layout();
|
| - ASSERT_EQ(1, unstyled.child_count());
|
| + EXPECT_EQ(1, unstyled.child_count());
|
|
|
| styled()->SetBounds(0, 0, styled_width, pref_height);
|
| styled()->Layout();
|
| @@ -251,10 +276,10 @@
|
| static_cast<Label*>(styled()->child_at(2))->font().GetStyle());
|
|
|
| // The second bold part should start on a new line.
|
| - EXPECT_EQ(0, styled()->child_at(0)->bounds().x());
|
| - EXPECT_EQ(0, styled()->child_at(1)->bounds().x());
|
| - EXPECT_EQ(styled()->child_at(1)->bounds().right() - 2,
|
| - styled()->child_at(2)->bounds().x());
|
| + EXPECT_EQ(0, styled()->child_at(0)->x());
|
| + EXPECT_EQ(0, styled()->child_at(1)->x());
|
| + EXPECT_EQ(styled()->child_at(1)->bounds().right(),
|
| + styled()->child_at(2)->x());
|
| }
|
|
|
| TEST_F(StyledLabelTest, Color) {
|
| @@ -342,13 +367,13 @@
|
| EXPECT_EQ(label_preferred_size.width(), styled()->width());
|
|
|
| ASSERT_EQ(5, styled()->child_count());
|
| - EXPECT_EQ(0, styled()->child_at(0)->bounds().x());
|
| - EXPECT_EQ(styled()->child_at(0)->bounds().right() - 2,
|
| - styled()->child_at(1)->bounds().x());
|
| - EXPECT_EQ(0, styled()->child_at(2)->bounds().x());
|
| - EXPECT_EQ(styled()->child_at(2)->bounds().right() - 2,
|
| - styled()->child_at(3)->bounds().x());
|
| - EXPECT_EQ(0, styled()->child_at(4)->bounds().x());
|
| + EXPECT_EQ(0, styled()->child_at(0)->x());
|
| + EXPECT_EQ(styled()->child_at(0)->bounds().right(),
|
| + styled()->child_at(1)->x());
|
| + EXPECT_EQ(0, styled()->child_at(2)->x());
|
| + EXPECT_EQ(styled()->child_at(2)->bounds().right(),
|
| + styled()->child_at(3)->x());
|
| + EXPECT_EQ(0, styled()->child_at(4)->x());
|
|
|
| string16 tooltip;
|
| EXPECT_TRUE(
|
| @@ -360,10 +385,10 @@
|
| }
|
|
|
| TEST_F(StyledLabelTest, HandleEmptyLayout) {
|
| - const std::string text("This is a test block of text, ");
|
| + const std::string text("This is a test block of text.");
|
| InitStyledLabel(text);
|
| styled()->Layout();
|
| - ASSERT_EQ(0, styled()->child_count());
|
| + EXPECT_EQ(0, styled()->child_count());
|
| }
|
|
|
| } // namespace
|
|
|