Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: ui/views/window/custom_frame_view_unittest.cc

Issue 281353009: Reland Linux Window Control Alignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix another test Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 "ui/views/window/custom_frame_view.h"
6
7 #include <vector>
8
9 #include "ui/views/controls/button/image_button.h"
10 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget.h"
12 #include "ui/views/widget/widget_delegate.h"
13 #include "ui/views/window/window_button_order_provider.h"
14
15 namespace views {
16
17 namespace {
18
19 // Allows for the control of whether or not the widget can maximize or not.
20 // This can be set after initial setup in order to allow testing of both forms
21 // of delegates. By default this can maximize.
22 class MaximizeStateControlDelegate : public WidgetDelegateView {
23 public:
24 MaximizeStateControlDelegate() : can_maximize_(true) {}
25 virtual ~MaximizeStateControlDelegate() {}
26
27 void set_can_maximize(bool can_maximize) {
28 can_maximize_ = can_maximize;
29 }
30
31 // WidgetDelegate:
32 virtual bool CanMaximize() const OVERRIDE { return can_maximize_; }
33
34 private:
35 bool can_maximize_;
36
37 DISALLOW_COPY_AND_ASSIGN(MaximizeStateControlDelegate);
38 };
39
40 } // namespace
41
42 class CustomFrameViewTest : public ViewsTestBase {
43 public:
44 CustomFrameViewTest() {}
45 virtual ~CustomFrameViewTest() {}
46
47 CustomFrameView* custom_frame_view() {
48 return custom_frame_view_;
49 }
50
51 MaximizeStateControlDelegate* maximize_state_control_delegate() {
52 return maximize_state_control_delegate_;
53 }
54
55 Widget* widget() {
56 return widget_;
57 }
58
59 // ViewsTestBase:
60 virtual void SetUp() OVERRIDE;
61 virtual void TearDown() OVERRIDE;
62
63 protected:
64 std::vector<views::FrameButton> GetLeadingButtons() {
varkha 2014/05/15 23:33:18 This may be just simple enough to call it leading_
jonross 2014/05/16 18:59:48 Done.
65 return WindowButtonOrderProvider::GetInstance()->GetLeadingButtons();
66 }
67
68 std::vector<views::FrameButton> GetTrailingButtons() {
69 return WindowButtonOrderProvider::GetInstance()->GetTrailingButtons();
70 }
71
72 ImageButton* GetMinimizeButton() {
varkha 2014/05/15 23:33:18 This may be just simple enough to call it minimize
jonross 2014/05/16 18:59:48 Done.
73 return custom_frame_view_->minimize_button_;
74 }
75
76 ImageButton* GetMaximizeButton() {
77 return custom_frame_view_->maximize_button_;
78 }
79
80 ImageButton* GetRestoreButton() {
81 return custom_frame_view_->restore_button_;
82 }
83
84 ImageButton* GetCloseButton() {
85 return custom_frame_view_->close_button_;
86 }
87
88 gfx::Rect GetTitleBounds() {
varkha 2014/05/15 23:33:18 This may be just simple enough to call it title_bo
jonross 2014/05/16 18:59:48 Done.
89 return custom_frame_view_->title_bounds_;
90 }
91
92 void SetWindowButtonOrder(
93 const std::vector<views::FrameButton> leading_buttons,
94 const std::vector<views::FrameButton> trailing_buttons);
95
96 private:
97 // Parent container for |custom_frame_view_|
98 Widget* widget_;
99
100 // Owned by |widget_|
101 CustomFrameView* custom_frame_view_;
102
103 // Delegate of |widget_| which controls maximizing
104 MaximizeStateControlDelegate* maximize_state_control_delegate_;
105
106 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest);
107 };
108
109 void CustomFrameViewTest::SetUp() {
110 ViewsTestBase::SetUp();
111
112 maximize_state_control_delegate_ = new MaximizeStateControlDelegate;
113 widget_ = new Widget;
114 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
115 params.delegate = maximize_state_control_delegate_;
116 params.remove_standard_frame = true;
117 params.top_level = true;
118 widget_->Init(params);
119
120 custom_frame_view_ = new CustomFrameView;
121 widget_->non_client_view()->SetFrameView(custom_frame_view_);
122 }
123
124 void CustomFrameViewTest::TearDown() {
125 widget_->CloseNow();
126
127 ViewsTestBase::TearDown();
128 }
129
130 void CustomFrameViewTest::SetWindowButtonOrder(
131 const std::vector<views::FrameButton> leading_buttons,
132 const std::vector<views::FrameButton> trailing_buttons) {
133 WindowButtonOrderProvider::GetInstance()->
134 SetWindowButtonOrder(leading_buttons, trailing_buttons);
135 }
136
137 // Tests that there is a default button ordering before initialization causes
138 // a configuration file check.
139 TEST_F(CustomFrameViewTest, DefaultButtons) {
140 std::vector<views::FrameButton> trailing = GetTrailingButtons();
141 EXPECT_EQ(trailing.size(), 3u);
142 EXPECT_TRUE(GetLeadingButtons().empty());
143 EXPECT_EQ(trailing[0], FRAME_BUTTON_MINIMIZE);
144 EXPECT_EQ(trailing[1], FRAME_BUTTON_MAXIMIZE);
145 EXPECT_EQ(trailing[2], FRAME_BUTTON_CLOSE);
146 }
147
148 // Tests that layout places the buttons in order, that the restore button is
149 // hidden and the buttons are placed after the title.
150 TEST_F(CustomFrameViewTest, DefaultButtonLayout) {
151 Widget* parent = widget();
152 CustomFrameView* view = custom_frame_view();
153 view->Init(parent);
154 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
155 parent->Show();
156
157 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
158 EXPECT_LT(GetMaximizeButton()->x(), GetCloseButton()->x());
159 EXPECT_FALSE(GetRestoreButton()->visible());
160
161 EXPECT_GT(GetMinimizeButton()->x(),
162 GetTitleBounds().x() + GetTitleBounds().width());
163 }
164
165 // Tests that setting the buttons to leading places them before the title.
166 TEST_F(CustomFrameViewTest, LeadingButtonLayout) {
167 Widget* parent = widget();
168 CustomFrameView* view = custom_frame_view();
169
170 std::vector<views::FrameButton> leading;
171 leading.push_back(views::FRAME_BUTTON_CLOSE);
172 leading.push_back(views::FRAME_BUTTON_MINIMIZE);
173 leading.push_back(views::FRAME_BUTTON_MAXIMIZE);
174
175 std::vector<views::FrameButton> trailing;
176
177 SetWindowButtonOrder(leading, trailing);
178
179 view->Init(parent);
180 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
181 parent->Show();
182 EXPECT_LT(GetCloseButton()->x(), GetMinimizeButton()->x());
183 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
184 EXPECT_FALSE(GetRestoreButton()->visible());
185 EXPECT_LT(GetMaximizeButton()->x() + GetMaximizeButton()->width(),
186 GetTitleBounds().x());
187 }
188
189 // Tests that layouts occuring while maximized swap the maximize button for the
190 // restore button
191 TEST_F(CustomFrameViewTest, MaximizeRevealsRestoreButton) {
192 Widget* parent = widget();
193 CustomFrameView* view = custom_frame_view();
194 view->Init(parent);
195 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
196 parent->Show();
197
198 ASSERT_FALSE(GetRestoreButton()->visible());
199 ASSERT_TRUE(GetMaximizeButton()->visible());
200
201 parent->Maximize();
202 view->Layout();
203
204 EXPECT_TRUE(GetRestoreButton()->visible());
205 EXPECT_FALSE(GetMaximizeButton()->visible());
206 }
207
208 // Tests that when the parent cannot maximize that the maximize button is not
209 // visible
210 TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) {
211 Widget* parent = widget();
212 CustomFrameView* view = custom_frame_view();
213 MaximizeStateControlDelegate* delegate = maximize_state_control_delegate();
214 delegate->set_can_maximize(false);
215
216 view->Init(parent);
217 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
218 parent->Show();
219
220 EXPECT_FALSE(GetRestoreButton()->visible());
221 EXPECT_FALSE(GetMaximizeButton()->visible());
222 }
223
224 // Tests that when maximized that the edge button has an increased width.
225 TEST_F(CustomFrameViewTest, LargerEdgeButtonsWhenMaximized) {
226 Widget* parent = widget();
227 CustomFrameView* view = custom_frame_view();
228
229 // Custom ordering to have a button on each edge.
230 std::vector<views::FrameButton> leading;
231 leading.push_back(views::FRAME_BUTTON_CLOSE);
232 leading.push_back(views::FRAME_BUTTON_MAXIMIZE);
233 std::vector<views::FrameButton> trailing;
234 trailing.push_back(views::FRAME_BUTTON_MINIMIZE);
235 SetWindowButtonOrder(leading, trailing);
236
237 view->Init(parent);
238 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
239 parent->Show();
240
241 gfx::Rect close_button_initial_bounds = GetCloseButton()->bounds();
242 gfx::Rect minimize_button_initial_bounds = GetMinimizeButton()->bounds();
243
244 parent->Maximize();
245 view->Layout();
246
247 EXPECT_GT(GetCloseButton()->bounds().width(),
248 close_button_initial_bounds.width());
249 EXPECT_GT(GetMinimizeButton()->bounds().width(),
250 minimize_button_initial_bounds.width());
251 }
252
253 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698