OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/message_loop.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "views/controls/tabbed_pane/tabbed_pane.h" |
| 8 #include "views/window/window.h" |
| 9 #include "views/window/window_delegate.h" |
| 10 |
| 11 namespace views { |
| 12 |
| 13 // A view for testing that takes a fixed preferred size upon construction. |
| 14 class FixedSizeView : public View { |
| 15 public: |
| 16 FixedSizeView(const gfx::Size& size) |
| 17 : size_(size) {} |
| 18 |
| 19 virtual gfx::Size GetPreferredSize() { |
| 20 return size_; |
| 21 } |
| 22 |
| 23 private: |
| 24 const gfx::Size size_; |
| 25 |
| 26 DISALLOW_COPY_AND_ASSIGN(FixedSizeView); |
| 27 }; |
| 28 |
| 29 class TabbedPaneTest : public testing::Test, WindowDelegate { |
| 30 public: |
| 31 TabbedPaneTest() {} |
| 32 |
| 33 TabbedPane* tabbed_pane_; |
| 34 |
| 35 private: |
| 36 virtual void SetUp() { |
| 37 tabbed_pane_ = new TabbedPane(); |
| 38 window_ = Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), this); |
| 39 window_->Show(); |
| 40 } |
| 41 |
| 42 virtual void TearDown() { |
| 43 window_->Close(); |
| 44 } |
| 45 |
| 46 virtual views::View* GetContentsView() { |
| 47 return tabbed_pane_; |
| 48 } |
| 49 |
| 50 MessageLoopForUI message_loop_; |
| 51 Window* window_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(TabbedPaneTest); |
| 54 }; |
| 55 |
| 56 // Tests that TabbedPane::GetPreferredSize() and TabbedPane::Layout(). |
| 57 TEST_F(TabbedPaneTest, SizeAndLayout) { |
| 58 View* child1 = new FixedSizeView(gfx::Size(20, 10)); |
| 59 tabbed_pane_->AddTab(L"tab1", child1); |
| 60 View* child2 = new FixedSizeView(gfx::Size(5, 5)); |
| 61 tabbed_pane_->AddTab(L"tab2", child2); |
| 62 tabbed_pane_->SelectTabAt(0); |
| 63 |
| 64 // Check that the preferred size is larger than the largest child. |
| 65 gfx::Size pref(tabbed_pane_->GetPreferredSize()); |
| 66 EXPECT_GT(pref.width(), 20); |
| 67 EXPECT_GT(pref.height(), 10); |
| 68 |
| 69 // The bounds of our children should be smaller than the tabbed pane's bounds. |
| 70 tabbed_pane_->SetBounds(0, 0, 100, 200); |
| 71 gfx::Rect bounds(child1->bounds()); |
| 72 EXPECT_GT(bounds.width(), 0); |
| 73 EXPECT_LT(bounds.width(), 100); |
| 74 EXPECT_GT(bounds.height(), 0); |
| 75 EXPECT_LT(bounds.height(), 200); |
| 76 |
| 77 // If we switch to the other tab, it should get assigned the same bounds. |
| 78 tabbed_pane_->SelectTabAt(1); |
| 79 EXPECT_EQ(bounds, child2->bounds()); |
| 80 } |
| 81 |
| 82 } // namespace views |
OLD | NEW |