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

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

Issue 567463002: Color picker window should not have a minimize button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and Added unit test for minimize button visibility. Created 6 years, 3 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
« no previous file with comments | « ui/views/window/custom_frame_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "ui/views/window/custom_frame_view.h" 5 #include "ui/views/window/custom_frame_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ui/views/controls/button/image_button.h" 9 #include "ui/views/controls/button/image_button.h"
10 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget.h" 11 #include "ui/views/widget/widget.h"
12 #include "ui/views/widget/widget_delegate.h" 12 #include "ui/views/widget/widget_delegate.h"
13 #include "ui/views/window/window_button_order_provider.h" 13 #include "ui/views/window/window_button_order_provider.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 namespace { 17 namespace {
18 18
19 // Allows for the control of whether or not the widget can maximize or not. 19 // Allows for the control of whether or not the widget can minimize/maximize or
20 // This can be set after initial setup in order to allow testing of both forms 20 // not. This can be set after initial setup in order to allow testing of both
21 // of delegates. By default this can maximize. 21 // forms of delegates. By default this can minimize and maximize.
22 class MaximizeStateControlDelegate : public WidgetDelegateView { 22 class MinimizeAndMaximizeStateControlDelegate : public WidgetDelegateView {
23 public: 23 public:
24 MaximizeStateControlDelegate() : can_maximize_(true) {} 24 MinimizeAndMaximizeStateControlDelegate()
25 virtual ~MaximizeStateControlDelegate() {} 25 : can_maximize_(true),
26 can_minimize_(true) {}
27 virtual ~MinimizeAndMaximizeStateControlDelegate() {}
26 28
27 void set_can_maximize(bool can_maximize) { 29 void set_can_maximize(bool can_maximize) {
28 can_maximize_ = can_maximize; 30 can_maximize_ = can_maximize;
29 } 31 }
30 32
33 void set_can_minimize(bool can_minimize) {
34 can_minimize_ = can_minimize;
35 }
36
31 // WidgetDelegate: 37 // WidgetDelegate:
32 virtual bool CanMaximize() const OVERRIDE { return can_maximize_; } 38 virtual bool CanMaximize() const OVERRIDE { return can_maximize_; }
39 virtual bool CanMinimize() const OVERRIDE { return can_minimize_; }
33 40
34 private: 41 private:
35 bool can_maximize_; 42 bool can_maximize_;
43 bool can_minimize_;
36 44
37 DISALLOW_COPY_AND_ASSIGN(MaximizeStateControlDelegate); 45 DISALLOW_COPY_AND_ASSIGN(MinimizeAndMaximizeStateControlDelegate);
38 }; 46 };
39 47
40 } // namespace 48 } // namespace
41 49
42 class CustomFrameViewTest : public ViewsTestBase { 50 class CustomFrameViewTest : public ViewsTestBase {
43 public: 51 public:
44 CustomFrameViewTest() {} 52 CustomFrameViewTest() {}
45 virtual ~CustomFrameViewTest() {} 53 virtual ~CustomFrameViewTest() {}
46 54
47 CustomFrameView* custom_frame_view() { 55 CustomFrameView* custom_frame_view() {
48 return custom_frame_view_; 56 return custom_frame_view_;
49 } 57 }
50 58
51 MaximizeStateControlDelegate* maximize_state_control_delegate() { 59 MinimizeAndMaximizeStateControlDelegate*
52 return maximize_state_control_delegate_; 60 minimize_and_maximize_state_control_delegate() {
61 return minimize_and_maximize_state_control_delegate_;
53 } 62 }
54 63
55 Widget* widget() { 64 Widget* widget() {
56 return widget_; 65 return widget_;
57 } 66 }
58 67
59 // ViewsTestBase: 68 // ViewsTestBase:
60 virtual void SetUp() OVERRIDE; 69 virtual void SetUp() OVERRIDE;
61 virtual void TearDown() OVERRIDE; 70 virtual void TearDown() OVERRIDE;
62 71
(...skipping 30 matching lines...) Expand all
93 const std::vector<views::FrameButton> leading_buttons, 102 const std::vector<views::FrameButton> leading_buttons,
94 const std::vector<views::FrameButton> trailing_buttons); 103 const std::vector<views::FrameButton> trailing_buttons);
95 104
96 private: 105 private:
97 // Parent container for |custom_frame_view_| 106 // Parent container for |custom_frame_view_|
98 Widget* widget_; 107 Widget* widget_;
99 108
100 // Owned by |widget_| 109 // Owned by |widget_|
101 CustomFrameView* custom_frame_view_; 110 CustomFrameView* custom_frame_view_;
102 111
103 // Delegate of |widget_| which controls maximizing 112 // Delegate of |widget_| which controls minimizing and maximizing
104 MaximizeStateControlDelegate* maximize_state_control_delegate_; 113 MinimizeAndMaximizeStateControlDelegate*
114 minimize_and_maximize_state_control_delegate_;
105 115
106 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest); 116 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewTest);
107 }; 117 };
108 118
109 void CustomFrameViewTest::SetUp() { 119 void CustomFrameViewTest::SetUp() {
110 ViewsTestBase::SetUp(); 120 ViewsTestBase::SetUp();
111 121
112 maximize_state_control_delegate_ = new MaximizeStateControlDelegate; 122 minimize_and_maximize_state_control_delegate_ =
123 new MinimizeAndMaximizeStateControlDelegate;
113 widget_ = new Widget; 124 widget_ = new Widget;
114 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 125 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
115 params.delegate = maximize_state_control_delegate_; 126 params.delegate = minimize_and_maximize_state_control_delegate_;
116 params.remove_standard_frame = true; 127 params.remove_standard_frame = true;
117 widget_->Init(params); 128 widget_->Init(params);
118 129
119 custom_frame_view_ = new CustomFrameView; 130 custom_frame_view_ = new CustomFrameView;
120 widget_->non_client_view()->SetFrameView(custom_frame_view_); 131 widget_->non_client_view()->SetFrameView(custom_frame_view_);
121 } 132 }
122 133
123 void CustomFrameViewTest::TearDown() { 134 void CustomFrameViewTest::TearDown() {
124 widget_->CloseNow(); 135 widget_->CloseNow();
125 136
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 213
203 EXPECT_TRUE(restore_button()->visible()); 214 EXPECT_TRUE(restore_button()->visible());
204 EXPECT_FALSE(maximize_button()->visible()); 215 EXPECT_FALSE(maximize_button()->visible());
205 } 216 }
206 217
207 // Tests that when the parent cannot maximize that the maximize button is not 218 // Tests that when the parent cannot maximize that the maximize button is not
208 // visible 219 // visible
209 TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) { 220 TEST_F(CustomFrameViewTest, CannotMaximizeHidesButton) {
210 Widget* parent = widget(); 221 Widget* parent = widget();
211 CustomFrameView* view = custom_frame_view(); 222 CustomFrameView* view = custom_frame_view();
212 MaximizeStateControlDelegate* delegate = maximize_state_control_delegate(); 223 MinimizeAndMaximizeStateControlDelegate* delegate =
224 minimize_and_maximize_state_control_delegate();
213 delegate->set_can_maximize(false); 225 delegate->set_can_maximize(false);
214 226
215 view->Init(parent); 227 view->Init(parent);
216 parent->SetBounds(gfx::Rect(0, 0, 300, 100)); 228 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
217 parent->Show(); 229 parent->Show();
218 230
219 EXPECT_FALSE(restore_button()->visible()); 231 EXPECT_FALSE(restore_button()->visible());
220 EXPECT_FALSE(maximize_button()->visible()); 232 EXPECT_FALSE(maximize_button()->visible());
221 } 233 }
222 234
235 // Tests that when the parent cannot minimize that the minimize button is not
236 // visible
237 TEST_F(CustomFrameViewTest, CannotMinimizeHidesButton) {
238 Widget* parent = widget();
239 CustomFrameView* view = custom_frame_view();
240 MinimizeAndMaximizeStateControlDelegate* delegate =
241 minimize_and_maximize_state_control_delegate();
242 delegate->set_can_minimize(false);
243
244 view->Init(parent);
245 parent->SetBounds(gfx::Rect(0, 0, 300, 100));
246 parent->Show();
247
248 EXPECT_FALSE(minimize_button()->visible());
249 }
250
223 // Tests that when maximized that the edge button has an increased width. 251 // Tests that when maximized that the edge button has an increased width.
224 TEST_F(CustomFrameViewTest, LargerEdgeButtonsWhenMaximized) { 252 TEST_F(CustomFrameViewTest, LargerEdgeButtonsWhenMaximized) {
225 Widget* parent = widget(); 253 Widget* parent = widget();
226 CustomFrameView* view = custom_frame_view(); 254 CustomFrameView* view = custom_frame_view();
227 255
228 // Custom ordering to have a button on each edge. 256 // Custom ordering to have a button on each edge.
229 std::vector<views::FrameButton> leading; 257 std::vector<views::FrameButton> leading;
230 leading.push_back(views::FRAME_BUTTON_CLOSE); 258 leading.push_back(views::FRAME_BUTTON_CLOSE);
231 leading.push_back(views::FRAME_BUTTON_MAXIMIZE); 259 leading.push_back(views::FRAME_BUTTON_MAXIMIZE);
232 std::vector<views::FrameButton> trailing; 260 std::vector<views::FrameButton> trailing;
(...skipping 10 matching lines...) Expand all
243 parent->Maximize(); 271 parent->Maximize();
244 view->Layout(); 272 view->Layout();
245 273
246 EXPECT_GT(close_button()->bounds().width(), 274 EXPECT_GT(close_button()->bounds().width(),
247 close_button_initial_bounds.width()); 275 close_button_initial_bounds.width());
248 EXPECT_GT(minimize_button()->bounds().width(), 276 EXPECT_GT(minimize_button()->bounds().width(),
249 minimize_button_initial_bounds.width()); 277 minimize_button_initial_bounds.width());
250 } 278 }
251 279
252 } // namespace views 280 } // namespace views
OLDNEW
« no previous file with comments | « 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