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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/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 16 matching lines...) Expand all Loading... |
27 private: | 27 private: |
28 const gfx::Size size_; | 28 const gfx::Size size_; |
29 | 29 |
30 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); | 30 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); |
31 }; | 31 }; |
32 | 32 |
33 typedef ViewsTestBase TabbedPaneTest; | 33 typedef ViewsTestBase TabbedPaneTest; |
34 | 34 |
35 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). | 35 // Tests TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
36 TEST_F(TabbedPaneTest, SizeAndLayout) { | 36 TEST_F(TabbedPaneTest, SizeAndLayout) { |
37 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane(false)); | 37 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
38 View* child1 = new FixedSizeView(gfx::Size(20, 10)); | 38 View* child1 = new FixedSizeView(gfx::Size(20, 10)); |
39 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1); | 39 tabbed_pane->AddTab(ASCIIToUTF16("tab1"), child1); |
40 View* child2 = new FixedSizeView(gfx::Size(5, 5)); | 40 View* child2 = new FixedSizeView(gfx::Size(5, 5)); |
41 tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2); | 41 tabbed_pane->AddTab(ASCIIToUTF16("tab2"), child2); |
42 tabbed_pane->SelectTabAt(0); | 42 tabbed_pane->SelectTabAt(0); |
43 | 43 |
44 // The |tabbed_pane| implementation of Views has no border by default. | 44 // The |tabbed_pane| implementation of Views has no border by default. |
45 // Therefore it should be as wide as the widest tab. The native Windows | 45 // Therefore it should be as wide as the widest tab. The native Windows |
46 // tabbed pane has a border that used up extra space. Therefore the preferred | 46 // tabbed pane has a border that used up extra space. Therefore the preferred |
47 // width is larger than the largest child. | 47 // width is larger than the largest child. |
(...skipping 11 matching lines...) Expand all Loading... |
59 EXPECT_LE(bounds.width(), 100); | 59 EXPECT_LE(bounds.width(), 100); |
60 EXPECT_GT(bounds.height(), 0); | 60 EXPECT_GT(bounds.height(), 0); |
61 EXPECT_LT(bounds.height(), 200); | 61 EXPECT_LT(bounds.height(), 200); |
62 | 62 |
63 // If we switch to the other tab, it should get assigned the same bounds. | 63 // If we switch to the other tab, it should get assigned the same bounds. |
64 tabbed_pane->SelectTabAt(1); | 64 tabbed_pane->SelectTabAt(1); |
65 EXPECT_EQ(bounds, child2->bounds()); | 65 EXPECT_EQ(bounds, child2->bounds()); |
66 } | 66 } |
67 | 67 |
68 TEST_F(TabbedPaneTest, AddAndSelect) { | 68 TEST_F(TabbedPaneTest, AddAndSelect) { |
69 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane(false)); | 69 scoped_ptr<TabbedPane> tabbed_pane(new TabbedPane()); |
70 // Add several tabs; only the first should be a selected automatically. | 70 // Add several tabs; only the first should be a selected automatically. |
71 for (int i = 0; i < 3; ++i) { | 71 for (int i = 0; i < 3; ++i) { |
72 View* tab = new View(); | 72 View* tab = new View(); |
73 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); | 73 tabbed_pane->AddTab(ASCIIToUTF16("tab"), tab); |
74 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); | 74 EXPECT_EQ(i + 1, tabbed_pane->GetTabCount()); |
75 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); | 75 EXPECT_EQ(0, tabbed_pane->selected_tab_index()); |
76 } | 76 } |
77 | 77 |
78 // Select each tab. | 78 // Select each tab. |
79 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { | 79 for (int i = 0; i < tabbed_pane->GetTabCount(); ++i) { |
80 tabbed_pane->SelectTabAt(i); | 80 tabbed_pane->SelectTabAt(i); |
81 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); | 81 EXPECT_EQ(i, tabbed_pane->selected_tab_index()); |
82 } | 82 } |
83 | 83 |
84 // Add a tab at index 0, it should not be selected automatically. | 84 // Add a tab at index 0, it should not be selected automatically. |
85 View* tab0 = new View(); | 85 View* tab0 = new View(); |
86 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); | 86 tabbed_pane->AddTabAtIndex(0, ASCIIToUTF16("tab0"), tab0); |
87 EXPECT_NE(tab0, tabbed_pane->GetSelectedTab()); | 87 EXPECT_NE(tab0, tabbed_pane->GetSelectedTab()); |
88 EXPECT_NE(0, tabbed_pane->selected_tab_index()); | 88 EXPECT_NE(0, tabbed_pane->selected_tab_index()); |
89 } | 89 } |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 } // namespace views | 93 } // namespace views |
OLD | NEW |