OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 8 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
9 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 virtual gfx::Size GetPreferredSize() OVERRIDE { | 22 virtual gfx::Size GetPreferredSize() OVERRIDE { |
23 return size_; | 23 return size_; |
24 } | 24 } |
25 | 25 |
26 private: | 26 private: |
27 const gfx::Size size_; | 27 const gfx::Size size_; |
28 | 28 |
29 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); | 29 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); |
30 }; | 30 }; |
31 | 31 |
32 class TabbedPaneTest : public ViewsTestBase, | 32 class TabbedPaneWinTest : public ViewsTestBase, |
33 public WidgetDelegate { | 33 public WidgetDelegate { |
34 public: | 34 public: |
35 TabbedPaneTest() {} | 35 TabbedPaneWinTest() {} |
36 | 36 |
37 TabbedPane* tabbed_pane_; | 37 TabbedPane* tabbed_pane_; |
38 | 38 |
39 private: | 39 private: |
40 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
41 ViewsTestBase::SetUp(); | 41 ViewsTestBase::SetUp(); |
42 tabbed_pane_ = new TabbedPane(); | 42 tabbed_pane_ = new TabbedPane(); |
43 tabbed_pane_->set_use_native_win_control(true); | 43 tabbed_pane_->set_use_native_win_control(true); |
44 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); | 44 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); |
45 window_->Show(); | 45 window_->Show(); |
46 } | 46 } |
47 | 47 |
48 virtual void TearDown() OVERRIDE { | 48 virtual void TearDown() OVERRIDE { |
49 window_->Close(); | 49 window_->Close(); |
50 ViewsTestBase::TearDown(); | 50 ViewsTestBase::TearDown(); |
51 } | 51 } |
52 | 52 |
53 virtual views::View* GetContentsView() OVERRIDE { | 53 virtual views::View* GetContentsView() OVERRIDE { |
54 return tabbed_pane_; | 54 return tabbed_pane_; |
55 } | 55 } |
56 virtual views::Widget* GetWidget() OVERRIDE { | 56 virtual views::Widget* GetWidget() OVERRIDE { |
57 return tabbed_pane_->GetWidget(); | 57 return tabbed_pane_->GetWidget(); |
58 } | 58 } |
59 virtual const views::Widget* GetWidget() const OVERRIDE { | 59 virtual const views::Widget* GetWidget() const OVERRIDE { |
60 return tabbed_pane_->GetWidget(); | 60 return tabbed_pane_->GetWidget(); |
61 } | 61 } |
62 | 62 |
63 Widget* window_; | 63 Widget* window_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest); | 65 DISALLOW_COPY_AND_ASSIGN(TabbedPaneWinTest); |
66 }; | 66 }; |
67 | 67 |
68 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). | 68 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
69 TEST_F(TabbedPaneTest, SizeAndLayout) { | 69 TEST_F(TabbedPaneWinTest, SizeAndLayout) { |
70 View* child1 = new FixedSizeView(gfx::Size(20, 10)); | 70 View* child1 = new FixedSizeView(gfx::Size(20, 10)); |
71 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); | 71 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); |
72 View* child2 = new FixedSizeView(gfx::Size(5, 5)); | 72 View* child2 = new FixedSizeView(gfx::Size(5, 5)); |
73 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); | 73 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); |
74 tabbed_pane_->SelectTabAt(0); | 74 tabbed_pane_->SelectTabAt(0); |
75 | 75 |
76 // Check that the preferred size is larger than the largest child. | 76 // Check that the preferred size is larger than the largest child. |
77 gfx::Size pref(tabbed_pane_->GetPreferredSize()); | 77 gfx::Size pref(tabbed_pane_->GetPreferredSize()); |
78 EXPECT_GT(pref.width(), 20); | 78 EXPECT_GT(pref.width(), 20); |
79 EXPECT_GT(pref.height(), 10); | 79 EXPECT_GT(pref.height(), 10); |
80 | 80 |
81 // The bounds of our children should be smaller than the tabbed pane's bounds. | 81 // The bounds of our children should be smaller than the tabbed pane's bounds. |
82 tabbed_pane_->SetBounds(0, 0, 100, 200); | 82 tabbed_pane_->SetBounds(0, 0, 100, 200); |
83 RunPendingMessages(); | 83 RunPendingMessages(); |
84 gfx::Rect bounds(child1->bounds()); | 84 gfx::Rect bounds(child1->bounds()); |
85 EXPECT_GT(bounds.width(), 0); | 85 EXPECT_GT(bounds.width(), 0); |
86 EXPECT_LT(bounds.width(), 100); | 86 EXPECT_LT(bounds.width(), 100); |
87 EXPECT_GT(bounds.height(), 0); | 87 EXPECT_GT(bounds.height(), 0); |
88 EXPECT_LT(bounds.height(), 200); | 88 EXPECT_LT(bounds.height(), 200); |
89 | 89 |
90 // If we switch to the other tab, it should get assigned the same bounds. | 90 // If we switch to the other tab, it should get assigned the same bounds. |
91 tabbed_pane_->SelectTabAt(1); | 91 tabbed_pane_->SelectTabAt(1); |
92 EXPECT_EQ(bounds, child2->bounds()); | 92 EXPECT_EQ(bounds, child2->bounds()); |
93 } | 93 } |
94 | 94 |
95 TEST_F(TabbedPaneTest, AddRemove) { | 95 TEST_F(TabbedPaneWinTest, AddRemove) { |
96 View* tab0 = new View; | 96 View* tab0 = new View; |
97 tabbed_pane_->AddTab(ASCIIToUTF16("tab0"), tab0); | 97 tabbed_pane_->AddTab(ASCIIToUTF16("tab0"), tab0); |
98 EXPECT_EQ(tab0, tabbed_pane_->GetSelectedTab()); | 98 EXPECT_EQ(tab0, tabbed_pane_->GetSelectedTab()); |
99 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 99 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
100 | 100 |
101 // Add more 3 tabs. | 101 // Add more 3 tabs. |
102 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), new View); | 102 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), new View); |
103 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), new View); | 103 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), new View); |
104 tabbed_pane_->AddTab(ASCIIToUTF16("tab3"), new View); | 104 tabbed_pane_->AddTab(ASCIIToUTF16("tab3"), new View); |
105 EXPECT_EQ(4, tabbed_pane_->GetTabCount()); | 105 EXPECT_EQ(4, tabbed_pane_->GetTabCount()); |
(...skipping 22 matching lines...) Expand all Loading... |
128 // Now change the selected tab. | 128 // Now change the selected tab. |
129 tabbed_pane_->SelectTabAt(1); | 129 tabbed_pane_->SelectTabAt(1); |
130 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 130 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
131 | 131 |
132 // Remove the first one. | 132 // Remove the first one. |
133 delete tabbed_pane_->RemoveTabAtIndex(0); | 133 delete tabbed_pane_->RemoveTabAtIndex(0); |
134 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 134 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
135 } | 135 } |
136 | 136 |
137 } // namespace views | 137 } // namespace views |
OLD | NEW |