Chromium Code Reviews| 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/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "grit/ash_resources.h" | 9 #include "grit/ash_resources.h" |
| 10 #include "ui/gfx/geometry/rect.h" | |
| 10 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 11 #include "ui/views/widget/widget_delegate.h" | 12 #include "ui/views/widget/widget_delegate.h" |
| 12 | 13 |
| 13 namespace ash { | 14 namespace ash { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class TestWidgetDelegate : public views::WidgetDelegateView { | 18 class TestWidgetDelegate : public views::WidgetDelegateView { |
| 18 public: | 19 public: |
| 19 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { | 20 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 | 102 |
| 102 // Test how the allowed actions affect which caption buttons are visible. | 103 // Test how the allowed actions affect which caption buttons are visible. |
| 103 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { | 104 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
| 104 // All the buttons should be visible when minimizing and maximizing are | 105 // All the buttons should be visible when minimizing and maximizing are |
| 105 // allowed. | 106 // allowed. |
| 106 scoped_ptr<views::Widget> widget_can_maximize( | 107 scoped_ptr<views::Widget> widget_can_maximize( |
| 107 CreateTestWidget(MAXIMIZE_ALLOWED)); | 108 CreateTestWidget(MAXIMIZE_ALLOWED)); |
| 108 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), | 109 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), |
| 109 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 110 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 110 SetMockImages(&container1); | 111 SetMockImages(&container1); |
| 112 container1.SetBoundsRect(gfx::Rect(container1.GetPreferredSize())); | |
| 111 container1.Layout(); | 113 container1.Layout(); |
| 112 FrameCaptionButtonContainerView::TestApi t1(&container1); | 114 FrameCaptionButtonContainerView::TestApi t1(&container1); |
| 113 EXPECT_TRUE(t1.minimize_button()->visible()); | 115 EXPECT_TRUE(t1.minimize_button()->visible()); |
| 114 EXPECT_TRUE(t1.size_button()->visible()); | 116 EXPECT_TRUE(t1.size_button()->visible()); |
| 115 EXPECT_TRUE(t1.close_button()->visible()); | 117 EXPECT_TRUE(t1.close_button()->visible()); |
| 116 EXPECT_TRUE(CheckButtonsAtEdges( | 118 EXPECT_TRUE(CheckButtonsAtEdges( |
| 117 &container1, *t1.minimize_button(), *t1.close_button())); | 119 &container1, *t1.minimize_button(), *t1.close_button())); |
| 118 | 120 |
| 119 // The minimize button should be visible when minimizing is allowed but | 121 // The minimize button should be visible when minimizing is allowed but |
| 120 // maximizing is disallowed. | 122 // maximizing is disallowed. |
| 121 scoped_ptr<views::Widget> widget_cannot_maximize( | 123 scoped_ptr<views::Widget> widget_cannot_maximize( |
| 122 CreateTestWidget(MAXIMIZE_DISALLOWED)); | 124 CreateTestWidget(MAXIMIZE_DISALLOWED)); |
| 123 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), | 125 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), |
| 124 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 126 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 125 SetMockImages(&container2); | 127 SetMockImages(&container2); |
| 128 container2.SetBoundsRect(gfx::Rect(container2.GetPreferredSize())); | |
| 126 container2.Layout(); | 129 container2.Layout(); |
| 127 FrameCaptionButtonContainerView::TestApi t2(&container2); | 130 FrameCaptionButtonContainerView::TestApi t2(&container2); |
| 128 EXPECT_TRUE(t2.minimize_button()->visible()); | 131 EXPECT_TRUE(t2.minimize_button()->visible()); |
| 129 EXPECT_FALSE(t2.size_button()->visible()); | 132 EXPECT_FALSE(t2.size_button()->visible()); |
| 130 EXPECT_TRUE(t2.close_button()->visible()); | 133 EXPECT_TRUE(t2.close_button()->visible()); |
| 131 EXPECT_TRUE(CheckButtonsAtEdges( | 134 EXPECT_TRUE(CheckButtonsAtEdges( |
| 132 &container2, *t2.minimize_button(), *t2.close_button())); | 135 &container2, *t2.minimize_button(), *t2.close_button())); |
| 133 | 136 |
| 134 // Neither the minimize button nor the size button should be visible when | 137 // Neither the minimize button nor the size button should be visible when |
| 135 // neither minimizing nor maximizing are allowed. | 138 // neither minimizing nor maximizing are allowed. |
| 136 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), | 139 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), |
| 137 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); | 140 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); |
| 138 SetMockImages(&container3); | 141 SetMockImages(&container3); |
| 142 container3.SetBoundsRect(gfx::Rect(container3.GetPreferredSize())); | |
| 139 container3.Layout(); | 143 container3.Layout(); |
| 140 FrameCaptionButtonContainerView::TestApi t3(&container3); | 144 FrameCaptionButtonContainerView::TestApi t3(&container3); |
| 141 EXPECT_FALSE(t3.minimize_button()->visible()); | 145 EXPECT_FALSE(t3.minimize_button()->visible()); |
| 142 EXPECT_FALSE(t3.size_button()->visible()); | 146 EXPECT_FALSE(t3.size_button()->visible()); |
| 143 EXPECT_TRUE(t3.close_button()->visible()); | 147 EXPECT_TRUE(t3.close_button()->visible()); |
| 144 EXPECT_TRUE(CheckButtonsAtEdges( | 148 EXPECT_TRUE(CheckButtonsAtEdges( |
| 145 &container3, *t3.close_button(), *t3.close_button())); | 149 &container3, *t3.close_button(), *t3.close_button())); |
| 146 } | 150 } |
| 147 | 151 |
| 152 // Tests that the layout animations triggered by button visibilty result in the | |
| 153 // correct placement of the buttons. | |
| 154 TEST_F(FrameCaptionButtonContainerViewTest, | |
| 155 TestUpdateSizeButtonVisibilityAnimation) { | |
| 156 scoped_ptr<views::Widget> widget_can_maximize( | |
| 157 CreateTestWidget(MAXIMIZE_ALLOWED)); | |
| 158 FrameCaptionButtonContainerView container(widget_can_maximize.get(), | |
| 159 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | |
| 160 SetMockImages(&container); | |
| 161 container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); | |
| 162 container.Layout(); | |
| 163 | |
| 164 FrameCaptionButtonContainerView::TestApi test(&container); | |
| 165 gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); | |
| 166 gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); | |
| 167 gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); | |
| 168 | |
| 169 // Hidden size button should result in minimize button animating to the | |
| 170 // right. The size button should not be visible, but should not have moved. | |
| 171 container.UpdateSizeButtonVisibility(/*force_hidden*/ true); | |
| 172 container.Layout(); | |
|
flackr
2014/05/21 14:42:21
Does the container size change at some point?
jonross
2014/05/21 22:15:05
Done.
| |
| 173 | |
| 174 EXPECT_TRUE(test.minimize_button()->visible()); | |
| 175 EXPECT_FALSE(test.size_button()->visible()); | |
| 176 EXPECT_TRUE(test.close_button()->visible()); | |
| 177 gfx::Rect minimize_button_bounds = test.minimize_button()->bounds(); | |
| 178 gfx::Rect close_button_bounds = test.close_button()->bounds(); | |
| 179 EXPECT_EQ(close_button_bounds.x() - minimize_button_bounds.width(), | |
|
flackr
2014/05/21 14:42:21
Can this just be EXPECT_EQ(close_button_bounds.x()
jonross
2014/05/21 22:15:05
Done.
| |
| 180 minimize_button_bounds.x()); | |
| 181 EXPECT_GT(minimize_button_bounds.x(), initial_minimize_button_bounds.x()); | |
|
flackr
2014/05/21 14:42:21
This is probably expected given that it's now flus
jonross
2014/05/21 22:15:05
Done.
| |
| 182 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); | |
| 183 EXPECT_EQ(initial_close_button_bounds, close_button_bounds); | |
| 184 | |
| 185 // Revealing the size button should cause the minimze button to return to its | |
| 186 // original position. | |
| 187 container.UpdateSizeButtonVisibility(/*force_hidden*/ false); | |
| 188 container.Layout(); | |
| 189 EXPECT_TRUE(test.minimize_button()->visible()); | |
| 190 EXPECT_TRUE(test.size_button()->visible()); | |
| 191 EXPECT_TRUE(test.close_button()->visible()); | |
| 192 EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); | |
| 193 EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); | |
| 194 EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); | |
| 195 } | |
| 196 | |
| 148 } // namespace ash | 197 } // namespace ash |
| OLD | NEW |