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

Side by Side Diff: ash/common/frame/custom_frame_view_ash_unittest.cc

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: Created 3 years, 9 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 | « ash/common/frame/custom_frame_view_ash.cc ('k') | ash/common/frame/default_header_painter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ash/common/frame/custom_frame_view_ash.h"
6
7 #include <memory>
8
9 #include "ash/common/ash_layout_constants.h"
10 #include "ash/common/frame/caption_buttons/frame_caption_button.h"
11 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h "
12 #include "ash/common/test/test_session_state_delegate.h"
13 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
14 #include "ash/common/wm_shell.h"
15 #include "ash/test/ash_test_base.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/image/image_skia.h"
18 #include "ui/gfx/image/image_unittest_util.h"
19 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h"
21
22 namespace ash {
23
24 // A views::WidgetDelegate which uses a CustomFrameViewAsh.
25 class TestWidgetDelegate : public views::WidgetDelegateView {
26 public:
27 TestWidgetDelegate() {}
28 ~TestWidgetDelegate() override {}
29
30 views::NonClientFrameView* CreateNonClientFrameView(
31 views::Widget* widget) override {
32 custom_frame_view_ = new CustomFrameViewAsh(widget);
33 return custom_frame_view_;
34 }
35
36 CustomFrameViewAsh* custom_frame_view() const { return custom_frame_view_; }
37
38 private:
39 // Not owned.
40 CustomFrameViewAsh* custom_frame_view_;
41
42 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
43 };
44
45 class TestWidgetConstraintsDelegate : public TestWidgetDelegate {
46 public:
47 TestWidgetConstraintsDelegate() {}
48 ~TestWidgetConstraintsDelegate() override {}
49
50 // views::View:
51 gfx::Size GetMinimumSize() const override { return minimum_size_; }
52
53 gfx::Size GetMaximumSize() const override { return maximum_size_; }
54
55 views::View* GetContentsView() override {
56 // Set this instance as the contents view so that the maximum and minimum
57 // size constraints will be used.
58 return this;
59 }
60
61 // views::WidgetDelegate:
62 bool CanMaximize() const override { return true; }
63
64 bool CanMinimize() const override { return true; }
65
66 void set_minimum_size(const gfx::Size& min_size) { minimum_size_ = min_size; }
67
68 void set_maximum_size(const gfx::Size& max_size) { maximum_size_ = max_size; }
69
70 const gfx::Rect& GetFrameCaptionButtonContainerViewBounds() {
71 return custom_frame_view()
72 ->GetFrameCaptionButtonContainerViewForTest()
73 ->bounds();
74 }
75
76 void EndFrameCaptionButtonContainerViewAnimations() {
77 FrameCaptionButtonContainerView::TestApi test(
78 custom_frame_view()->GetFrameCaptionButtonContainerViewForTest());
79 test.EndAnimations();
80 }
81
82 int GetTitleBarHeight() const {
83 return custom_frame_view()->NonClientTopBorderHeight();
84 }
85
86 private:
87 gfx::Size minimum_size_;
88 gfx::Size maximum_size_;
89
90 DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate);
91 };
92
93 class CustomFrameViewAshTest : public test::AshTestBase {
94 public:
95 CustomFrameViewAshTest() {}
96 ~CustomFrameViewAshTest() override {}
97
98 protected:
99 std::unique_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) {
100 std::unique_ptr<views::Widget> widget(new views::Widget);
101 views::Widget::InitParams params;
102 params.delegate = delegate;
103 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
104 params.bounds = gfx::Rect(0, 0, 100, 100);
105 params.context = CurrentContext();
106 widget->Init(params);
107 return widget;
108 }
109
110 test::TestSessionStateDelegate* GetTestSessionStateDelegate() {
111 return static_cast<test::TestSessionStateDelegate*>(
112 WmShell::Get()->GetSessionStateDelegate());
113 }
114
115 private:
116 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
117 };
118
119 // Verifies the client view is not placed at a y location of 0.
120 TEST_F(CustomFrameViewAshTest, ClientViewCorrectlyPlaced) {
121 std::unique_ptr<views::Widget> widget(CreateWidget(new TestWidgetDelegate));
122 widget->Show();
123 EXPECT_NE(0, widget->client_view()->bounds().y());
124 }
125
126 // Test that the height of the header is correct upon initially displaying
127 // the widget.
128 TEST_F(CustomFrameViewAshTest, HeaderHeight) {
129 TestWidgetDelegate* delegate = new TestWidgetDelegate;
130
131 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
132 widget->Show();
133
134 // The header should have enough room for the window controls. The
135 // header/content separator line overlays the window controls.
136 EXPECT_EQ(
137 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(),
138 delegate->custom_frame_view()->GetHeaderView()->height());
139 }
140
141 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
142 // sizes when the client view does not specify any size constraints.
143 TEST_F(CustomFrameViewAshTest, NoSizeConstraints) {
144 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
145 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
146
147 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
148 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
149 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
150
151 EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height());
152
153 // A width and height constraint of 0 denotes unbounded.
154 EXPECT_EQ(0, max_frame_size.width());
155 EXPECT_EQ(0, max_frame_size.height());
156 }
157
158 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
159 // sizes when the client view specifies size constraints.
160 TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) {
161 gfx::Size min_client_size(500, 500);
162 gfx::Size max_client_size(800, 800);
163 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
164 delegate->set_minimum_size(min_client_size);
165 delegate->set_maximum_size(max_client_size);
166 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
167
168 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
169 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
170 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
171
172 EXPECT_EQ(min_client_size.width(), min_frame_size.width());
173 EXPECT_EQ(max_client_size.width(), max_frame_size.width());
174 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
175 min_frame_size.height());
176 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
177 max_frame_size.height());
178 }
179
180 // Verify that CustomFrameViewAsh updates the avatar icon based on the
181 // state of the SessionStateDelegate after visibility change.
182 TEST_F(CustomFrameViewAshTest, AvatarIcon) {
183 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
184 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
185
186 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
187 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
188
189 // Avatar image becomes available.
190 GetTestSessionStateDelegate()->SetUserImage(
191 gfx::test::CreateImage(27, 27).AsImageSkia());
192 widget->Hide();
193 widget->Show();
194 EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest());
195
196 // Avatar image is gone; the ImageView for the avatar icon should be
197 // removed.
198 GetTestSessionStateDelegate()->SetUserImage(gfx::ImageSkia());
199 widget->Hide();
200 widget->Show();
201 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
202 }
203
204 // The visibility of the size button is updated when maximize mode is toggled.
205 // Verify that the layout of the HeaderView is updated for the size button's
206 // new visibility.
207 TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) {
208 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
209 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
210
211 const gfx::Rect initial =
212 delegate->GetFrameCaptionButtonContainerViewBounds();
213 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
214 true);
215 delegate->EndFrameCaptionButtonContainerViewAnimations();
216 const gfx::Rect maximize_mode_bounds =
217 delegate->GetFrameCaptionButtonContainerViewBounds();
218 EXPECT_GT(initial.width(), maximize_mode_bounds.width());
219 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
220 false);
221 delegate->EndFrameCaptionButtonContainerViewAnimations();
222 const gfx::Rect after_restore =
223 delegate->GetFrameCaptionButtonContainerViewBounds();
224 EXPECT_EQ(initial, after_restore);
225 }
226
227 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/frame/custom_frame_view_ash.cc ('k') | ash/common/frame/default_header_painter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698