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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" | 9 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 EXPECT_GT(bounds.width(), 0); | 93 EXPECT_GT(bounds.width(), 0); |
94 // The |tabbed_pane_| has no border. Therefore the children should be as wide | 94 // The |tabbed_pane_| has no border. Therefore the children should be as wide |
95 // as the |tabbed_pane_|. | 95 // as the |tabbed_pane_|. |
96 EXPECT_LE(bounds.width(), 100); | 96 EXPECT_LE(bounds.width(), 100); |
97 EXPECT_GT(bounds.height(), 0); | 97 EXPECT_GT(bounds.height(), 0); |
98 EXPECT_LT(bounds.height(), 200); | 98 EXPECT_LT(bounds.height(), 200); |
99 | 99 |
100 // If we switch to the other tab, it should get assigned the same bounds. | 100 // If we switch to the other tab, it should get assigned the same bounds. |
101 tabbed_pane->SelectTabAt(1); | 101 tabbed_pane->SelectTabAt(1); |
102 EXPECT_EQ(bounds, child2->bounds()); | 102 EXPECT_EQ(bounds, child2->bounds()); |
| 103 |
| 104 // Clean up. |
| 105 delete tabbed_pane->RemoveTabAtIndex(0); |
| 106 EXPECT_EQ(1, tabbed_pane->GetTabCount()); |
| 107 delete tabbed_pane->RemoveTabAtIndex(0); |
| 108 EXPECT_EQ(0, tabbed_pane->GetTabCount()); |
103 } | 109 } |
104 | 110 |
105 void TabbedPaneTest::TestAddRemove(TabbedPane* tabbed_pane) { | 111 void TabbedPaneTest::TestAddRemove(TabbedPane* tabbed_pane) { |
106 View* tab0 = new View; | 112 View* tab0 = new View; |
107 tabbed_pane->AddTab(ASCIIToUTF16("tab0"), tab0); | 113 tabbed_pane->AddTab(ASCIIToUTF16("tab0"), tab0); |
108 EXPECT_EQ(tab0, tabbed_pane->GetSelectedTab()); | 114 EXPECT_EQ(tab0, tabbed_pane->GetSelectedTab()); |
109 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); | 115 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
110 | 116 |
111 // Add more 3 tabs. | 117 // Add more 3 tabs. |
112 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), new View); | 118 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), new View); |
(...skipping 22 matching lines...) Expand all Loading... |
135 // The last tab should remains selected, instead of the tab added at index 0. | 141 // The last tab should remains selected, instead of the tab added at index 0. |
136 EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex()); | 142 EXPECT_EQ(3, tabbed_pane->GetSelectedTabIndex()); |
137 | 143 |
138 // Now change the selected tab. | 144 // Now change the selected tab. |
139 tabbed_pane->SelectTabAt(1); | 145 tabbed_pane->SelectTabAt(1); |
140 EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex()); | 146 EXPECT_EQ(1, tabbed_pane->GetSelectedTabIndex()); |
141 | 147 |
142 // Remove the first one. | 148 // Remove the first one. |
143 delete tabbed_pane->RemoveTabAtIndex(0); | 149 delete tabbed_pane->RemoveTabAtIndex(0); |
144 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); | 150 EXPECT_EQ(0, tabbed_pane->GetSelectedTabIndex()); |
| 151 |
| 152 // Clean up the other panes. |
| 153 EXPECT_EQ(3, tabbed_pane->GetTabCount()); |
| 154 delete tabbed_pane->RemoveTabAtIndex(0); |
| 155 delete tabbed_pane->RemoveTabAtIndex(0); |
| 156 delete tabbed_pane->RemoveTabAtIndex(0); |
| 157 EXPECT_EQ(0, tabbed_pane->GetTabCount()); |
145 } | 158 } |
146 | 159 |
147 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). | 160 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
148 TEST_F(TabbedPaneTest, SizeAndLayout) { | 161 TEST_F(TabbedPaneTest, SizeAndLayout) { |
149 TestSizeAndLayout(tabbed_pane_); | 162 TestSizeAndLayout(tabbed_pane_); |
150 // TODO(markusheintz): Once replacing NativeTabbedPaneWin with | 163 // TODO(markusheintz): Once replacing NativeTabbedPaneWin with |
151 // NativeTabbedPaneView is completed (http://crbug.com/138059), then the | 164 // NativeTabbedPaneView is completed (http://crbug.com/138059), then the |
152 // TestSizeAndLayout method should be inlined here again and the "ifdef" part | 165 // TestSizeAndLayout method should be inlined here again and the "ifdef" part |
153 // should be deleted. | 166 // should be deleted. |
154 #if defined(OS_WIN) && !defined(USE_AURA) | 167 #if defined(OS_WIN) && !defined(USE_AURA) |
155 TestSizeAndLayout(tabbed_pane_win_); | 168 TestSizeAndLayout(tabbed_pane_win_); |
156 #endif | 169 #endif |
157 } | 170 } |
158 | 171 |
159 TEST_F(TabbedPaneTest, AddRemove) { | 172 TEST_F(TabbedPaneTest, AddRemove) { |
160 TestAddRemove(tabbed_pane_); | 173 TestAddRemove(tabbed_pane_); |
161 // TODO(markusheintz): Once replacing NativeTabbedPaneWin with | 174 // TODO(markusheintz): Once replacing NativeTabbedPaneWin with |
162 // NativeTabbedPaneView is completed (http://crbug.com/138059), then the | 175 // NativeTabbedPaneView is completed (http://crbug.com/138059), then the |
163 // TestAddRemove method should be inlined here again and the "ifdef" part | 176 // TestAddRemove method should be inlined here again and the "ifdef" part |
164 // should be deleted. | 177 // should be deleted. |
165 #if defined(OS_WIN) && !defined(USE_AURA) | 178 #if defined(OS_WIN) && !defined(USE_AURA) |
166 TestAddRemove(tabbed_pane_win_); | 179 TestAddRemove(tabbed_pane_win_); |
167 #endif | 180 #endif |
168 } | 181 } |
169 | 182 |
170 } // namespace views | 183 } // namespace views |
OLD | NEW |