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

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: Created 6 years, 8 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
12 namespace views {
13
14 namespace {
15
16 // Allows for the control of whether or not the widget can maximize or not.
17 // This can be set after initial setup in order to allow testing of both forms
18 // of delegates. By default this can maximize.
19 class MaximizeStateControlDelegate : public WidgetDelegateView {
20 public:
21 MaximizeStateControlDelegate() : can_maximize_(true) {}
22 virtual ~MaximizeStateControlDelegate() {}
23
24 void set_can_maximize(bool can_maximize) {
25 can_maximize_ = can_maximize;
26 }
27
28 // WidgetDelegate:
29 virtual bool CanMaximize() const OVERRIDE { return can_maximize_; }
30
31 private:
32 bool can_maximize_;
33
34 DISALLOW_COPY_AND_ASSIGN(MaximizeStateControlDelegate);
35 };
36
37 } // namespace
38
39 class CustomFrameViewTest : public ViewsTestBase {
40 public:
41 CustomFrameViewTest() {}
42 virtual ~CustomFrameViewTest() {}
43
44 CustomFrameView* custom_frame_view() {
45 return custom_frame_view_;
46 }
47
48 MaximizeStateControlDelegate* maximize_state_control_delegate() {
49 return maximize_state_control_delegate_;
50 }
51
52 Widget* widget() {
53 return widget_;
54 }
55
56 // ViewsTestBase:
57 virtual void SetUp() OVERRIDE;
58 virtual void TearDown() OVERRIDE;
59
60 protected:
61 std::vector<views::FrameButton> GetLeadingButtons() {
62 return custom_frame_view_->leading_buttons_;
63 }
64
65 std::vector<views::FrameButton> GetTrailingButtons() {
66 return custom_frame_view_->trailing_buttons_;
67 }
68
69 ImageButton* GetMinimizeButton() {
70 return custom_frame_view_->minimize_button_;
71 }
72
73 ImageButton* GetMaximizeButton() {
74 return custom_frame_view_->maximize_button_;
75 }
76
77 ImageButton* GetRestoreButton() {
78 return custom_frame_view_->restore_button_;
79 }
80
81 ImageButton* GetCloseButton() {
82 return custom_frame_view_->close_button_;
83 }
84
85 gfx::Rect GetTitleBounds() {
86 return custom_frame_view_->title_bounds_;
87 }
88
89 private:
90 // Parent container for |custom_frame_view_|
91 Widget* widget_;
92
93 // Owned by |widget_|
94 CustomFrameView* custom_frame_view_;
95
96 // Delegate of |widget_| which controls maximizing
97 MaximizeStateControlDelegate* maximize_state_control_delegate_;
98
99 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest);
100 };
101
102 void CustomFrameViewTest::SetUp() {
103 ViewsTestBase::SetUp();
104
105 maximize_state_control_delegate_ = new MaximizeStateControlDelegate;
106 widget_ = new Widget;
107 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
108 params.delegate = maximize_state_control_delegate_;
109 params.remove_standard_frame = true;
110 params.top_level = true;
111 widget_->Init(params);
112
113 custom_frame_view_ = new CustomFrameView;
114 widget_->non_client_view()->SetFrameView(custom_frame_view_);
115 }
116
117 void CustomFrameViewTest::TearDown() {
118 widget_->CloseNow();
119
120 ViewsTestBase::TearDown();
121 }
122
123 // Tests that there is a default button ordering before initialization causes
124 // a configuration file check.
125 TEST_F(CustomFrameViewTest, DefaultButtons) {
126 std::vector<views::FrameButton> trailing = GetTrailingButtons();
127 EXPECT_EQ(trailing.size(), 3u);
128 EXPECT_TRUE(GetLeadingButtons().empty());
129 EXPECT_EQ(trailing[0], FRAME_BUTTON_MINIMIZE);
130 EXPECT_EQ(trailing[1], FRAME_BUTTON_MAXIMIZE);
131 EXPECT_EQ(trailing[2], FRAME_BUTTON_CLOSE);
132 }
133
134 // Tests that layout places the buttons in order, that the restore button is
135 // hidden and the buttons are placed after the title.
136 TEST_F(CustomFrameViewTest, DefaultButtonLayout) {
137 Widget* parent = widget();
138 CustomFrameView* view = custom_frame_view();
139 view->Init(parent);
140 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
141 parent->Show();
142
143 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
144 EXPECT_LT(GetMaximizeButton()->x(), GetCloseButton()->x());
145 EXPECT_FALSE(GetRestoreButton()->visible());
146
147 EXPECT_GT(GetMinimizeButton()->x(),
148 GetTitleBounds().x() + GetTitleBounds().width());
149 }
150
151 // Tests that setting the buttons to leading places them before the title.
152 TEST_F(CustomFrameViewTest, LeadingButtonLayout) {
153 Widget* parent = widget();
154 CustomFrameView* view = custom_frame_view();
155
156 std::vector<views::FrameButton> leading;
157 leading.push_back(views::FRAME_BUTTON_CLOSE);
158 leading.push_back(views::FRAME_BUTTON_MINIMIZE);
159 leading.push_back(views::FRAME_BUTTON_MAXIMIZE);
160
161 std::vector<views::FrameButton> trailing;
162
163 view->OnWindowButtonOrderingChange(leading, trailing);
164
165 view->Init(parent);
166 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
167 parent->Show();
168 EXPECT_LT(GetCloseButton()->x(), GetMinimizeButton()->x());
169 EXPECT_LT(GetMinimizeButton()->x(), GetMaximizeButton()->x());
170 EXPECT_FALSE(GetRestoreButton()->visible());
171 EXPECT_LT(GetMaximizeButton()->x() + GetMaximizeButton()->width(),
172 GetTitleBounds().x());
173 }
174
175 // Tests that layouts occuring while maximized swap the maximize button for the
176 // restore button
177 TEST_F(CustomFrameViewTest, MaximizeRevealsRestoreButton) {
178 Widget* parent = widget();
179 CustomFrameView* view = custom_frame_view();
180 view->Init(parent);
181 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
182 parent->Show();
183
184 ASSERT_FALSE(GetRestoreButton()->visible());
185 ASSERT_TRUE(GetMaximizeButton()->visible());
186
187 parent->Maximize();
188 view->Layout();
189
190 EXPECT_TRUE(GetRestoreButton()->visible());
191 EXPECT_FALSE(GetMaximizeButton()->visible());
192 }
193
194 // Tests that when the parent cannot maximize that the maximize button is not
195 // visible
196 TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) {
197 Widget* parent = widget();
198 CustomFrameView* view = custom_frame_view();
199 MaximizeStateControlDelegate* delegate = maximize_state_control_delegate();
200 delegate->set_can_maximize(false);
201
202 view->Init(parent);
203 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
204 parent->Show();
205
206 EXPECT_FALSE(GetRestoreButton()->visible());
207 EXPECT_FALSE(GetMaximizeButton()->visible());
208 }
209
210 } // namespace views
OLDNEW
« ui/views/window/custom_frame_view.cc ('K') | « ui/views/window/custom_frame_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698