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

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

Issue 240163006: Linux Aura Task Manager Frame Buttons Misaligned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor button observer out of CustomFrameView 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 "ui/views/controls/button/image_button.h"
8 #include "ui/views/test/views_test_base.h"
9 #include "ui/views/widget/widget.h"
10 #include "ui/views/widget/widget_delegate.h"
11 #include "ui/views/window/window_button_order_provider.h"
12
13 namespace views {
14
15 namespace {
16
17 // Allows for the control of whether or not the widget can maximize or not.
18 // This can be set after initial setup in order to allow testing of both forms
19 // of delegates. By default this can maximize.
20 class MaximizeStateControlDelegate : public WidgetDelegateView {
21 public:
22 MaximizeStateControlDelegate() : can_maximize_(true) {}
23 virtual ~MaximizeStateControlDelegate() {}
24
25 void set_can_maximize(bool can_maximize) {
26 can_maximize_ = can_maximize;
27 }
28
29 // WidgetDelegate:
30 virtual bool CanMaximize() const OVERRIDE { return can_maximize_; }
31
32 private:
33 bool can_maximize_;
34
35 DISALLOW_COPY_AND_ASSIGN(MaximizeStateControlDelegate);
36 };
37
38 } // namespace
39
40 class CustomFrameViewTest : public ViewsTestBase {
41 public:
42 CustomFrameViewTest() {}
43 virtual ~CustomFrameViewTest() {}
44
45 CustomFrameView* custom_frame_view() {
46 return custom_frame_view_;
47 }
48
49 MaximizeStateControlDelegate* maximize_state_control_delegate() {
50 return maximize_state_control_delegate_;
51 }
52
53 Widget* widget() {
54 return widget_;
55 }
56
57 // ViewsTestBase:
58 virtual void SetUp() OVERRIDE;
59 virtual void TearDown() OVERRIDE;
60
61 protected:
62 std::vector<views::FrameButton> GetLeadingButtons() {
63 return WindowButtonOrderProvider::GetInstance()->GetLeadingButtons();
64 }
65
66 std::vector<views::FrameButton> GetTrailingButtons() {
67 return WindowButtonOrderProvider::GetInstance()->GetTrailingButtons();
68 }
69
70 ImageButton* GetMinimizeButton() {
71 return custom_frame_view_->minimize_button_;
72 }
73
74 ImageButton* GetMaximizeButton() {
75 return custom_frame_view_->maximize_button_;
76 }
77
78 ImageButton* GetRestoreButton() {
79 return custom_frame_view_->restore_button_;
80 }
81
82 ImageButton* GetCloseButton() {
83 return custom_frame_view_->close_button_;
84 }
85
86 gfx::Rect GetTitleBounds() {
87 return custom_frame_view_->title_bounds_;
88 }
89
90 void SetWindowButtonOrder(
91 const std::vector<views::FrameButton> leading_buttons,
92 const std::vector<views::FrameButton> trailing_buttons);
93
94 private:
95 // Parent container for |custom_frame_view_|
96 Widget* widget_;
97
98 // Owned by |widget_|
99 CustomFrameView* custom_frame_view_;
100
101 // Delegate of |widget_| which controls maximizing
102 MaximizeStateControlDelegate* maximize_state_control_delegate_;
103
104 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest);
105 };
106
107 void CustomFrameViewTest::SetUp() {
108 ViewsTestBase::SetUp();
109
110 maximize_state_control_delegate_ = new MaximizeStateControlDelegate;
111 widget_ = new Widget;
112 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
113 params.delegate = maximize_state_control_delegate_;
114 params.remove_standard_frame = true;
115 params.top_level = true;
116 widget_->Init(params);
117
118 custom_frame_view_ = new CustomFrameView;
119 widget_->non_client_view()->SetFrameView(custom_frame_view_);
120 }
121
122 void CustomFrameViewTest::TearDown() {
123 widget_->CloseNow();
124
125 ViewsTestBase::TearDown();
126 }
127
128 void CustomFrameViewTest::SetWindowButtonOrder(
129 const std::vector<views::FrameButton> leading_buttons,
130 const std::vector<views::FrameButton> trailing_buttons) {
131 WindowButtonOrderProvider::GetInstance()->
132 SetWindowButtonOrder(leading_buttons, trailing_buttons);
133 }
134
135 // Tests that there is a default button ordering before initialization causes
136 // a configuration file check.
137 TEST_F(CustomFrameViewTest, DefaultButtons) {
138 std::vector<views::FrameButton> trailing = GetTrailingButtons();
139 EXPECT_EQ(trailing.size(), 3u);
140 EXPECT_TRUE(GetLeadingButtons().empty());
141 EXPECT_EQ(trailing[0], FRAME_BUTTON_MINIMIZE);
142 EXPECT_EQ(trailing[1], FRAME_BUTTON_MAXIMIZE);
143 EXPECT_EQ(trailing[2], FRAME_BUTTON_CLOSE);
144 }
145
146 // Tests that layout places the buttons in order, that the restore button is
147 // hidden and the buttons are placed after the title.
148 TEST_F(CustomFrameViewTest, DefaultButtonLayout) {
149 Widget* parent = widget();
150 CustomFrameView* view = custom_frame_view();
151 view->Init(parent);
152 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
153 parent->Show();
154
155 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
156 EXPECT_LT(GetMaximizeButton()->x(), GetCloseButton()->x());
157 EXPECT_FALSE(GetRestoreButton()->visible());
158
159 EXPECT_GT(GetMinimizeButton()->x(),
160 GetTitleBounds().x() + GetTitleBounds().width());
161 }
162
163 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
164 // Tests that setting the buttons to leading places them before the title.
165 TEST_F(CustomFrameViewTest, LeadingButtonLayout) {
166 Widget* parent = widget();
167 CustomFrameView* view = custom_frame_view();
168
169 std::vector<views::FrameButton> leading;
170 leading.push_back(views::FRAME_BUTTON_CLOSE);
171 leading.push_back(views::FRAME_BUTTON_MINIMIZE);
172 leading.push_back(views::FRAME_BUTTON_MAXIMIZE);
173
174 std::vector<views::FrameButton> trailing;
175
176 SetWindowButtonOrder(leading, trailing);
177
178 view->Init(parent);
179 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
180 parent->Show();
181 EXPECT_LT(GetCloseButton()->x(), GetMinimizeButton()->x());
182 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
183 EXPECT_FALSE(GetRestoreButton()->visible());
184 EXPECT_LT(GetMaximizeButton()->x() + GetMaximizeButton()->width(),
185 GetTitleBounds().x());
186 }
187 #endif
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 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698