OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/desktop_background/desktop_background_controller.h" | 5 #include "ash/wallpaper/wallpaper_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/desktop_background/desktop_background_view.h" | |
13 #include "ash/desktop_background/desktop_background_widget_controller.h" | |
14 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
15 #include "ash/shell.h" | 13 #include "ash/shell.h" |
16 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/test_wallpaper_delegate.h" | 15 #include "ash/test/test_wallpaper_delegate.h" |
| 16 #include "ash/wallpaper/wallpaper_view.h" |
| 17 #include "ash/wallpaper/wallpaper_widget_controller.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
22 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
23 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
25 #include "ui/compositor/test/layer_animator_test_controller.h" | 25 #include "ui/compositor/test/layer_animator_test_controller.h" |
26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
28 | 28 |
29 using wallpaper::WALLPAPER_LAYOUT_CENTER; | 29 using wallpaper::WALLPAPER_LAYOUT_CENTER; |
30 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; | 30 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; |
31 using wallpaper::WALLPAPER_LAYOUT_STRETCH; | 31 using wallpaper::WALLPAPER_LAYOUT_STRETCH; |
32 using wallpaper::WALLPAPER_LAYOUT_TILE; | 32 using wallpaper::WALLPAPER_LAYOUT_TILE; |
33 | 33 |
34 namespace ash { | 34 namespace ash { |
35 namespace { | 35 namespace { |
36 | 36 |
37 // Containers IDs used for tests. | 37 // Containers IDs used for tests. |
38 const int kDesktopBackgroundId = ash::kShellWindowId_DesktopBackgroundContainer; | 38 const int kWallpaperId = ash::kShellWindowId_WallpaperContainer; |
39 const int kLockScreenBackgroundId = | 39 const int kLockScreenWallpaperId = |
40 ash::kShellWindowId_LockScreenBackgroundContainer; | 40 ash::kShellWindowId_LockScreenWallpaperContainer; |
41 | 41 |
42 // Returns number of child windows in a shell window container. | 42 // Returns number of child windows in a shell window container. |
43 int ChildCountForContainer(int container_id) { | 43 int ChildCountForContainer(int container_id) { |
44 aura::Window* root = ash::Shell::GetPrimaryRootWindow(); | 44 aura::Window* root = ash::Shell::GetPrimaryRootWindow(); |
45 aura::Window* container = root->GetChildById(container_id); | 45 aura::Window* container = root->GetChildById(container_id); |
46 return static_cast<int>(container->children().size()); | 46 return static_cast<int>(container->children().size()); |
47 } | 47 } |
48 | 48 |
49 // Steps a widget's layer animation until it is completed. Animations must be | 49 // Steps a widget's layer animation until it is completed. Animations must be |
50 // enabled. | 50 // enabled. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
95 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); | 95 base::MessageLoop::current()->RemoveTaskObserver(&task_observer); |
96 | 96 |
97 if (!task_observer.processed()) | 97 if (!task_observer.processed()) |
98 break; | 98 break; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 class DesktopBackgroundControllerTest : public test::AshTestBase { | 104 class WallpaperControllerTest : public test::AshTestBase { |
105 public: | 105 public: |
106 DesktopBackgroundControllerTest() | 106 WallpaperControllerTest() : controller_(NULL), wallpaper_delegate_(NULL) {} |
107 : controller_(NULL), wallpaper_delegate_(NULL) {} | 107 ~WallpaperControllerTest() override {} |
108 ~DesktopBackgroundControllerTest() override {} | |
109 | 108 |
110 void SetUp() override { | 109 void SetUp() override { |
111 test::AshTestBase::SetUp(); | 110 test::AshTestBase::SetUp(); |
112 // Ash shell initialization creates wallpaper. Reset it so we can manually | 111 // Ash shell initialization creates wallpaper. Reset it so we can manually |
113 // control wallpaper creation and animation in our tests. | 112 // control wallpaper creation and animation in our tests. |
114 RootWindowController* root_window_controller = | 113 RootWindowController* root_window_controller = |
115 Shell::GetPrimaryRootWindowController(); | 114 Shell::GetPrimaryRootWindowController(); |
116 root_window_controller->SetWallpaperController(NULL); | 115 root_window_controller->SetWallpaperController(NULL); |
117 root_window_controller->SetAnimatingWallpaperController(NULL); | 116 root_window_controller->SetAnimatingWallpaperController(NULL); |
118 controller_ = Shell::GetInstance()->desktop_background_controller(); | 117 controller_ = Shell::GetInstance()->wallpaper_controller(); |
119 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( | 118 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( |
120 WmShell::Get()->wallpaper_delegate()); | 119 WmShell::Get()->wallpaper_delegate()); |
121 controller_->set_wallpaper_reload_delay_for_test(0); | 120 controller_->set_wallpaper_reload_delay_for_test(0); |
122 } | 121 } |
123 | 122 |
124 DesktopBackgroundView* desktop_background_view() { | 123 WallpaperView* wallpaper_view() { |
125 DesktopBackgroundWidgetController* controller = | 124 WallpaperWidgetController* controller = |
126 Shell::GetPrimaryRootWindowController() | 125 Shell::GetPrimaryRootWindowController() |
127 ->animating_wallpaper_controller() | 126 ->animating_wallpaper_controller() |
128 ->GetController(false); | 127 ->GetController(false); |
129 EXPECT_TRUE(controller); | 128 EXPECT_TRUE(controller); |
130 return static_cast<DesktopBackgroundView*>( | 129 return static_cast<WallpaperView*>( |
131 controller->widget()->GetContentsView()->child_at(0)); | 130 controller->widget()->GetContentsView()->child_at(0)); |
132 } | 131 } |
133 | 132 |
134 protected: | 133 protected: |
135 // A color that can be passed to CreateImage(). Specifically chosen to not | 134 // A color that can be passed to CreateImage(). Specifically chosen to not |
136 // conflict with any of the default wallpaper colors. | 135 // conflict with any of the default wallpaper colors. |
137 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; | 136 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; |
138 | 137 |
139 // Creates an image of size |size|. | 138 // Creates an image of size |size|. |
140 gfx::ImageSkia CreateImage(int width, int height, SkColor color) { | 139 gfx::ImageSkia CreateImage(int width, int height, SkColor color) { |
141 SkBitmap bitmap; | 140 SkBitmap bitmap; |
142 bitmap.allocN32Pixels(width, height); | 141 bitmap.allocN32Pixels(width, height); |
143 bitmap.eraseColor(color); | 142 bitmap.eraseColor(color); |
144 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 143 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
145 return image; | 144 return image; |
146 } | 145 } |
147 | 146 |
148 // Helper function that tests the wallpaper is always fitted to the native | 147 // Helper function that tests the wallpaper is always fitted to the native |
149 // display resolution when the layout is WALLPAPER_LAYOUT_CENTER. | 148 // display resolution when the layout is WALLPAPER_LAYOUT_CENTER. |
150 void WallpaperFitToNativeResolution(DesktopBackgroundView* view, | 149 void WallpaperFitToNativeResolution(WallpaperView* view, |
151 float device_scale_factor, | 150 float device_scale_factor, |
152 int image_width, | 151 int image_width, |
153 int image_height, | 152 int image_height, |
154 SkColor color) { | 153 SkColor color) { |
155 gfx::Size size = view->bounds().size(); | 154 gfx::Size size = view->bounds().size(); |
156 gfx::Canvas canvas(size, device_scale_factor, true); | 155 gfx::Canvas canvas(size, device_scale_factor, true); |
157 view->OnPaint(&canvas); | 156 view->OnPaint(&canvas); |
158 | 157 |
159 int canvas_width = canvas.sk_canvas()->imageInfo().width(); | 158 int canvas_width = canvas.sk_canvas()->imageInfo().width(); |
160 int canvas_height = canvas.sk_canvas()->imageInfo().height(); | 159 int canvas_height = canvas.sk_canvas()->imageInfo().height(); |
(...skipping 11 matching lines...) Expand all Loading... |
172 } else { | 171 } else { |
173 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); | 172 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); |
174 } | 173 } |
175 } | 174 } |
176 } | 175 } |
177 } | 176 } |
178 | 177 |
179 // Runs kAnimatingDesktopController's animation to completion. | 178 // Runs kAnimatingDesktopController's animation to completion. |
180 // TODO(bshe): Don't require tests to run animations; it's slow. | 179 // TODO(bshe): Don't require tests to run animations; it's slow. |
181 void RunDesktopControllerAnimation() { | 180 void RunDesktopControllerAnimation() { |
182 DesktopBackgroundWidgetController* controller = | 181 WallpaperWidgetController* controller = |
183 Shell::GetPrimaryRootWindowController() | 182 Shell::GetPrimaryRootWindowController() |
184 ->animating_wallpaper_controller() | 183 ->animating_wallpaper_controller() |
185 ->GetController(false); | 184 ->GetController(false); |
186 EXPECT_TRUE(controller); | 185 EXPECT_TRUE(controller); |
187 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 186 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
188 } | 187 } |
189 | 188 |
190 DesktopBackgroundController* controller_; // Not owned. | 189 WallpaperController* controller_; // Not owned. |
191 | 190 |
192 test::TestWallpaperDelegate* wallpaper_delegate_; | 191 test::TestWallpaperDelegate* wallpaper_delegate_; |
193 | 192 |
194 private: | 193 private: |
195 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); | 194 DISALLOW_COPY_AND_ASSIGN(WallpaperControllerTest); |
196 }; | 195 }; |
197 | 196 |
198 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { | 197 TEST_F(WallpaperControllerTest, BasicReparenting) { |
199 DesktopBackgroundController* controller = | 198 WallpaperController* controller = |
200 Shell::GetInstance()->desktop_background_controller(); | 199 Shell::GetInstance()->wallpaper_controller(); |
201 controller->CreateEmptyWallpaper(); | 200 controller->CreateEmptyWallpaper(); |
202 | 201 |
203 // Wallpaper view/window exists in the desktop background container and | 202 // Wallpaper view/window exists in the wallpaper container and nothing is in |
204 // nothing is in the lock screen background container. | 203 // the lock screen wallpaper container. |
205 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); | 204 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); |
206 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 205 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
207 | 206 |
208 // Moving background to lock container should succeed the first time but | 207 // Moving wallpaper to lock container should succeed the first time but |
209 // subsequent calls should do nothing. | 208 // subsequent calls should do nothing. |
210 EXPECT_TRUE(controller->MoveDesktopToLockedContainer()); | 209 EXPECT_TRUE(controller->MoveToLockedContainer()); |
211 EXPECT_FALSE(controller->MoveDesktopToLockedContainer()); | 210 EXPECT_FALSE(controller->MoveToLockedContainer()); |
212 | 211 |
213 // One window is moved from desktop to lock container. | 212 // One window is moved from desktop to lock container. |
214 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); | 213 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId)); |
215 EXPECT_EQ(1, ChildCountForContainer(kLockScreenBackgroundId)); | 214 EXPECT_EQ(1, ChildCountForContainer(kLockScreenWallpaperId)); |
216 | 215 |
217 // Moving background to desktop container should succeed the first time. | 216 // Moving wallpaper to desktop container should succeed the first time. |
218 EXPECT_TRUE(controller->MoveDesktopToUnlockedContainer()); | 217 EXPECT_TRUE(controller->MoveToUnlockedContainer()); |
219 EXPECT_FALSE(controller->MoveDesktopToUnlockedContainer()); | 218 EXPECT_FALSE(controller->MoveToUnlockedContainer()); |
220 | 219 |
221 // One window is moved from lock to desktop container. | 220 // One window is moved from lock to desktop container. |
222 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); | 221 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); |
223 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 222 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
224 } | 223 } |
225 | 224 |
226 TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { | 225 TEST_F(WallpaperControllerTest, ControllerOwnership) { |
227 // We cannot short-circuit animations for this test. | 226 // We cannot short-circuit animations for this test. |
228 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 227 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
229 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 228 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
230 | 229 |
231 // Create wallpaper and background view. | 230 // Create the wallpaper and its view. |
232 DesktopBackgroundController* controller = | 231 WallpaperController* controller = |
233 Shell::GetInstance()->desktop_background_controller(); | 232 Shell::GetInstance()->wallpaper_controller(); |
234 controller->CreateEmptyWallpaper(); | 233 controller->CreateEmptyWallpaper(); |
235 | 234 |
236 // The new wallpaper is ready to start animating. kAnimatingDesktopController | 235 // The new wallpaper is ready to start animating. kAnimatingDesktopController |
237 // holds the widget controller instance. kDesktopController will get it later. | 236 // holds the widget controller instance. kDesktopController will get it later. |
238 RootWindowController* root_window_controller = | 237 RootWindowController* root_window_controller = |
239 Shell::GetPrimaryRootWindowController(); | 238 Shell::GetPrimaryRootWindowController(); |
240 EXPECT_TRUE( | 239 EXPECT_TRUE( |
241 root_window_controller->animating_wallpaper_controller()->GetController( | 240 root_window_controller->animating_wallpaper_controller()->GetController( |
242 false)); | 241 false)); |
243 | 242 |
244 // kDesktopController will receive the widget controller when the animation | 243 // kDesktopController will receive the widget controller when the animation |
245 // is done. | 244 // is done. |
246 EXPECT_FALSE(root_window_controller->wallpaper_controller()); | 245 EXPECT_FALSE(root_window_controller->wallpaper_controller()); |
247 | 246 |
248 // Force the widget's layer animation to play to completion. | 247 // Force the widget's layer animation to play to completion. |
249 RunDesktopControllerAnimation(); | 248 RunDesktopControllerAnimation(); |
250 | 249 |
251 // Ownership has moved from kAnimatingDesktopController to kDesktopController. | 250 // Ownership has moved from kAnimatingDesktopController to kDesktopController. |
252 EXPECT_FALSE( | 251 EXPECT_FALSE( |
253 root_window_controller->animating_wallpaper_controller()->GetController( | 252 root_window_controller->animating_wallpaper_controller()->GetController( |
254 false)); | 253 false)); |
255 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 254 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
256 } | 255 } |
257 | 256 |
258 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we | 257 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we |
259 // move all desktop views if there are more than one. | 258 // move all wallpaper views if there are more than one. |
260 TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { | 259 TEST_F(WallpaperControllerTest, WallpaperMovementDuringUnlock) { |
261 // We cannot short-circuit animations for this test. | 260 // We cannot short-circuit animations for this test. |
262 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 261 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
263 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 262 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
264 | 263 |
265 // Reset wallpaper state, see ControllerOwnership above. | 264 // Reset wallpaper state, see ControllerOwnership above. |
266 DesktopBackgroundController* controller = | 265 WallpaperController* controller = |
267 Shell::GetInstance()->desktop_background_controller(); | 266 Shell::GetInstance()->wallpaper_controller(); |
268 controller->CreateEmptyWallpaper(); | 267 controller->CreateEmptyWallpaper(); |
269 | 268 |
270 // Run wallpaper show animation to completion. | 269 // Run wallpaper show animation to completion. |
271 RunDesktopControllerAnimation(); | 270 RunDesktopControllerAnimation(); |
272 | 271 |
273 // User locks the screen, which moves the background forward. | 272 // User locks the screen, which moves the wallpaper forward. |
274 controller->MoveDesktopToLockedContainer(); | 273 controller->MoveToLockedContainer(); |
275 | 274 |
276 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop | 275 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper |
277 // background that will animate in on top of the old one. | 276 // that will animate in on top of the old one. |
278 controller->CreateEmptyWallpaper(); | 277 controller->CreateEmptyWallpaper(); |
279 | 278 |
280 // In this state we have two desktop background views stored in different | 279 // In this state we have two wallpaper views stored in different properties. |
281 // properties. Both are in the lock screen background container. | 280 // Both are in the lock screen wallpaper container. |
282 RootWindowController* root_window_controller = | 281 RootWindowController* root_window_controller = |
283 Shell::GetPrimaryRootWindowController(); | 282 Shell::GetPrimaryRootWindowController(); |
284 EXPECT_TRUE( | 283 EXPECT_TRUE( |
285 root_window_controller->animating_wallpaper_controller()->GetController( | 284 root_window_controller->animating_wallpaper_controller()->GetController( |
286 false)); | 285 false)); |
287 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 286 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
288 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); | 287 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId)); |
289 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); | 288 EXPECT_EQ(2, ChildCountForContainer(kLockScreenWallpaperId)); |
290 | 289 |
291 // Before the wallpaper's animation completes, user unlocks the screen, which | 290 // Before the wallpaper's animation completes, user unlocks the screen, which |
292 // moves the desktop to the back. | 291 // moves the wallpaper to the back. |
293 controller->MoveDesktopToUnlockedContainer(); | 292 controller->MoveToUnlockedContainer(); |
294 | 293 |
295 // Ensure both desktop backgrounds have moved. | 294 // Ensure both wallpapers have moved. |
296 EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); | 295 EXPECT_EQ(2, ChildCountForContainer(kWallpaperId)); |
297 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 296 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
298 | 297 |
299 // Finish the new desktop background animation. | 298 // Finish the new wallpaper animation. |
300 RunDesktopControllerAnimation(); | 299 RunDesktopControllerAnimation(); |
301 | 300 |
302 // Now there is one desktop background, in the back. | 301 // Now there is one wallpaper, in the back. |
303 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); | 302 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); |
304 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 303 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
305 } | 304 } |
306 | 305 |
307 // Test for crbug.com/156542. Animating wallpaper should immediately finish | 306 // Test for crbug.com/156542. Animating wallpaper should immediately finish |
308 // animation and replace current wallpaper before next animation starts. | 307 // animation and replace current wallpaper before next animation starts. |
309 TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { | 308 TEST_F(WallpaperControllerTest, ChangeWallpaperQuick) { |
310 // We cannot short-circuit animations for this test. | 309 // We cannot short-circuit animations for this test. |
311 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 310 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
312 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 311 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
313 | 312 |
314 // Reset wallpaper state, see ControllerOwnership above. | 313 // Reset wallpaper state, see ControllerOwnership above. |
315 DesktopBackgroundController* controller = | 314 WallpaperController* controller = |
316 Shell::GetInstance()->desktop_background_controller(); | 315 Shell::GetInstance()->wallpaper_controller(); |
317 controller->CreateEmptyWallpaper(); | 316 controller->CreateEmptyWallpaper(); |
318 | 317 |
319 // Run wallpaper show animation to completion. | 318 // Run wallpaper show animation to completion. |
320 RunDesktopControllerAnimation(); | 319 RunDesktopControllerAnimation(); |
321 | 320 |
322 // Change to a new wallpaper. | 321 // Change to a new wallpaper. |
323 controller->CreateEmptyWallpaper(); | 322 controller->CreateEmptyWallpaper(); |
324 | 323 |
325 RootWindowController* root_window_controller = | 324 RootWindowController* root_window_controller = |
326 Shell::GetPrimaryRootWindowController(); | 325 Shell::GetPrimaryRootWindowController(); |
327 DesktopBackgroundWidgetController* animating_controller = | 326 WallpaperWidgetController* animating_controller = |
328 root_window_controller->animating_wallpaper_controller()->GetController( | 327 root_window_controller->animating_wallpaper_controller()->GetController( |
329 false); | 328 false); |
330 EXPECT_TRUE(animating_controller); | 329 EXPECT_TRUE(animating_controller); |
331 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 330 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
332 | 331 |
333 // Change to another wallpaper before animation finished. | 332 // Change to another wallpaper before animation finished. |
334 controller->CreateEmptyWallpaper(); | 333 controller->CreateEmptyWallpaper(); |
335 | 334 |
336 // The animating controller should immediately move to desktop controller. | 335 // The animating controller should immediately move to wallpaper controller. |
337 EXPECT_EQ(animating_controller, | 336 EXPECT_EQ(animating_controller, |
338 root_window_controller->wallpaper_controller()); | 337 root_window_controller->wallpaper_controller()); |
339 | 338 |
340 // Cache the new animating controller. | 339 // Cache the new animating controller. |
341 animating_controller = | 340 animating_controller = |
342 root_window_controller->animating_wallpaper_controller()->GetController( | 341 root_window_controller->animating_wallpaper_controller()->GetController( |
343 false); | 342 false); |
344 | 343 |
345 // Run wallpaper show animation to completion. | 344 // Run wallpaper show animation to completion. |
346 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget( | 345 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget( |
347 root_window_controller->animating_wallpaper_controller() | 346 root_window_controller->animating_wallpaper_controller() |
348 ->GetController(false) | 347 ->GetController(false) |
349 ->widget())); | 348 ->widget())); |
350 | 349 |
351 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 350 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
352 EXPECT_FALSE( | 351 EXPECT_FALSE( |
353 root_window_controller->animating_wallpaper_controller()->GetController( | 352 root_window_controller->animating_wallpaper_controller()->GetController( |
354 false)); | 353 false)); |
355 // The desktop controller should be the last created animating controller. | 354 // The wallpaper controller should be the last created animating controller. |
356 EXPECT_EQ(animating_controller, | 355 EXPECT_EQ(animating_controller, |
357 root_window_controller->wallpaper_controller()); | 356 root_window_controller->wallpaper_controller()); |
358 } | 357 } |
359 | 358 |
360 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { | 359 TEST_F(WallpaperControllerTest, ResizeCustomWallpaper) { |
361 if (!SupportsMultipleDisplays()) | 360 if (!SupportsMultipleDisplays()) |
362 return; | 361 return; |
363 | 362 |
364 UpdateDisplay("320x200"); | 363 UpdateDisplay("320x200"); |
365 | 364 |
366 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); | 365 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); |
367 | 366 |
368 // Set the image as custom wallpaper, wait for the resize to finish, and check | 367 // Set the image as custom wallpaper, wait for the resize to finish, and check |
369 // that the resized image is the expected size. | 368 // that the resized image is the expected size. |
370 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | 369 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
(...skipping 10 matching lines...) Expand all Loading... |
381 RunAllBlockingPoolTasksUntilIdle(Shell::GetInstance()->blocking_pool()); | 380 RunAllBlockingPoolTasksUntilIdle(Shell::GetInstance()->blocking_pool()); |
382 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); | 381 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
383 } | 382 } |
384 | 383 |
385 #if defined(OS_WIN) && !defined(USE_ASH) | 384 #if defined(OS_WIN) && !defined(USE_ASH) |
386 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 385 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
387 #define MAYBE_GetMaxDisplaySize DISABLED_GetMaxDisplaySize | 386 #define MAYBE_GetMaxDisplaySize DISABLED_GetMaxDisplaySize |
388 #else | 387 #else |
389 #define MAYBE_GetMaxDisplaySize GetMaxDisplaySize | 388 #define MAYBE_GetMaxDisplaySize GetMaxDisplaySize |
390 #endif | 389 #endif |
391 TEST_F(DesktopBackgroundControllerTest, MAYBE_GetMaxDisplaySize) { | 390 TEST_F(WallpaperControllerTest, MAYBE_GetMaxDisplaySize) { |
392 // Device scale factor shouldn't affect the native size. | 391 // Device scale factor shouldn't affect the native size. |
393 UpdateDisplay("1000x300*2"); | 392 UpdateDisplay("1000x300*2"); |
394 EXPECT_EQ( | 393 EXPECT_EQ("1000x300", |
395 "1000x300", | 394 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
396 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
397 | 395 |
398 // Rotated display should return the rotated size. | 396 // Rotated display should return the rotated size. |
399 UpdateDisplay("1000x300*2/r"); | 397 UpdateDisplay("1000x300*2/r"); |
400 EXPECT_EQ( | 398 EXPECT_EQ("300x1000", |
401 "300x1000", | 399 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
402 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
403 | 400 |
404 // UI Scaling shouldn't affect the native size. | 401 // UI Scaling shouldn't affect the native size. |
405 UpdateDisplay("1000x300*2@1.5"); | 402 UpdateDisplay("1000x300*2@1.5"); |
406 EXPECT_EQ( | 403 EXPECT_EQ("1000x300", |
407 "1000x300", | 404 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
408 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
409 | 405 |
410 if (!SupportsMultipleDisplays()) | 406 if (!SupportsMultipleDisplays()) |
411 return; | 407 return; |
412 | 408 |
413 // First display has maximum size. | 409 // First display has maximum size. |
414 UpdateDisplay("400x300,100x100"); | 410 UpdateDisplay("400x300,100x100"); |
415 EXPECT_EQ( | 411 EXPECT_EQ("400x300", |
416 "400x300", | 412 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
417 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
418 | 413 |
419 // Second display has maximum size. | 414 // Second display has maximum size. |
420 UpdateDisplay("400x300,500x600"); | 415 UpdateDisplay("400x300,500x600"); |
421 EXPECT_EQ( | 416 EXPECT_EQ("500x600", |
422 "500x600", | 417 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
423 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
424 | 418 |
425 // Maximum width and height belongs to different displays. | 419 // Maximum width and height belongs to different displays. |
426 UpdateDisplay("400x300,100x500"); | 420 UpdateDisplay("400x300,100x500"); |
427 EXPECT_EQ( | 421 EXPECT_EQ("400x500", |
428 "400x500", | 422 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
429 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | |
430 } | 423 } |
431 | 424 |
432 // Test that the wallpaper is always fitted to the native display resolution | 425 // Test that the wallpaper is always fitted to the native display resolution |
433 // when the layout is WALLPAPER_LAYOUT_CENTER to prevent blurry images. | 426 // when the layout is WALLPAPER_LAYOUT_CENTER to prevent blurry images. |
434 TEST_F(DesktopBackgroundControllerTest, DontScaleWallpaperWithCenterLayout) { | 427 TEST_F(WallpaperControllerTest, DontScaleWallpaperWithCenterLayout) { |
435 // We cannot short-circuit animations for this test. | 428 // We cannot short-circuit animations for this test. |
436 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 429 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
437 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 430 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
438 | 431 |
439 const gfx::Size high_resolution(3600, 2400); | 432 const gfx::Size high_resolution(3600, 2400); |
440 const gfx::Size low_resolution(360, 240); | 433 const gfx::Size low_resolution(360, 240); |
441 const float high_dsf = 2.0f; | 434 const float high_dsf = 2.0f; |
442 const float low_dsf = 1.0f; | 435 const float low_dsf = 1.0f; |
443 | 436 |
444 gfx::ImageSkia image_high_res = CreateImage( | 437 gfx::ImageSkia image_high_res = CreateImage( |
445 high_resolution.width(), high_resolution.height(), kCustomWallpaperColor); | 438 high_resolution.width(), high_resolution.height(), kCustomWallpaperColor); |
446 gfx::ImageSkia image_low_res = CreateImage( | 439 gfx::ImageSkia image_low_res = CreateImage( |
447 low_resolution.width(), low_resolution.height(), kCustomWallpaperColor); | 440 low_resolution.width(), low_resolution.height(), kCustomWallpaperColor); |
448 | 441 |
449 UpdateDisplay("1200x600*2"); | 442 UpdateDisplay("1200x600*2"); |
450 { | 443 { |
451 SCOPED_TRACE(base::StringPrintf("1200x600*2 high resolution")); | 444 SCOPED_TRACE(base::StringPrintf("1200x600*2 high resolution")); |
452 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); | 445 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); |
453 WallpaperFitToNativeResolution( | 446 WallpaperFitToNativeResolution( |
454 desktop_background_view(), high_dsf, high_resolution.width(), | 447 wallpaper_view(), high_dsf, high_resolution.width(), |
455 high_resolution.height(), kCustomWallpaperColor); | 448 high_resolution.height(), kCustomWallpaperColor); |
456 } | 449 } |
457 { | 450 { |
458 SCOPED_TRACE(base::StringPrintf("1200x600*2 low resolution")); | 451 SCOPED_TRACE(base::StringPrintf("1200x600*2 low resolution")); |
459 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); | 452 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); |
460 WallpaperFitToNativeResolution( | 453 WallpaperFitToNativeResolution( |
461 desktop_background_view(), high_dsf, low_resolution.width(), | 454 wallpaper_view(), high_dsf, low_resolution.width(), |
462 low_resolution.height(), kCustomWallpaperColor); | 455 low_resolution.height(), kCustomWallpaperColor); |
463 } | 456 } |
464 | 457 |
465 UpdateDisplay("1200x600"); | 458 UpdateDisplay("1200x600"); |
466 { | 459 { |
467 SCOPED_TRACE(base::StringPrintf("1200x600 high resolution")); | 460 SCOPED_TRACE(base::StringPrintf("1200x600 high resolution")); |
468 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); | 461 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); |
469 WallpaperFitToNativeResolution( | 462 WallpaperFitToNativeResolution( |
470 desktop_background_view(), low_dsf, high_resolution.width(), | 463 wallpaper_view(), low_dsf, high_resolution.width(), |
471 high_resolution.height(), kCustomWallpaperColor); | 464 high_resolution.height(), kCustomWallpaperColor); |
472 } | 465 } |
473 { | 466 { |
474 SCOPED_TRACE(base::StringPrintf("1200x600 low resolution")); | 467 SCOPED_TRACE(base::StringPrintf("1200x600 low resolution")); |
475 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); | 468 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); |
476 WallpaperFitToNativeResolution( | 469 WallpaperFitToNativeResolution( |
477 desktop_background_view(), low_dsf, low_resolution.width(), | 470 wallpaper_view(), low_dsf, low_resolution.width(), |
478 low_resolution.height(), kCustomWallpaperColor); | 471 low_resolution.height(), kCustomWallpaperColor); |
479 } | 472 } |
480 | 473 |
481 UpdateDisplay("1200x600/u@1.5"); // 1.5 ui scale | 474 UpdateDisplay("1200x600/u@1.5"); // 1.5 ui scale |
482 { | 475 { |
483 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 high resolution")); | 476 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 high resolution")); |
484 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); | 477 controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER); |
485 WallpaperFitToNativeResolution( | 478 WallpaperFitToNativeResolution( |
486 desktop_background_view(), low_dsf, high_resolution.width(), | 479 wallpaper_view(), low_dsf, high_resolution.width(), |
487 high_resolution.height(), kCustomWallpaperColor); | 480 high_resolution.height(), kCustomWallpaperColor); |
488 } | 481 } |
489 { | 482 { |
490 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 low resolution")); | 483 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 low resolution")); |
491 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); | 484 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); |
492 WallpaperFitToNativeResolution( | 485 WallpaperFitToNativeResolution( |
493 desktop_background_view(), low_dsf, low_resolution.width(), | 486 wallpaper_view(), low_dsf, low_resolution.width(), |
494 low_resolution.height(), kCustomWallpaperColor); | 487 low_resolution.height(), kCustomWallpaperColor); |
495 } | 488 } |
496 } | 489 } |
497 | 490 |
498 } // namespace ash | 491 } // namespace ash |
OLD | NEW |