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

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

Issue 2910773002: cros: CustomFrameViewAsh avatar icon from a window prop (Closed)
Patch Set: add test Created 3 years, 6 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/header_view.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> 7 #include <memory>
8 8
9 #include "ash/ash_layout_constants.h" 9 #include "ash/ash_layout_constants.h"
10 #include "ash/frame/caption_buttons/frame_caption_button.h" 10 #include "ash/frame/caption_buttons/frame_caption_button.h"
11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/test_session_state_delegate.h"
16 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 15 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
16 #include "ui/aura/client/aura_constants.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/image/image_skia.h" 18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/image/image_unittest_util.h" 19 #include "ui/gfx/image/image_unittest_util.h"
20 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
21 #include "ui/views/widget/widget_delegate.h" 21 #include "ui/views/widget/widget_delegate.h"
22 22
23 namespace ash { 23 namespace ash {
24 24
25 // A views::WidgetDelegate which uses a CustomFrameViewAsh. 25 // A views::WidgetDelegate which uses a CustomFrameViewAsh.
26 class TestWidgetDelegate : public views::WidgetDelegateView { 26 class TestWidgetDelegate : public views::WidgetDelegateView {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 std::unique_ptr<views::Widget> widget(new views::Widget); 101 std::unique_ptr<views::Widget> widget(new views::Widget);
102 views::Widget::InitParams params; 102 views::Widget::InitParams params;
103 params.delegate = delegate; 103 params.delegate = delegate;
104 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 104 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
105 params.bounds = gfx::Rect(0, 0, 100, 100); 105 params.bounds = gfx::Rect(0, 0, 100, 100);
106 params.context = CurrentContext(); 106 params.context = CurrentContext();
107 widget->Init(params); 107 widget->Init(params);
108 return widget; 108 return widget;
109 } 109 }
110 110
111 test::TestSessionStateDelegate* GetTestSessionStateDelegate() {
112 return static_cast<test::TestSessionStateDelegate*>(
113 ShellPort::Get()->GetSessionStateDelegate());
114 }
115
116 private: 111 private:
117 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest); 112 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
118 }; 113 };
119 114
120 // Verifies the client view is not placed at a y location of 0. 115 // Verifies the client view is not placed at a y location of 0.
121 TEST_F(CustomFrameViewAshTest, ClientViewCorrectlyPlaced) { 116 TEST_F(CustomFrameViewAshTest, ClientViewCorrectlyPlaced) {
122 std::unique_ptr<views::Widget> widget(CreateWidget(new TestWidgetDelegate)); 117 std::unique_ptr<views::Widget> widget(CreateWidget(new TestWidgetDelegate));
123 widget->Show(); 118 widget->Show();
124 EXPECT_NE(0, widget->client_view()->bounds().y()); 119 EXPECT_NE(0, widget->client_view()->bounds().y());
125 } 120 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 167
173 EXPECT_EQ(min_client_size.width(), min_frame_size.width()); 168 EXPECT_EQ(min_client_size.width(), min_frame_size.width());
174 EXPECT_EQ(max_client_size.width(), max_frame_size.width()); 169 EXPECT_EQ(max_client_size.width(), max_frame_size.width());
175 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(), 170 EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
176 min_frame_size.height()); 171 min_frame_size.height());
177 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(), 172 EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
178 max_frame_size.height()); 173 max_frame_size.height());
179 } 174 }
180 175
181 // Verify that CustomFrameViewAsh updates the avatar icon based on the 176 // Verify that CustomFrameViewAsh updates the avatar icon based on the
182 // state of the SessionStateDelegate after visibility change. 177 // avatar icon window property.
183 TEST_F(CustomFrameViewAshTest, AvatarIcon) { 178 TEST_F(CustomFrameViewAshTest, AvatarIcon) {
184 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 179 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
185 std::unique_ptr<views::Widget> widget(CreateWidget(delegate)); 180 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
186 181
187 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view(); 182 CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
188 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest()); 183 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
189 184
190 // Avatar image becomes available. 185 // Avatar image becomes available.
191 GetTestSessionStateDelegate()->SetUserImage( 186 widget->GetNativeWindow()->SetProperty(
192 gfx::test::CreateImage(27, 27).AsImageSkia()); 187 aura::client::kAvatarIconKey,
193 widget->Hide(); 188 new gfx::ImageSkia(gfx::test::CreateImage(27, 27).AsImageSkia()));
194 widget->Show();
195 EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest()); 189 EXPECT_TRUE(custom_frame_view->GetAvatarIconViewForTest());
196 190
197 // Avatar image is gone; the ImageView for the avatar icon should be 191 // Avatar image is gone; the ImageView for the avatar icon should be
198 // removed. 192 // removed.
199 GetTestSessionStateDelegate()->SetUserImage(gfx::ImageSkia()); 193 widget->GetNativeWindow()->ClearProperty(aura::client::kAvatarIconKey);
200 widget->Hide();
201 widget->Show();
202 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest()); 194 EXPECT_FALSE(custom_frame_view->GetAvatarIconViewForTest());
203 } 195 }
204 196
205 // The visibility of the size button is updated when maximize mode is toggled. 197 // The visibility of the size button is updated when maximize mode is toggled.
206 // Verify that the layout of the HeaderView is updated for the size button's 198 // Verify that the layout of the HeaderView is updated for the size button's
207 // new visibility. 199 // new visibility.
208 TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) { 200 TEST_F(CustomFrameViewAshTest, HeaderViewNotifiedOfChildSizeChange) {
209 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate; 201 TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
210 std::unique_ptr<views::Widget> widget(CreateWidget(delegate)); 202 std::unique_ptr<views::Widget> widget(CreateWidget(delegate));
211 203
212 const gfx::Rect initial = 204 const gfx::Rect initial =
213 delegate->GetFrameCaptionButtonContainerViewBounds(); 205 delegate->GetFrameCaptionButtonContainerViewBounds();
214 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 206 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
215 true); 207 true);
216 delegate->EndFrameCaptionButtonContainerViewAnimations(); 208 delegate->EndFrameCaptionButtonContainerViewAnimations();
217 const gfx::Rect maximize_mode_bounds = 209 const gfx::Rect maximize_mode_bounds =
218 delegate->GetFrameCaptionButtonContainerViewBounds(); 210 delegate->GetFrameCaptionButtonContainerViewBounds();
219 EXPECT_GT(initial.width(), maximize_mode_bounds.width()); 211 EXPECT_GT(initial.width(), maximize_mode_bounds.width());
220 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 212 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager(
221 false); 213 false);
222 delegate->EndFrameCaptionButtonContainerViewAnimations(); 214 delegate->EndFrameCaptionButtonContainerViewAnimations();
223 const gfx::Rect after_restore = 215 const gfx::Rect after_restore =
224 delegate->GetFrameCaptionButtonContainerViewBounds(); 216 delegate->GetFrameCaptionButtonContainerViewBounds();
225 EXPECT_EQ(initial, after_restore); 217 EXPECT_EQ(initial, after_restore);
226 } 218 }
227 219
228 } // namespace ash 220 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/custom_frame_view_ash.cc ('k') | ash/frame/header_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698