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 "ui/views/controls/styled_label.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
| 9 #include <memory> |
7 #include <string> | 10 #include <string> |
8 | 11 |
9 #include "base/macros.h" | 12 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/gfx/font_list.h" | 16 #include "ui/gfx/font_list.h" |
15 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
16 #include "ui/views/controls/link.h" | 18 #include "ui/views/controls/link.h" |
17 #include "ui/views/controls/styled_label.h" | |
18 #include "ui/views/controls/styled_label_listener.h" | 19 #include "ui/views/controls/styled_label_listener.h" |
19 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 | 22 |
22 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
23 | 24 |
24 namespace views { | 25 namespace views { |
25 | 26 |
26 class StyledLabelTest : public ViewsTestBase, public StyledLabelListener { | 27 class StyledLabelTest : public ViewsTestBase, public StyledLabelListener { |
27 public: | 28 public: |
(...skipping 11 matching lines...) Expand all Loading... |
39 void InitStyledLabel(const std::string& ascii_text) { | 40 void InitStyledLabel(const std::string& ascii_text) { |
40 styled_.reset(new StyledLabel(ASCIIToUTF16(ascii_text), this)); | 41 styled_.reset(new StyledLabel(ASCIIToUTF16(ascii_text), this)); |
41 styled_->set_owned_by_client(); | 42 styled_->set_owned_by_client(); |
42 } | 43 } |
43 | 44 |
44 int StyledLabelContentHeightForWidth(int w) { | 45 int StyledLabelContentHeightForWidth(int w) { |
45 return styled_->GetHeightForWidth(w) - styled_->GetInsets().height(); | 46 return styled_->GetHeightForWidth(w) - styled_->GetInsets().height(); |
46 } | 47 } |
47 | 48 |
48 private: | 49 private: |
49 scoped_ptr<StyledLabel> styled_; | 50 std::unique_ptr<StyledLabel> styled_; |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(StyledLabelTest); | 52 DISALLOW_COPY_AND_ASSIGN(StyledLabelTest); |
52 }; | 53 }; |
53 | 54 |
54 TEST_F(StyledLabelTest, NoWrapping) { | 55 TEST_F(StyledLabelTest, NoWrapping) { |
55 const std::string text("This is a test block of text"); | 56 const std::string text("This is a test block of text"); |
56 InitStyledLabel(text); | 57 InitStyledLabel(text); |
57 Label label(ASCIIToUTF16(text)); | 58 Label label(ASCIIToUTF16(text)); |
58 const gfx::Size label_preferred_size = label.GetPreferredSize(); | 59 const gfx::Size label_preferred_size = label.GetPreferredSize(); |
59 EXPECT_EQ(label_preferred_size.height(), | 60 EXPECT_EQ(label_preferred_size.height(), |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // all controls should be recreated | 499 // all controls should be recreated |
499 styled()->SetText(another_text); | 500 styled()->SetText(another_text); |
500 int updated_height = styled()->GetHeightForWidth(styled()->width()); | 501 int updated_height = styled()->GetHeightForWidth(styled()->width()); |
501 EXPECT_NE(updated_height, real_height); | 502 EXPECT_NE(updated_height, real_height); |
502 View* first_child_after_text_update = styled()->has_children() ? | 503 View* first_child_after_text_update = styled()->has_children() ? |
503 styled()->child_at(0) : nullptr; | 504 styled()->child_at(0) : nullptr; |
504 EXPECT_NE(first_child_after_text_update, first_child_after_layout); | 505 EXPECT_NE(first_child_after_text_update, first_child_after_layout); |
505 } | 506 } |
506 | 507 |
507 } // namespace views | 508 } // namespace views |
OLD | NEW |