| 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/wm/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 private: | 131 private: |
| 132 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTestOldStyle); | 132 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTestOldStyle); |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 // Test how the allowed actions affect which caption buttons are visible. | 135 // Test how the allowed actions affect which caption buttons are visible. |
| 136 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, ButtonVisibility) { | 136 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, ButtonVisibility) { |
| 137 // The minimize button should be hidden when both minimizing and maximizing | 137 // The minimize button should be hidden when both minimizing and maximizing |
| 138 // are allowed because the size button can do both. | 138 // are allowed because the size button can do both. |
| 139 scoped_ptr<views::Widget> widget_can_maximize( | 139 scoped_ptr<views::Widget> widget_can_maximize( |
| 140 CreateTestWidget(MAXIMIZE_ALLOWED)); | 140 CreateTestWidget(MAXIMIZE_ALLOWED)); |
| 141 FrameCaptionButtonContainerView container1(NULL, widget_can_maximize.get(), | 141 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), |
| 142 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 142 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 143 container1.Layout(); | 143 container1.Layout(); |
| 144 FrameCaptionButtonContainerView::TestApi t1(&container1); | 144 FrameCaptionButtonContainerView::TestApi t1(&container1); |
| 145 EXPECT_FALSE(t1.minimize_button()->visible()); | 145 EXPECT_FALSE(t1.minimize_button()->visible()); |
| 146 EXPECT_TRUE(t1.size_button()->visible()); | 146 EXPECT_TRUE(t1.size_button()->visible()); |
| 147 EXPECT_TRUE(t1.close_button()->visible()); | 147 EXPECT_TRUE(t1.close_button()->visible()); |
| 148 EXPECT_TRUE(CheckButtonsAtEdges( | 148 EXPECT_TRUE(CheckButtonsAtEdges( |
| 149 &container1, *t1.size_button(), *t1.close_button())); | 149 &container1, *t1.size_button(), *t1.close_button())); |
| 150 | 150 |
| 151 // The minimize button should be visible when minimizing is allowed but | 151 // The minimize button should be visible when minimizing is allowed but |
| 152 // maximizing is disallowed. | 152 // maximizing is disallowed. |
| 153 scoped_ptr<views::Widget> widget_cannot_maximize( | 153 scoped_ptr<views::Widget> widget_cannot_maximize( |
| 154 CreateTestWidget(MAXIMIZE_DISALLOWED)); | 154 CreateTestWidget(MAXIMIZE_DISALLOWED)); |
| 155 FrameCaptionButtonContainerView container2(NULL, widget_cannot_maximize.get(), | 155 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), |
| 156 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 156 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 157 container2.Layout(); | 157 container2.Layout(); |
| 158 FrameCaptionButtonContainerView::TestApi t2(&container2); | 158 FrameCaptionButtonContainerView::TestApi t2(&container2); |
| 159 EXPECT_TRUE(t2.minimize_button()->visible()); | 159 EXPECT_TRUE(t2.minimize_button()->visible()); |
| 160 EXPECT_FALSE(t2.size_button()->visible()); | 160 EXPECT_FALSE(t2.size_button()->visible()); |
| 161 EXPECT_TRUE(t2.close_button()->visible()); | 161 EXPECT_TRUE(t2.close_button()->visible()); |
| 162 EXPECT_TRUE(CheckButtonsAtEdges( | 162 EXPECT_TRUE(CheckButtonsAtEdges( |
| 163 &container2, *t2.minimize_button(), *t2.close_button())); | 163 &container2, *t2.minimize_button(), *t2.close_button())); |
| 164 | 164 |
| 165 // Neither the minimize button nor the size button should be visible when | 165 // Neither the minimize button nor the size button should be visible when |
| 166 // neither minimizing nor maximizing are allowed. | 166 // neither minimizing nor maximizing are allowed. |
| 167 FrameCaptionButtonContainerView container3(NULL, widget_cannot_maximize.get(), | 167 FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), |
| 168 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); | 168 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); |
| 169 container3.Layout(); | 169 container3.Layout(); |
| 170 FrameCaptionButtonContainerView::TestApi t3(&container3); | 170 FrameCaptionButtonContainerView::TestApi t3(&container3); |
| 171 EXPECT_FALSE(t3.minimize_button()->visible()); | 171 EXPECT_FALSE(t3.minimize_button()->visible()); |
| 172 EXPECT_FALSE(t3.size_button()->visible()); | 172 EXPECT_FALSE(t3.size_button()->visible()); |
| 173 EXPECT_TRUE(t3.close_button()->visible()); | 173 EXPECT_TRUE(t3.close_button()->visible()); |
| 174 EXPECT_TRUE(CheckButtonsAtEdges( | 174 EXPECT_TRUE(CheckButtonsAtEdges( |
| 175 &container3, *t3.close_button(), *t3.close_button())); | 175 &container3, *t3.close_button(), *t3.close_button())); |
| 176 | 176 |
| 177 // Neither the minimize button nor the size button should be visible when the | 177 // Neither the minimize button nor the size button should be visible when the |
| 178 // "force-maximize-mode" experiment is turned on. | 178 // "force-maximize-mode" experiment is turned on. |
| 179 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kForcedMaximizeMode); | 179 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kForcedMaximizeMode); |
| 180 FrameCaptionButtonContainerView container4(NULL, widget_can_maximize.get(), | 180 FrameCaptionButtonContainerView container4(widget_can_maximize.get(), |
| 181 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 181 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 182 container4.Layout(); | 182 container4.Layout(); |
| 183 FrameCaptionButtonContainerView::TestApi t4(&container4); | 183 FrameCaptionButtonContainerView::TestApi t4(&container4); |
| 184 EXPECT_FALSE(t4.minimize_button()->visible()); | 184 EXPECT_FALSE(t4.minimize_button()->visible()); |
| 185 EXPECT_FALSE(t4.size_button()->visible()); | 185 EXPECT_FALSE(t4.size_button()->visible()); |
| 186 EXPECT_TRUE(t4.close_button()->visible()); | 186 EXPECT_TRUE(t4.close_button()->visible()); |
| 187 EXPECT_TRUE(CheckButtonsAtEdges( | 187 EXPECT_TRUE(CheckButtonsAtEdges( |
| 188 &container4, *t4.close_button(), *t4.close_button())); | 188 &container4, *t4.close_button(), *t4.close_button())); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Test the layout when a border is set on the container. | 191 // Test the layout when a border is set on the container. |
| 192 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, LayoutBorder) { | 192 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, LayoutBorder) { |
| 193 const int kTopInset = 1; | 193 const int kTopInset = 1; |
| 194 const int kLeftInset = 2; | 194 const int kLeftInset = 2; |
| 195 const int kBottomInset = 3; | 195 const int kBottomInset = 3; |
| 196 const int kRightInset = 4; | 196 const int kRightInset = 4; |
| 197 | 197 |
| 198 scoped_ptr<views::Widget> widget(CreateTestWidget(MAXIMIZE_ALLOWED)); | 198 scoped_ptr<views::Widget> widget(CreateTestWidget(MAXIMIZE_ALLOWED)); |
| 199 FrameCaptionButtonContainerView container(NULL, widget.get(), | 199 FrameCaptionButtonContainerView container(widget.get(), |
| 200 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 200 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 201 container.set_border(views::Border::CreateEmptyBorder( | 201 container.set_border(views::Border::CreateEmptyBorder( |
| 202 kTopInset, kLeftInset, kBottomInset, kRightInset)); | 202 kTopInset, kLeftInset, kBottomInset, kRightInset)); |
| 203 container.Layout(); | 203 container.Layout(); |
| 204 FrameCaptionButtonContainerView::TestApi t(&container); | 204 FrameCaptionButtonContainerView::TestApi t(&container); |
| 205 | 205 |
| 206 EXPECT_EQ(kLeftInset, t.size_button()->x()); | 206 EXPECT_EQ(kLeftInset, t.size_button()->x()); |
| 207 EXPECT_EQ(kTopInset, t.close_button()->y()); | 207 EXPECT_EQ(kTopInset, t.close_button()->y()); |
| 208 EXPECT_EQ(container.GetPreferredSize().height(), | 208 EXPECT_EQ(container.GetPreferredSize().height(), |
| 209 t.close_button()->bounds().bottom() + kBottomInset); | 209 t.close_button()->bounds().bottom() + kBottomInset); |
| 210 EXPECT_EQ(container.GetPreferredSize().width(), | 210 EXPECT_EQ(container.GetPreferredSize().width(), |
| 211 t.close_button()->bounds().right() + kRightInset); | 211 t.close_button()->bounds().right() + kRightInset); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // Test how the header style affects which images are used for the buttons. | 214 // Test how the header style affects which images are used for the buttons. |
| 215 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, HeaderStyle) { | 215 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, HeaderStyle) { |
| 216 scoped_ptr<views::Widget> widget(CreateTestWidget(MAXIMIZE_ALLOWED)); | 216 scoped_ptr<views::Widget> widget(CreateTestWidget(MAXIMIZE_ALLOWED)); |
| 217 FrameCaptionButtonContainerView container(NULL, widget.get(), | 217 FrameCaptionButtonContainerView container(widget.get(), |
| 218 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 218 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 219 FrameCaptionButtonContainerView::TestApi t(&container); | 219 FrameCaptionButtonContainerView::TestApi t(&container); |
| 220 | 220 |
| 221 // Tall header style. | 221 // Tall header style. |
| 222 container.set_header_style( | 222 container.set_header_style( |
| 223 FrameCaptionButtonContainerView::HEADER_STYLE_TALL); | 223 FrameCaptionButtonContainerView::HEADER_STYLE_TALL); |
| 224 container.Layout(); | 224 container.Layout(); |
| 225 EXPECT_TRUE(ImagesMatch(t.size_button(), | 225 EXPECT_TRUE(ImagesMatch(t.size_button(), |
| 226 IDR_AURA_WINDOW_MAXIMIZE, | 226 IDR_AURA_WINDOW_MAXIMIZE, |
| 227 IDR_AURA_WINDOW_MAXIMIZE_H, | 227 IDR_AURA_WINDOW_MAXIMIZE_H, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 // Test how the alternate button style affects which buttons are visible in the | 306 // Test how the alternate button style affects which buttons are visible in the |
| 307 // default case. | 307 // default case. |
| 308 TEST_F(FrameCaptionButtonContainerViewTestAlternateStyle, ButtonVisibility) { | 308 TEST_F(FrameCaptionButtonContainerViewTestAlternateStyle, ButtonVisibility) { |
| 309 // Both the minimize button and the maximize button should be visible when | 309 // Both the minimize button and the maximize button should be visible when |
| 310 // both minimizing and maximizing are allowed when using the alternate | 310 // both minimizing and maximizing are allowed when using the alternate |
| 311 // button style. | 311 // button style. |
| 312 scoped_ptr<views::Widget> widget_can_maximize( | 312 scoped_ptr<views::Widget> widget_can_maximize( |
| 313 CreateTestWidget(MAXIMIZE_ALLOWED)); | 313 CreateTestWidget(MAXIMIZE_ALLOWED)); |
| 314 FrameCaptionButtonContainerView container(NULL, widget_can_maximize.get(), | 314 FrameCaptionButtonContainerView container(widget_can_maximize.get(), |
| 315 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 315 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 316 container.Layout(); | 316 container.Layout(); |
| 317 FrameCaptionButtonContainerView::TestApi t(&container); | 317 FrameCaptionButtonContainerView::TestApi t(&container); |
| 318 EXPECT_TRUE(t.minimize_button()->visible()); | 318 EXPECT_TRUE(t.minimize_button()->visible()); |
| 319 EXPECT_TRUE(t.size_button()->visible()); | 319 EXPECT_TRUE(t.size_button()->visible()); |
| 320 EXPECT_TRUE(t.close_button()->visible()); | 320 EXPECT_TRUE(t.close_button()->visible()); |
| 321 EXPECT_TRUE(CheckButtonsAtEdges( | 321 EXPECT_TRUE(CheckButtonsAtEdges( |
| 322 &container, *t.minimize_button(), *t.close_button())); | 322 &container, *t.minimize_button(), *t.close_button())); |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace ash | 325 } // namespace ash |
| OLD | NEW |