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

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

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 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
« no previous file with comments | « ash/frame/custom_frame_view_ash.cc ('k') | ash/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
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 "ash/frame/custom_frame_view_ash.h" 5 #include "ash/frame/custom_frame_view_ash.h"
6 6
7 #include <memory>
8
7 #include "ash/ash_layout_constants.h" 9 #include "ash/ash_layout_constants.h"
8 #include "ash/frame/caption_buttons/frame_caption_button.h" 10 #include "ash/frame/caption_buttons/frame_caption_button.h"
9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
10 #include "ash/shell.h" 12 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
12 #include "ash/test/test_session_state_delegate.h" 14 #include "ash/test/test_session_state_delegate.h"
13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 15 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
21 22
22 namespace ash { 23 namespace ash {
23 24
24 // A views::WidgetDelegate which uses a CustomFrameViewAsh. 25 // A views::WidgetDelegate which uses a CustomFrameViewAsh.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate); 96 DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate);
96 }; 97 };
97 98
98 class CustomFrameViewAshTest : public test::AshTestBase { 99 class CustomFrameViewAshTest : public test::AshTestBase {
99 public: 100 public:
100 CustomFrameViewAshTest() {} 101 CustomFrameViewAshTest() {}
101 ~CustomFrameViewAshTest() override {} 102 ~CustomFrameViewAshTest() override {}
102 103
103 protected: 104 protected:
104 scoped_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) { 105 std::unique_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) {
105 scoped_ptr<views::Widget> widget(new views::Widget); 106 std::unique_ptr<views::Widget> widget(new views::Widget);
106 views::Widget::InitParams params; 107 views::Widget::InitParams params;
107 params.delegate = delegate; 108 params.delegate = delegate;
108 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 109 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
109 params.bounds = gfx::Rect(0, 0, 100, 100); 110 params.bounds = gfx::Rect(0, 0, 100, 100);
110 params.context = CurrentContext(); 111 params.context = CurrentContext();
111 widget->Init(params); 112 widget->Init(params);
112 return widget; 113 return widget;
113 } 114 }
114 115
115 test::TestSessionStateDelegate* GetTestSessionStateDelegate() { 116 test::TestSessionStateDelegate* GetTestSessionStateDelegate() {
116 return static_cast<ash::test::TestSessionStateDelegate*>( 117 return static_cast<ash::test::TestSessionStateDelegate*>(
117 Shell::GetInstance()->session_state_delegate()); 118 Shell::GetInstance()->session_state_delegate());
118 } 119 }
119 120
120 private: 121 private:
121 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest); 122 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
122 }; 123 };
123 124
124 // Test that the height of the header is correct upon initially displaying 125 // Test that the height of the header is correct upon initially displaying
125 // the widget. 126 // the widget.
126 TEST_F(CustomFrameViewAshTest, HeaderHeight) { 127 TEST_F(CustomFrameViewAshTest, HeaderHeight) {
127 TestWidgetDelegate* delegate = new TestWidgetDelegate; 128 TestWidgetDelegate* delegate = new TestWidgetDelegate;
128 129
129 scoped_ptr<views::Widget> widget(CreateWidget(delegate)); 130 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
130 widget->Show(); 131 widget->Show();
131 132
132 // The header should have enough room for the window controls. The 133 // The header should have enough room for the window controls. The
133 // header/content separator line overlays the window controls. 134 // header/content separator line overlays the window controls.
134 EXPECT_EQ( 135 EXPECT_EQ(
135 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(), 136 GetAshLayoutSize(AshLayoutSize::NON_BROWSER_CAPTION_BUTTON).height(),
136 delegate->custom_frame_view()->GetHeaderView()->height()); 137 delegate->custom_frame_view()->GetHeaderView()->height());
137 } 138 }
138 139
139 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame 140 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
140 // sizes when the client view does not specify any size constraints. 141 // sizes when the client view does not specify any size constraints.
141 TEST_F(CustomFrameViewAshTest, NoSizeConstraints) { 142 TEST_F(CustomFrameViewAshTest, NoSizeConstraints) {
142 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 143 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
143 scoped_ptr<views::Widget> widget(CreateWidget(delegate)); 144 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
144 145
145 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view(); 146 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
146 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize(); 147 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
147 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize(); 148 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
148 149
149 EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height()); 150 EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height());
150 151
151 // A width and height constraint of 0 denotes unbounded. 152 // A width and height constraint of 0 denotes unbounded.
152 EXPECT_EQ(0, max_frame_size.width()); 153 EXPECT_EQ(0, max_frame_size.width());
153 EXPECT_EQ(0, max_frame_size.height()); 154 EXPECT_EQ(0, max_frame_size.height());
154 } 155 }
155 156
156 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame 157 // Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
157 // sizes when the client view specifies size constraints. 158 // sizes when the client view specifies size constraints.
158 TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) { 159 TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) {
159 gfx::Size min_client_size(500, 500); 160 gfx::Size min_client_size(500, 500);
160 gfx::Size max_client_size(800, 800); 161 gfx::Size max_client_size(800, 800);
161 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 162 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
162 delegate->set_minimum_size(min_client_size); 163 delegate->set_minimum_size(min_client_size);
163 delegate->set_maximum_size(max_client_size); 164 delegate->set_maximum_size(max_client_size);
164 scoped_ptr<views::Widget> widget(CreateWidget(delegate)); 165 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
165 166
166 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view(); 167 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
167 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize(); 168 gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
168 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize(); 169 gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
169 170
170 EXPECT_EQ(min_client_size.width(), min_frame_size.width()); 171 EXPECT_EQ(min_client_size.width(), min_frame_size.width());
171 EXPECT_EQ(max_client_size.width(), max_frame_size.width()); 172 EXPECT_EQ(max_client_size.width(), max_frame_size.width());
172 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(), 173 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
173 min_frame_size.height()); 174 min_frame_size.height());
174 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(), 175 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
175 max_frame_size.height()); 176 max_frame_size.height());
176 } 177 }
177 178
178 // Verify that CustomFrameViewAsh updates the avatar icon based on the 179 // Verify that CustomFrameViewAsh updates the avatar icon based on the
179 // state of the SessionStateDelegate after visibility change. 180 // state of the SessionStateDelegate after visibility change.
180 TEST_F(CustomFrameViewAshTest, AvatarIcon) { 181 TEST_F(CustomFrameViewAshTest, AvatarIcon) {
181 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 182 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
182 scoped_ptr<views::Widget> widget(CreateWidget(delegate)); 183 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
183 184
184 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view(); 185 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
185 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest()); 186 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
186 187
187 // Avatar image becomes available. 188 // Avatar image becomes available.
188 const gfx::ImageSkia user_image = 189 const gfx::ImageSkia user_image =
189 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 190 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
190 IDR_AURA_UBER_TRAY_GUEST_ICON); 191 IDR_AURA_UBER_TRAY_GUEST_ICON);
191 GetTestSessionStateDelegate()->SetUserImage(user_image); 192 GetTestSessionStateDelegate()->SetUserImage(user_image);
192 widget->Hide(); 193 widget->Hide();
193 widget->Show(); 194 widget->Show();
194 EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest()); 195 EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest());
195 196
196 // Avatar image is gone; the ImageView for the avatar icon should be 197 // Avatar image is gone; the ImageView for the avatar icon should be
197 // removed. 198 // removed.
198 GetTestSessionStateDelegate()->SetUserImage(gfx::ImageSkia()); 199 GetTestSessionStateDelegate()->SetUserImage(gfx::ImageSkia());
199 widget->Hide(); 200 widget->Hide();
200 widget->Show(); 201 widget->Show();
201 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest()); 202 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
202 } 203 }
203 204
204 // The visibility of the size button is updated when maximize mode is toggled. 205 // 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 // Verify that the layout of the HeaderView is updated for the size button's
206 // new visibility. 207 // new visibility.
207 TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) { 208 TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) {
208 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 209 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
209 scoped_ptr<views::Widget> widget(CreateWidget(delegate)); 210 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
210 211
211 const gfx::Rect initial = delegate-> 212 const gfx::Rect initial = delegate->
212 GetFrameCaptionButtonContainerViewBounds(); 213 GetFrameCaptionButtonContainerViewBounds();
213 Shell::GetInstance()->maximize_mode_controller()-> 214 Shell::GetInstance()->maximize_mode_controller()->
214 EnableMaximizeModeWindowManager(true); 215 EnableMaximizeModeWindowManager(true);
215 delegate->EndFrameCaptionButtonContainerViewAnimations(); 216 delegate->EndFrameCaptionButtonContainerViewAnimations();
216 const gfx::Rect maximize_mode_bounds = delegate-> 217 const gfx::Rect maximize_mode_bounds = delegate->
217 GetFrameCaptionButtonContainerViewBounds(); 218 GetFrameCaptionButtonContainerViewBounds();
218 EXPECT_GT(initial.width(), maximize_mode_bounds.width()); 219 EXPECT_GT(initial.width(), maximize_mode_bounds.width());
219 Shell::GetInstance()->maximize_mode_controller()-> 220 Shell::GetInstance()->maximize_mode_controller()->
220 EnableMaximizeModeWindowManager(false); 221 EnableMaximizeModeWindowManager(false);
221 delegate->EndFrameCaptionButtonContainerViewAnimations(); 222 delegate->EndFrameCaptionButtonContainerViewAnimations();
222 const gfx::Rect after_restore = delegate-> 223 const gfx::Rect after_restore = delegate->
223 GetFrameCaptionButtonContainerViewBounds(); 224 GetFrameCaptionButtonContainerViewBounds();
224 EXPECT_EQ(initial, after_restore); 225 EXPECT_EQ(initial, after_restore);
225 } 226 }
226 227
227 } // namespace ash 228 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/custom_frame_view_ash.cc ('k') | ash/frame/default_header_painter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698