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

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

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

Powered by Google App Engine
This is Rietveld 408576698