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/ash_switches.h" | |
8 #include "ash/frame/caption_buttons/frame_caption_button.h" | 7 #include "ash/frame/caption_buttons/frame_caption_button.h" |
9 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
10 #include "base/command_line.h" | |
11 #include "grit/ash_resources.h" | 9 #include "grit/ash_resources.h" |
12 #include "ui/aura/window_event_dispatcher.h" | |
13 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
14 #include "ui/views/widget/widget_delegate.h" | 11 #include "ui/views/widget/widget_delegate.h" |
15 | 12 |
16 namespace ash { | 13 namespace ash { |
17 | 14 |
18 namespace { | 15 namespace { |
19 | 16 |
20 class TestWidgetDelegate : public views::WidgetDelegateView { | 17 class TestWidgetDelegate : public views::WidgetDelegateView { |
21 public: | 18 public: |
22 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { | 19 TestWidgetDelegate(bool can_maximize) : can_maximize_(can_maximize) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 LOG(ERROR) << "Buttons " << leftmost.bounds().ToString() << " " | 92 LOG(ERROR) << "Buttons " << leftmost.bounds().ToString() << " " |
96 << rightmost.bounds().ToString() << " not at edges of " | 93 << rightmost.bounds().ToString() << " not at edges of " |
97 << expected.ToString(); | 94 << expected.ToString(); |
98 return false; | 95 return false; |
99 } | 96 } |
100 | 97 |
101 private: | 98 private: |
102 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); | 99 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTest); |
103 }; | 100 }; |
104 | 101 |
105 class FrameCaptionButtonContainerViewTestOldStyle | |
106 : public FrameCaptionButtonContainerViewTest { | |
107 public: | |
108 FrameCaptionButtonContainerViewTestOldStyle() { | |
109 } | |
110 | |
111 virtual ~FrameCaptionButtonContainerViewTestOldStyle() { | |
112 } | |
113 | |
114 virtual void SetUp() OVERRIDE { | |
115 FrameCaptionButtonContainerViewTest::SetUp(); | |
116 CommandLine::ForCurrentProcess()->AppendSwitch( | |
117 switches::kAshDisableAlternateFrameCaptionButtonStyle); | |
118 } | |
119 | |
120 private: | |
121 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTestOldStyle); | |
122 }; | |
123 | |
124 // Test how the allowed actions affect which caption buttons are visible. | 102 // Test how the allowed actions affect which caption buttons are visible. |
125 TEST_F(FrameCaptionButtonContainerViewTestOldStyle, ButtonVisibility) { | 103 TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
126 // The minimize button should be hidden when both minimizing and maximizing | 104 // All the buttons should be visible when minimizing and maximizing are |
127 // are allowed because the size button can do both. | 105 // allowed. |
128 scoped_ptr<views::Widget> widget_can_maximize( | 106 scoped_ptr<views::Widget> widget_can_maximize( |
129 CreateTestWidget(MAXIMIZE_ALLOWED)); | 107 CreateTestWidget(MAXIMIZE_ALLOWED)); |
130 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), | 108 FrameCaptionButtonContainerView container1(widget_can_maximize.get(), |
131 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 109 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
132 SetMockImages(&container1); | 110 SetMockImages(&container1); |
133 container1.Layout(); | 111 container1.Layout(); |
134 FrameCaptionButtonContainerView::TestApi t1(&container1); | 112 FrameCaptionButtonContainerView::TestApi t1(&container1); |
135 EXPECT_FALSE(t1.minimize_button()->visible()); | 113 EXPECT_TRUE(t1.minimize_button()->visible()); |
136 EXPECT_TRUE(t1.size_button()->visible()); | 114 EXPECT_TRUE(t1.size_button()->visible()); |
137 EXPECT_TRUE(t1.close_button()->visible()); | 115 EXPECT_TRUE(t1.close_button()->visible()); |
138 EXPECT_TRUE(CheckButtonsAtEdges( | 116 EXPECT_TRUE(CheckButtonsAtEdges( |
139 &container1, *t1.size_button(), *t1.close_button())); | 117 &container1, *t1.minimize_button(), *t1.close_button())); |
140 | 118 |
141 // The minimize button should be visible when minimizing is allowed but | 119 // The minimize button should be visible when minimizing is allowed but |
142 // maximizing is disallowed. | 120 // maximizing is disallowed. |
143 scoped_ptr<views::Widget> widget_cannot_maximize( | 121 scoped_ptr<views::Widget> widget_cannot_maximize( |
144 CreateTestWidget(MAXIMIZE_DISALLOWED)); | 122 CreateTestWidget(MAXIMIZE_DISALLOWED)); |
145 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), | 123 FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), |
146 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 124 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
147 SetMockImages(&container2); | 125 SetMockImages(&container2); |
148 container2.Layout(); | 126 container2.Layout(); |
149 FrameCaptionButtonContainerView::TestApi t2(&container2); | 127 FrameCaptionButtonContainerView::TestApi t2(&container2); |
(...skipping 10 matching lines...) Expand all Loading... |
160 SetMockImages(&container3); | 138 SetMockImages(&container3); |
161 container3.Layout(); | 139 container3.Layout(); |
162 FrameCaptionButtonContainerView::TestApi t3(&container3); | 140 FrameCaptionButtonContainerView::TestApi t3(&container3); |
163 EXPECT_FALSE(t3.minimize_button()->visible()); | 141 EXPECT_FALSE(t3.minimize_button()->visible()); |
164 EXPECT_FALSE(t3.size_button()->visible()); | 142 EXPECT_FALSE(t3.size_button()->visible()); |
165 EXPECT_TRUE(t3.close_button()->visible()); | 143 EXPECT_TRUE(t3.close_button()->visible()); |
166 EXPECT_TRUE(CheckButtonsAtEdges( | 144 EXPECT_TRUE(CheckButtonsAtEdges( |
167 &container3, *t3.close_button(), *t3.close_button())); | 145 &container3, *t3.close_button(), *t3.close_button())); |
168 } | 146 } |
169 | 147 |
170 class FrameCaptionButtonContainerViewTestAlternateStyle | |
171 : public FrameCaptionButtonContainerViewTest { | |
172 public: | |
173 FrameCaptionButtonContainerViewTestAlternateStyle() { | |
174 } | |
175 | |
176 virtual ~FrameCaptionButtonContainerViewTestAlternateStyle() { | |
177 } | |
178 | |
179 virtual void SetUp() OVERRIDE { | |
180 FrameCaptionButtonContainerViewTest::SetUp(); | |
181 CommandLine::ForCurrentProcess()->AppendSwitch( | |
182 switches::kAshEnableAlternateFrameCaptionButtonStyle); | |
183 } | |
184 | |
185 private: | |
186 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerViewTestAlternateStyle); | |
187 }; | |
188 | |
189 // Test how the alternate button style affects which buttons are visible in the | |
190 // default case. | |
191 TEST_F(FrameCaptionButtonContainerViewTestAlternateStyle, ButtonVisibility) { | |
192 // Both the minimize button and the maximize button should be visible when | |
193 // both minimizing and maximizing are allowed when using the alternate | |
194 // button style. | |
195 scoped_ptr<views::Widget> widget_can_maximize( | |
196 CreateTestWidget(MAXIMIZE_ALLOWED)); | |
197 FrameCaptionButtonContainerView container(widget_can_maximize.get(), | |
198 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | |
199 SetMockImages(&container); | |
200 container.Layout(); | |
201 FrameCaptionButtonContainerView::TestApi t(&container); | |
202 EXPECT_TRUE(t.minimize_button()->visible()); | |
203 EXPECT_TRUE(t.size_button()->visible()); | |
204 EXPECT_TRUE(t.close_button()->visible()); | |
205 EXPECT_TRUE(CheckButtonsAtEdges( | |
206 &container, *t.minimize_button(), *t.close_button())); | |
207 } | |
208 | |
209 } // namespace ash | 148 } // namespace ash |
OLD | NEW |