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 22 matching lines...) Expand all Loading... | |
33 public WidgetDelegate { | 33 public WidgetDelegate { |
34 public: | 34 public: |
35 TabbedPaneTest() {} | 35 TabbedPaneTest() {} |
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); | |
44 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); | 43 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); |
45 window_->Show(); | 44 window_->Show(); |
46 } | 45 } |
47 | 46 |
48 virtual void TearDown() OVERRIDE { | 47 virtual void TearDown() OVERRIDE { |
49 window_->Close(); | 48 window_->Close(); |
50 ViewsTestBase::TearDown(); | 49 ViewsTestBase::TearDown(); |
51 } | 50 } |
52 | 51 |
53 virtual views::View* GetContentsView() OVERRIDE { | 52 virtual views::View* GetContentsView() OVERRIDE { |
(...skipping 14 matching lines...) Expand all Loading... | |
68 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). | 67 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
69 TEST_F(TabbedPaneTest, SizeAndLayout) { | 68 TEST_F(TabbedPaneTest, SizeAndLayout) { |
70 View* child1 = new FixedSizeView(gfx::Size(20, 10)); | 69 View* child1 = new FixedSizeView(gfx::Size(20, 10)); |
71 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); | 70 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); |
72 View* child2 = new FixedSizeView(gfx::Size(5, 5)); | 71 View* child2 = new FixedSizeView(gfx::Size(5, 5)); |
73 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); | 72 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); |
74 tabbed_pane_->SelectTabAt(0); | 73 tabbed_pane_->SelectTabAt(0); |
75 | 74 |
76 // Check that the preferred size is larger than the largest child. | 75 // Check that the preferred size is larger than the largest child. |
77 gfx::Size pref(tabbed_pane_->GetPreferredSize()); | 76 gfx::Size pref(tabbed_pane_->GetPreferredSize()); |
78 EXPECT_GT(pref.width(), 20); | 77 // The |tabbed_pane_| has no border. Therefor it should be as wide as the |
msw
2012/07/25 20:19:27
nit: "therefore" here and at 87
markusheintz_
2012/07/26 18:21:35
Done.
| |
78 // widest tab. | |
79 EXPECT_EQ(pref.width(), 20); | |
msw
2012/07/25 20:19:27
EXPECT_GE would cover both impls then, right?
markusheintz_
2012/07/26 18:21:35
Correct. Done.
| |
79 EXPECT_GT(pref.height(), 10); | 80 EXPECT_GT(pref.height(), 10); |
80 | 81 |
81 // The bounds of our children should be smaller than the tabbed pane's bounds. | 82 // The bounds of our children should be smaller than the tabbed pane's bounds. |
82 tabbed_pane_->SetBounds(0, 0, 100, 200); | 83 tabbed_pane_->SetBounds(0, 0, 100, 200); |
83 RunPendingMessages(); | 84 RunPendingMessages(); |
84 gfx::Rect bounds(child1->bounds()); | 85 gfx::Rect bounds(child1->bounds()); |
85 EXPECT_GT(bounds.width(), 0); | 86 EXPECT_GT(bounds.width(), 0); |
86 EXPECT_LT(bounds.width(), 100); | 87 // The |tabbed_pane_| has no border. Therefor the children should be as wide |
88 // as the |tabbed_pane_|. | |
89 EXPECT_EQ(bounds.width(), 100); | |
msw
2012/07/25 20:19:27
EXPECT_LE would cover both impls then, right?
markusheintz_
2012/07/26 18:21:35
Correct. Done.
| |
87 EXPECT_GT(bounds.height(), 0); | 90 EXPECT_GT(bounds.height(), 0); |
88 EXPECT_LT(bounds.height(), 200); | 91 EXPECT_LT(bounds.height(), 200); |
89 | 92 |
90 // If we switch to the other tab, it should get assigned the same bounds. | 93 // If we switch to the other tab, it should get assigned the same bounds. |
91 tabbed_pane_->SelectTabAt(1); | 94 tabbed_pane_->SelectTabAt(1); |
92 EXPECT_EQ(bounds, child2->bounds()); | 95 EXPECT_EQ(bounds, child2->bounds()); |
93 } | 96 } |
94 | 97 |
95 TEST_F(TabbedPaneTest, AddRemove) { | 98 TEST_F(TabbedPaneTest, AddRemove) { |
96 View* tab0 = new View; | 99 View* tab0 = new View; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Now change the selected tab. | 131 // Now change the selected tab. |
129 tabbed_pane_->SelectTabAt(1); | 132 tabbed_pane_->SelectTabAt(1); |
130 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 133 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
131 | 134 |
132 // Remove the first one. | 135 // Remove the first one. |
133 delete tabbed_pane_->RemoveTabAtIndex(0); | 136 delete tabbed_pane_->RemoveTabAtIndex(0); |
134 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 137 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
135 } | 138 } |
136 | 139 |
137 } // namespace views | 140 } // namespace views |
OLD | NEW |