| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 6 | 6 |
| 7 #include "ash/frame/caption_buttons/frame_caption_button.h" | 7 #include "ash/frame/caption_buttons/frame_caption_button.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 11 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 14 #include "ui/views/widget/widget_delegate.h" | 14 #include "ui/views/widget/widget_delegate.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class TestWidgetDelegate : public views::WidgetDelegateView { | 20 class TestWidgetDelegate : public views::WidgetDelegateView { |
| 21 public: | 21 public: |
| 22 explicit TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { | 22 TestWidgetDelegate(bool can_maximize, bool can_minimize) |
| 23 } | 23 : can_maximize_(can_maximize), can_minimize_(can_minimize) {} |
| 24 virtual ~TestWidgetDelegate() { | 24 virtual ~TestWidgetDelegate() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual bool CanMaximize() const OVERRIDE { | 27 virtual bool CanMaximize() const OVERRIDE { |
| 28 return can_maximize_; | 28 return can_maximize_; |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual bool CanMinimize() const OVERRIDE { | 31 virtual bool CanMinimize() const OVERRIDE { |
| 32 return can_maximize_; | 32 return can_minimize_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 bool can_maximize_; | 36 bool can_maximize_; |
| 37 bool can_minimize_; |
| 37 | 38 |
| 38 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); | 39 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 class FrameCaptionButtonContainerViewTest : public ash::test::AshTestBase { | 44 class FrameCaptionButtonContainerViewTest : public ash::test::AshTestBase { |
| 44 public: | 45 public: |
| 45 enum MaximizeAllowed { | 46 enum MaximizeAllowed { |
| 46 MAXIMIZE_ALLOWED, | 47 MAXIMIZE_ALLOWED, |
| 47 MAXIMIZE_DISALLOWED | 48 MAXIMIZE_DISALLOWED |
| 48 }; | 49 }; |
| 49 | 50 |
| 51 enum MinimizeAllowed { |
| 52 MINIMIZE_ALLOWED, |
| 53 MINIMIZE_DISALLOWED |
| 54 }; |
| 55 |
| 50 FrameCaptionButtonContainerViewTest() { | 56 FrameCaptionButtonContainerViewTest() { |
| 51 } | 57 } |
| 52 | 58 |
| 53 virtual ~FrameCaptionButtonContainerViewTest() { | 59 virtual ~FrameCaptionButtonContainerViewTest() { |
| 54 } | 60 } |
| 55 | 61 |
| 56 // Creates a widget which allows maximizing based on |maximize_allowed|. | 62 // Creates a widget which allows maximizing based on |maximize_allowed|. |
| 57 // The caller takes ownership of the returned widget. | 63 // The caller takes ownership of the returned widget. |
| 58 views::Widget* CreateTestWidget( | 64 views::Widget* CreateTestWidget( |
| 59 MaximizeAllowed maximize_allowed) WARN_UNUSED_RESULT { | 65 MaximizeAllowed maximize_allowed, |
| 66 MinimizeAllowed minimize_allowed) WARN_UNUSED_RESULT { |
| 60 views::Widget* widget = new views::Widget; | 67 views::Widget* widget = new views::Widget; |
| 61 views::Widget::InitParams params; | 68 views::Widget::InitParams params; |
| 62 params.delegate = new TestWidgetDelegate( | 69 params.delegate = new TestWidgetDelegate( |
| 63 maximize_allowed == MAXIMIZE_ALLOWED); | 70 maximize_allowed == MAXIMIZE_ALLOWED, |
| 71 minimize_allowed == MINIMIZE_ALLOWED); |
| 64 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 72 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 65 params.context = CurrentContext(); | 73 params.context = CurrentContext(); |
| 66 widget->Init(params); | 74 widget->Init(params); |
| 67 return widget; | 75 return widget; |
| 68 } | 76 } |
| 69 | 77 |
| 70 // Sets |container| to use arbitrary images for the buttons. Setting the | 78 // Sets |container| to use arbitrary images for the buttons. Setting the |
| 71 // images causes the buttons to have non-empty sizes. | 79 // images causes the buttons to have non-empty sizes. |
| 72 void SetMockImages(FrameCaptionButtonContainerView* container) { | 80 void SetMockImages(FrameCaptionButtonContainerView* container) { |
| 73 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { | 81 for (int icon = 0; icon < CAPTION_BUTTON_ICON_COUNT; ++icon) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 103 } | 111 } |
| 104 | 112 |
| 105 private: | 113 private: |
| 106 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); | 114 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); |
| 107 }; | 115 }; |
| 108 | 116 |
| 109 // Test how the allowed actions affect which caption buttons are visible. | 117 // Test how the allowed actions affect which caption buttons are visible. |
| 110 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { | 118 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
| 111 // All the buttons should be visible when minimizing and maximizing are | 119 // All the buttons should be visible when minimizing and maximizing are |
| 112 // allowed. | 120 // allowed. |
| 113 scoped_ptr<views::Widget> widget_can_maximize( | 121 FrameCaptionButtonContainerView container1( |
| 114 CreateTestWidget(MAXIMIZE_ALLOWED)); | 122 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); |
| 115 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), | |
| 116 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | |
| 117 SetMockImages(&container1); | 123 SetMockImages(&container1); |
| 118 container1.Layout(); | 124 container1.Layout(); |
| 119 FrameCaptionButtonContainerView::TestApi t1(&container1); | 125 FrameCaptionButtonContainerView::TestApi t1(&container1); |
| 120 EXPECT_TRUE(t1.minimize_button()->visible()); | 126 EXPECT_TRUE(t1.minimize_button()->visible()); |
| 121 EXPECT_TRUE(t1.size_button()->visible()); | 127 EXPECT_TRUE(t1.size_button()->visible()); |
| 122 EXPECT_TRUE(t1.close_button()->visible()); | 128 EXPECT_TRUE(t1.close_button()->visible()); |
| 123 EXPECT_TRUE(CheckButtonsAtEdges( | 129 EXPECT_TRUE(CheckButtonsAtEdges( |
| 124 &container1, *t1.minimize_button(), *t1.close_button())); | 130 &container1, *t1.minimize_button(), *t1.close_button())); |
| 125 | 131 |
| 126 // The minimize button should be visible when minimizing is allowed but | 132 // The minimize button should be visible when minimizing is allowed but |
| 127 // maximizing is disallowed. | 133 // maximizing is disallowed. |
| 128 scoped_ptr<views::Widget> widget_cannot_maximize( | 134 FrameCaptionButtonContainerView container2( |
| 129 CreateTestWidget(MAXIMIZE_DISALLOWED)); | 135 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_ALLOWED)); |
| 130 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), | |
| 131 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | |
| 132 SetMockImages(&container2); | 136 SetMockImages(&container2); |
| 133 container2.Layout(); | 137 container2.Layout(); |
| 134 FrameCaptionButtonContainerView::TestApi t2(&container2); | 138 FrameCaptionButtonContainerView::TestApi t2(&container2); |
| 135 EXPECT_TRUE(t2.minimize_button()->visible()); | 139 EXPECT_TRUE(t2.minimize_button()->visible()); |
| 136 EXPECT_FALSE(t2.size_button()->visible()); | 140 EXPECT_FALSE(t2.size_button()->visible()); |
| 137 EXPECT_TRUE(t2.close_button()->visible()); | 141 EXPECT_TRUE(t2.close_button()->visible()); |
| 138 EXPECT_TRUE(CheckButtonsAtEdges( | 142 EXPECT_TRUE(CheckButtonsAtEdges( |
| 139 &container2, *t2.minimize_button(), *t2.close_button())); | 143 &container2, *t2.minimize_button(), *t2.close_button())); |
| 140 | 144 |
| 141 // Neither the minimize button nor the size button should be visible when | 145 // Neither the minimize button nor the size button should be visible when |
| 142 // neither minimizing nor maximizing are allowed. | 146 // neither minimizing nor maximizing are allowed. |
| 143 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), | 147 FrameCaptionButtonContainerView container3( |
| 144 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); | 148 CreateTestWidget(MAXIMIZE_DISALLOWED, MINIMIZE_DISALLOWED)); |
| 145 SetMockImages(&container3); | 149 SetMockImages(&container3); |
| 146 container3.Layout(); | 150 container3.Layout(); |
| 147 FrameCaptionButtonContainerView::TestApi t3(&container3); | 151 FrameCaptionButtonContainerView::TestApi t3(&container3); |
| 148 EXPECT_FALSE(t3.minimize_button()->visible()); | 152 EXPECT_FALSE(t3.minimize_button()->visible()); |
| 149 EXPECT_FALSE(t3.size_button()->visible()); | 153 EXPECT_FALSE(t3.size_button()->visible()); |
| 150 EXPECT_TRUE(t3.close_button()->visible()); | 154 EXPECT_TRUE(t3.close_button()->visible()); |
| 151 EXPECT_TRUE(CheckButtonsAtEdges( | 155 EXPECT_TRUE(CheckButtonsAtEdges( |
| 152 &container3, *t3.close_button(), *t3.close_button())); | 156 &container3, *t3.close_button(), *t3.close_button())); |
| 153 } | 157 } |
| 154 | 158 |
| 155 // Tests that the layout animations trigered by button visibility result in the | 159 // Tests that the layout animations trigered by button visibility result in the |
| 156 // correct placement of the buttons. | 160 // correct placement of the buttons. |
| 157 TEST_F(FrameCaptionButtonContainerViewTest, | 161 TEST_F(FrameCaptionButtonContainerViewTest, |
| 158 TestUpdateSizeButtonVisibilityAnimation) { | 162 TestUpdateSizeButtonVisibilityAnimation) { |
| 159 scoped_ptr<views::Widget> widget_can_maximize( | 163 FrameCaptionButtonContainerView container( |
| 160 CreateTestWidget(MAXIMIZE_ALLOWED)); | 164 CreateTestWidget(MAXIMIZE_ALLOWED, MINIMIZE_ALLOWED)); |
| 161 FrameCaptionButtonContainerView container(widget_can_maximize.get(), | |
| 162 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | |
| 163 SetMockImages(&container); | 165 SetMockImages(&container); |
| 164 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); | 166 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); |
| 165 container.Layout(); | 167 container.Layout(); |
| 166 | 168 |
| 167 FrameCaptionButtonContainerView::TestApi test(&container); | 169 FrameCaptionButtonContainerView::TestApi test(&container); |
| 168 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); | 170 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); |
| 169 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); | 171 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); |
| 170 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); | 172 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); |
| 171 gfx::Rect initial_container_bounds = container.bounds(); | 173 gfx::Rect initial_container_bounds = container.bounds(); |
| 172 | 174 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 EXPECT_TRUE(test.size_button()->visible()); | 209 EXPECT_TRUE(test.size_button()->visible()); |
| 208 EXPECT_TRUE(test.close_button()->visible()); | 210 EXPECT_TRUE(test.close_button()->visible()); |
| 209 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); | 211 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); |
| 210 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); | 212 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); |
| 211 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); | 213 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); |
| 212 EXPECT_EQ(container.GetPreferredSize().width(), | 214 EXPECT_EQ(container.GetPreferredSize().width(), |
| 213 initial_container_bounds.width()); | 215 initial_container_bounds.width()); |
| 214 } | 216 } |
| 215 | 217 |
| 216 } // namespace ash | 218 } // namespace ash |
| OLD | NEW |