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