| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "views/controls/tabbed_pane/tabbed_pane.h" | 8 #include "views/controls/tabbed_pane/tabbed_pane.h" |
| 9 #include "views/test/views_test_base.h" |
| 9 #include "views/widget/widget.h" | 10 #include "views/widget/widget.h" |
| 10 #include "views/widget/widget_delegate.h" | 11 #include "views/widget/widget_delegate.h" |
| 11 | 12 |
| 12 namespace views { | 13 namespace views { |
| 13 | 14 |
| 14 // A view for testing that takes a fixed preferred size upon construction. | 15 // A view for testing that takes a fixed preferred size upon construction. |
| 15 class FixedSizeView : public View { | 16 class FixedSizeView : public View { |
| 16 public: | 17 public: |
| 17 FixedSizeView(const gfx::Size& size) | 18 FixedSizeView(const gfx::Size& size) |
| 18 : size_(size) {} | 19 : size_(size) {} |
| 19 | 20 |
| 20 virtual gfx::Size GetPreferredSize() { | 21 virtual gfx::Size GetPreferredSize() { |
| 21 return size_; | 22 return size_; |
| 22 } | 23 } |
| 23 | 24 |
| 24 private: | 25 private: |
| 25 const gfx::Size size_; | 26 const gfx::Size size_; |
| 26 | 27 |
| 27 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); | 28 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); |
| 28 }; | 29 }; |
| 29 | 30 |
| 30 class TabbedPaneTest : public testing::Test, | 31 class TabbedPaneTest : public ViewsTestBase, |
| 31 public WidgetDelegate { | 32 public WidgetDelegate { |
| 32 public: | 33 public: |
| 33 TabbedPaneTest() {} | 34 TabbedPaneTest() {} |
| 34 | 35 |
| 35 TabbedPane* tabbed_pane_; | 36 TabbedPane* tabbed_pane_; |
| 36 | 37 |
| 37 void RunAllPending() { | |
| 38 message_loop_.RunAllPending(); | |
| 39 } | |
| 40 | |
| 41 private: | 38 private: |
| 42 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
| 40 ViewsTestBase::SetUp(); |
| 43 tabbed_pane_ = new TabbedPane(); | 41 tabbed_pane_ = new TabbedPane(); |
| 44 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); | 42 window_ = Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 100, 100)); |
| 45 window_->Show(); | 43 window_->Show(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 virtual void TearDown() OVERRIDE { | 46 virtual void TearDown() OVERRIDE { |
| 49 window_->Close(); | 47 window_->Close(); |
| 50 message_loop_.RunAllPending(); | 48 ViewsTestBase::TearDown(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 virtual views::View* GetContentsView() OVERRIDE { | 51 virtual views::View* GetContentsView() OVERRIDE { |
| 54 return tabbed_pane_; | 52 return tabbed_pane_; |
| 55 } | 53 } |
| 56 virtual views::Widget* GetWidget() OVERRIDE { | 54 virtual views::Widget* GetWidget() OVERRIDE { |
| 57 return tabbed_pane_->GetWidget(); | 55 return tabbed_pane_->GetWidget(); |
| 58 } | 56 } |
| 59 virtual const views::Widget* GetWidget() const OVERRIDE { | 57 virtual const views::Widget* GetWidget() const OVERRIDE { |
| 60 return tabbed_pane_->GetWidget(); | 58 return tabbed_pane_->GetWidget(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 MessageLoopForUI message_loop_; | |
| 64 Widget* window_; | 61 Widget* window_; |
| 65 | 62 |
| 66 DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest); | 63 DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest); |
| 67 }; | 64 }; |
| 68 | 65 |
| 69 #if defined(OS_WIN) | |
| 70 // These test are failing and crash on Win7. See http://crbug.com/104067 | |
| 71 #define MAYBE_SizeAndLayout DISABLED_SizeAndLayout | |
| 72 #define MAYBE_AddRemove DISABLED_AddRemove | |
| 73 #else | |
| 74 #define MAYBE_SizeAndLayout SizeAndLayout | |
| 75 #define MAYBE_AddRemove AddRemove | |
| 76 #endif | |
| 77 | |
| 78 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). | 66 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
| 79 TEST_F(TabbedPaneTest, MAYBE_SizeAndLayout) { | 67 TEST_F(TabbedPaneTest, SizeAndLayout) { |
| 80 View* child1 = new FixedSizeView(gfx::Size(20, 10)); | 68 View* child1 = new FixedSizeView(gfx::Size(20, 10)); |
| 81 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); | 69 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), child1); |
| 82 View* child2 = new FixedSizeView(gfx::Size(5, 5)); | 70 View* child2 = new FixedSizeView(gfx::Size(5, 5)); |
| 83 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); | 71 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), child2); |
| 84 tabbed_pane_->SelectTabAt(0); | 72 tabbed_pane_->SelectTabAt(0); |
| 85 | 73 |
| 86 // Check that the preferred size is larger than the largest child. | 74 // Check that the preferred size is larger than the largest child. |
| 87 gfx::Size pref(tabbed_pane_->GetPreferredSize()); | 75 gfx::Size pref(tabbed_pane_->GetPreferredSize()); |
| 88 EXPECT_GT(pref.width(), 20); | 76 EXPECT_GT(pref.width(), 20); |
| 89 EXPECT_GT(pref.height(), 10); | 77 EXPECT_GT(pref.height(), 10); |
| 90 | 78 |
| 91 // The bounds of our children should be smaller than the tabbed pane's bounds. | 79 // The bounds of our children should be smaller than the tabbed pane's bounds. |
| 92 tabbed_pane_->SetBounds(0, 0, 100, 200); | 80 tabbed_pane_->SetBounds(0, 0, 100, 200); |
| 93 RunAllPending(); | 81 RunPendingMessages(); |
| 94 gfx::Rect bounds(child1->bounds()); | 82 gfx::Rect bounds(child1->bounds()); |
| 95 EXPECT_GT(bounds.width(), 0); | 83 EXPECT_GT(bounds.width(), 0); |
| 96 EXPECT_LT(bounds.width(), 100); | 84 EXPECT_LT(bounds.width(), 100); |
| 97 EXPECT_GT(bounds.height(), 0); | 85 EXPECT_GT(bounds.height(), 0); |
| 98 EXPECT_LT(bounds.height(), 200); | 86 EXPECT_LT(bounds.height(), 200); |
| 99 | 87 |
| 100 // If we switch to the other tab, it should get assigned the same bounds. | 88 // If we switch to the other tab, it should get assigned the same bounds. |
| 101 tabbed_pane_->SelectTabAt(1); | 89 tabbed_pane_->SelectTabAt(1); |
| 102 EXPECT_EQ(bounds, child2->bounds()); | 90 EXPECT_EQ(bounds, child2->bounds()); |
| 103 } | 91 } |
| 104 | 92 |
| 105 TEST_F(TabbedPaneTest, MAYBE_AddRemove) { | 93 TEST_F(TabbedPaneTest, AddRemove) { |
| 106 View* tab0 = new View; | 94 View* tab0 = new View; |
| 107 tabbed_pane_->AddTab(ASCIIToUTF16("tab0"), tab0); | 95 tabbed_pane_->AddTab(ASCIIToUTF16("tab0"), tab0); |
| 108 EXPECT_EQ(tab0, tabbed_pane_->GetSelectedTab()); | 96 EXPECT_EQ(tab0, tabbed_pane_->GetSelectedTab()); |
| 109 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 97 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 110 | 98 |
| 111 // Add more 3 tabs. | 99 // Add more 3 tabs. |
| 112 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), new View); | 100 tabbed_pane_->AddTab(ASCIIToUTF16("tab1"), new View); |
| 113 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), new View); | 101 tabbed_pane_->AddTab(ASCIIToUTF16("tab2"), new View); |
| 114 tabbed_pane_->AddTab(ASCIIToUTF16("tab3"), new View); | 102 tabbed_pane_->AddTab(ASCIIToUTF16("tab3"), new View); |
| 115 EXPECT_EQ(4, tabbed_pane_->GetTabCount()); | 103 EXPECT_EQ(4, tabbed_pane_->GetTabCount()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 // Now change the selected tab. | 126 // Now change the selected tab. |
| 139 tabbed_pane_->SelectTabAt(1); | 127 tabbed_pane_->SelectTabAt(1); |
| 140 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); | 128 EXPECT_EQ(1, tabbed_pane_->GetSelectedTabIndex()); |
| 141 | 129 |
| 142 // Remove the first one. | 130 // Remove the first one. |
| 143 delete tabbed_pane_->RemoveTabAtIndex(0); | 131 delete tabbed_pane_->RemoveTabAtIndex(0); |
| 144 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); | 132 EXPECT_EQ(0, tabbed_pane_->GetSelectedTabIndex()); |
| 145 } | 133 } |
| 146 | 134 |
| 147 } // namespace views | 135 } // namespace views |
| OLD | NEW |