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/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include <cmath> | |
8 #include <cstdlib> | |
9 | |
10 #include "ash/ash_switches.h" | |
11 #include "ash/desktop_background/desktop_background_controller_observer.h" | |
7 #include "ash/desktop_background/desktop_background_widget_controller.h" | 12 #include "ash/desktop_background/desktop_background_widget_controller.h" |
8 #include "ash/shell.h" | 13 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
16 #include "ash/test/display_manager_test_api.h" | |
17 #include "base/command_line.h" | |
18 #include "base/file_util.h" | |
19 #include "base/files/file_path.h" | |
20 #include "base/files/scoped_temp_dir.h" | |
21 #include "base/message_loop/message_loop.h" | |
22 #include "content/public/test/test_browser_thread.h" | |
23 #include "third_party/skia/include/core/SkBitmap.h" | |
24 #include "third_party/skia/include/core/SkColor.h" | |
11 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
13 #include "ui/compositor/test/layer_animator_test_controller.h" | 27 #include "ui/compositor/test/layer_animator_test_controller.h" |
28 #include "ui/gfx/codec/jpeg_codec.h" | |
14 | 29 |
15 using aura::RootWindow; | 30 using aura::RootWindow; |
16 using aura::Window; | 31 using aura::Window; |
17 | 32 |
33 namespace ash { | |
34 namespace internal { | |
35 | |
18 namespace { | 36 namespace { |
19 | 37 |
20 // Containers IDs used for tests. | 38 // Containers IDs used for tests. |
21 const int kDesktopBackgroundId = | 39 const int kDesktopBackgroundId = |
22 ash::internal::kShellWindowId_DesktopBackgroundContainer; | 40 ash::internal::kShellWindowId_DesktopBackgroundContainer; |
23 const int kLockScreenBackgroundId = | 41 const int kLockScreenBackgroundId = |
24 ash::internal::kShellWindowId_LockScreenBackgroundContainer; | 42 ash::internal::kShellWindowId_LockScreenBackgroundContainer; |
25 | 43 |
26 // Returns number of child windows in a shell window container. | 44 // Returns number of child windows in a shell window container. |
27 int ChildCountForContainer(int container_id) { | 45 int ChildCountForContainer(int container_id) { |
28 RootWindow* root = ash::Shell::GetPrimaryRootWindow(); | 46 RootWindow* root = ash::Shell::GetPrimaryRootWindow(); |
29 Window* container = root->GetChildById(container_id); | 47 Window* container = root->GetChildById(container_id); |
30 return static_cast<int>(container->children().size()); | 48 return static_cast<int>(container->children().size()); |
31 } | 49 } |
32 | 50 |
51 class TestObserver : public DesktopBackgroundControllerObserver { | |
52 public: | |
53 explicit TestObserver(DesktopBackgroundController* controller) | |
54 : controller_(controller) { | |
55 DCHECK(controller_); | |
56 controller_->AddObserver(this); | |
57 } | |
58 | |
59 virtual ~TestObserver() { | |
60 controller_->RemoveObserver(this); | |
61 } | |
62 | |
63 void WaitForWallpaperDataChanged() { | |
64 base::MessageLoop::current()->Run(); | |
65 } | |
66 | |
67 // DesktopBackgroundControllerObserver overrides: | |
68 virtual void OnWallpaperDataChanged() OVERRIDE { | |
69 base::MessageLoop::current()->Quit(); | |
70 } | |
71 | |
72 private: | |
73 DesktopBackgroundController* controller_; | |
74 }; | |
75 | |
33 // Steps a widget's layer animation until it is completed. Animations must be | 76 // Steps a widget's layer animation until it is completed. Animations must be |
34 // enabled. | 77 // enabled. |
35 void RunAnimationForWidget(views::Widget* widget) { | 78 void RunAnimationForWidget(views::Widget* widget) { |
36 // Animations must be enabled for stepping to work. | 79 // Animations must be enabled for stepping to work. |
37 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), | 80 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), |
38 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 81 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
39 | 82 |
40 ui::Layer* layer = widget->GetNativeView()->layer(); | 83 ui::Layer* layer = widget->GetNativeView()->layer(); |
41 ui::LayerAnimatorTestController controller(layer->GetAnimator()); | 84 ui::LayerAnimatorTestController controller(layer->GetAnimator()); |
42 ui::AnimationContainerElement* element = layer->GetAnimator(); | 85 ui::AnimationContainerElement* element = layer->GetAnimator(); |
43 // Multiple steps are required to complete complex animations. | 86 // Multiple steps are required to complete complex animations. |
44 // TODO(vollick): This should not be necessary. crbug.com/154017 | 87 // TODO(vollick): This should not be necessary. crbug.com/154017 |
45 while (controller.animator()->is_animating()) { | 88 while (controller.animator()->is_animating()) { |
46 controller.StartThreadedAnimationsIfNeeded(); | 89 controller.StartThreadedAnimationsIfNeeded(); |
47 base::TimeTicks step_time = controller.animator()->last_step_time(); | 90 base::TimeTicks step_time = controller.animator()->last_step_time(); |
48 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); | 91 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); |
49 } | 92 } |
50 } | 93 } |
51 | 94 |
52 } // namespace | 95 } // namespace |
53 | 96 |
54 namespace ash { | |
55 namespace internal { | |
56 | |
57 class DesktopBackgroundControllerTest : public test::AshTestBase { | 97 class DesktopBackgroundControllerTest : public test::AshTestBase { |
58 public: | 98 public: |
59 DesktopBackgroundControllerTest() {} | 99 DesktopBackgroundControllerTest() |
100 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()) { | |
101 } | |
60 virtual ~DesktopBackgroundControllerTest() {} | 102 virtual ~DesktopBackgroundControllerTest() {} |
61 | 103 |
62 virtual void SetUp() OVERRIDE { | 104 virtual void SetUp() OVERRIDE { |
63 test::AshTestBase::SetUp(); | 105 test::AshTestBase::SetUp(); |
64 // Ash shell initialization creates wallpaper. Reset it so we can manually | 106 // Ash shell initialization creates wallpaper. Reset it so we can manually |
65 // control wallpaper creation and animation in our tests. | 107 // control wallpaper creation and animation in our tests. |
66 RootWindow* root = Shell::GetPrimaryRootWindow(); | 108 RootWindow* root = Shell::GetPrimaryRootWindow(); |
67 root->SetProperty(kDesktopController, | 109 root->SetProperty(kDesktopController, |
68 static_cast<DesktopBackgroundWidgetController*>(NULL)); | 110 static_cast<DesktopBackgroundWidgetController*>(NULL)); |
69 root->SetProperty(kAnimatingDesktopController, | 111 root->SetProperty(kAnimatingDesktopController, |
70 static_cast<AnimatingDesktopController*>(NULL)); | 112 static_cast<AnimatingDesktopController*>(NULL)); |
71 } | 113 } |
72 | 114 |
115 protected: | |
116 // Runs kAnimatingDesktopController's animation to completion. | |
117 // TODO(bshe): Don't require tests to run animations; it's slow. | |
118 void RunDesktopControllerAnimation() { | |
119 RootWindow* root = Shell::GetPrimaryRootWindow(); | |
120 DesktopBackgroundWidgetController* controller = | |
121 root->GetProperty(kAnimatingDesktopController)->GetController(false); | |
122 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | |
123 } | |
124 | |
125 // Returns true if |image|'s color at (0, 0) is close to |expected_color|. | |
126 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { | |
127 if (image.size().IsEmpty()) { | |
128 LOG(ERROR) << "Image is empty"; | |
129 return false; | |
130 } | |
131 | |
132 const SkBitmap* bitmap = image.bitmap(); | |
133 if (!bitmap) { | |
134 LOG(ERROR) << "Unable to get bitmap from image"; | |
135 return false; | |
136 } | |
137 | |
138 bitmap->lockPixels(); | |
139 SkColor image_color = bitmap->getColor(0, 0); | |
140 bitmap->unlockPixels(); | |
141 | |
142 const int kDiff = 3; | |
143 if (std::abs(static_cast<int>(SkColorGetA(image_color)) - | |
144 static_cast<int>(SkColorGetA(expected_color))) > kDiff || | |
145 std::abs(static_cast<int>(SkColorGetR(image_color)) - | |
146 static_cast<int>(SkColorGetR(expected_color))) > kDiff || | |
147 std::abs(static_cast<int>(SkColorGetG(image_color)) - | |
148 static_cast<int>(SkColorGetG(expected_color))) > kDiff || | |
149 std::abs(static_cast<int>(SkColorGetB(image_color)) - | |
150 static_cast<int>(SkColorGetB(expected_color))) > kDiff) { | |
151 LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color | |
152 << " but got 0x" << image_color; | |
153 return false; | |
154 } | |
155 | |
156 return true; | |
157 } | |
158 | |
159 // Writes a JPEG image of the specified size and color to |path|. Returns | |
160 // true on success. | |
161 bool WriteJPEGFile(const base::FilePath& path, | |
162 int width, | |
163 int height, | |
164 SkColor color) { | |
165 SkBitmap bitmap; | |
166 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); | |
167 bitmap.allocPixels(); | |
168 bitmap.eraseColor(color); | |
169 | |
170 const int kQuality = 80; | |
171 std::vector<unsigned char> output; | |
172 if (!gfx::JPEGCodec::Encode( | |
173 static_cast<const unsigned char*>(bitmap.getPixels()), | |
174 gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(), | |
175 kQuality, &output)) { | |
176 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; | |
177 return false; | |
178 } | |
179 | |
180 size_t bytes_written = file_util::WriteFile( | |
181 path, reinterpret_cast<const char*>(&output[0]), output.size()); | |
182 if (bytes_written != output.size()) { | |
183 LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " | |
184 << output.size() << " to " << path.value(); | |
185 return false; | |
186 } | |
187 | |
188 return true; | |
189 } | |
190 | |
73 private: | 191 private: |
192 content::TestBrowserThread ui_thread_; | |
193 | |
74 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); | 194 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); |
75 }; | 195 }; |
76 | 196 |
77 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { | 197 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { |
78 DesktopBackgroundController* controller = | 198 DesktopBackgroundController* controller = |
79 Shell::GetInstance()->desktop_background_controller(); | 199 Shell::GetInstance()->desktop_background_controller(); |
80 controller->CreateEmptyWallpaper(); | 200 controller->CreateEmptyWallpaper(); |
81 | 201 |
82 // Wallpaper view/window exists in the desktop background container and | 202 // Wallpaper view/window exists in the desktop background container and |
83 // nothing is in the lock screen background container. | 203 // nothing is in the lock screen background container. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 // holds the widget controller instance. kDesktopController will get it later. | 236 // holds the widget controller instance. kDesktopController will get it later. |
117 RootWindow* root = Shell::GetPrimaryRootWindow(); | 237 RootWindow* root = Shell::GetPrimaryRootWindow(); |
118 EXPECT_TRUE( | 238 EXPECT_TRUE( |
119 root->GetProperty(kAnimatingDesktopController)->GetController(false)); | 239 root->GetProperty(kAnimatingDesktopController)->GetController(false)); |
120 | 240 |
121 // kDesktopController will receive the widget controller when the animation | 241 // kDesktopController will receive the widget controller when the animation |
122 // is done. | 242 // is done. |
123 EXPECT_FALSE(root->GetProperty(kDesktopController)); | 243 EXPECT_FALSE(root->GetProperty(kDesktopController)); |
124 | 244 |
125 // Force the widget's layer animation to play to completion. | 245 // Force the widget's layer animation to play to completion. |
126 ASSERT_NO_FATAL_FAILURE( | 246 RunDesktopControllerAnimation(); |
127 RunAnimationForWidget( | |
128 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> | |
129 widget())); | |
130 | 247 |
131 // Ownership has moved from kAnimatingDesktopController to kDesktopController. | 248 // Ownership has moved from kAnimatingDesktopController to kDesktopController. |
132 EXPECT_FALSE( | 249 EXPECT_FALSE( |
133 root->GetProperty(kAnimatingDesktopController)->GetController(false)); | 250 root->GetProperty(kAnimatingDesktopController)->GetController(false)); |
134 EXPECT_TRUE(root->GetProperty(kDesktopController)); | 251 EXPECT_TRUE(root->GetProperty(kDesktopController)); |
135 } | 252 } |
136 | 253 |
137 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we | 254 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we |
138 // move all desktop views if there are more than one. | 255 // move all desktop views if there are more than one. |
139 TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { | 256 TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { |
140 // We cannot short-circuit animations for this test. | 257 // We cannot short-circuit animations for this test. |
141 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 258 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
142 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 259 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
143 | 260 |
144 // Reset wallpaper state, see ControllerOwnership above. | 261 // Reset wallpaper state, see ControllerOwnership above. |
145 DesktopBackgroundController* controller = | 262 DesktopBackgroundController* controller = |
146 Shell::GetInstance()->desktop_background_controller(); | 263 Shell::GetInstance()->desktop_background_controller(); |
147 controller->CreateEmptyWallpaper(); | 264 controller->CreateEmptyWallpaper(); |
148 | 265 |
149 // Run wallpaper show animation to completion. | 266 // Run wallpaper show animation to completion. |
150 RootWindow* root = Shell::GetPrimaryRootWindow(); | 267 RunDesktopControllerAnimation(); |
151 ASSERT_NO_FATAL_FAILURE( | |
152 RunAnimationForWidget( | |
153 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> | |
154 widget())); | |
155 | 268 |
156 // User locks the screen, which moves the background forward. | 269 // User locks the screen, which moves the background forward. |
157 controller->MoveDesktopToLockedContainer(); | 270 controller->MoveDesktopToLockedContainer(); |
158 | 271 |
159 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop | 272 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop |
160 // background that will animate in on top of the old one. | 273 // background that will animate in on top of the old one. |
161 controller->CreateEmptyWallpaper(); | 274 controller->CreateEmptyWallpaper(); |
162 | 275 |
163 // In this state we have two desktop background views stored in different | 276 // In this state we have two desktop background views stored in different |
164 // properties. Both are in the lock screen background container. | 277 // properties. Both are in the lock screen background container. |
278 RootWindow* root = Shell::GetPrimaryRootWindow(); | |
165 EXPECT_TRUE( | 279 EXPECT_TRUE( |
166 root->GetProperty(kAnimatingDesktopController)->GetController(false)); | 280 root->GetProperty(kAnimatingDesktopController)->GetController(false)); |
167 EXPECT_TRUE(root->GetProperty(kDesktopController)); | 281 EXPECT_TRUE(root->GetProperty(kDesktopController)); |
168 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); | 282 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); |
169 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); | 283 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); |
170 | 284 |
171 // Before the wallpaper's animation completes, user unlocks the screen, which | 285 // Before the wallpaper's animation completes, user unlocks the screen, which |
172 // moves the desktop to the back. | 286 // moves the desktop to the back. |
173 controller->MoveDesktopToUnlockedContainer(); | 287 controller->MoveDesktopToUnlockedContainer(); |
174 | 288 |
175 // Ensure both desktop backgrounds have moved. | 289 // Ensure both desktop backgrounds have moved. |
176 EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); | 290 EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); |
177 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 291 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); |
178 | 292 |
179 // Finish the new desktop background animation. | 293 // Finish the new desktop background animation. |
180 ASSERT_NO_FATAL_FAILURE( | 294 RunDesktopControllerAnimation(); |
181 RunAnimationForWidget( | |
182 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> | |
183 widget())); | |
184 | 295 |
185 // Now there is one desktop background, in the back. | 296 // Now there is one desktop background, in the back. |
186 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); | 297 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); |
187 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); | 298 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); |
188 } | 299 } |
189 | 300 |
190 // Test for crbug.com/156542. Animating wallpaper should immediately finish | 301 // Test for crbug.com/156542. Animating wallpaper should immediately finish |
191 // animation and replace current wallpaper before next animation starts. | 302 // animation and replace current wallpaper before next animation starts. |
192 TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { | 303 TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { |
193 // We cannot short-circuit animations for this test. | 304 // We cannot short-circuit animations for this test. |
194 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 305 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
195 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 306 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
196 | 307 |
197 // Reset wallpaper state, see ControllerOwnership above. | 308 // Reset wallpaper state, see ControllerOwnership above. |
198 DesktopBackgroundController* controller = | 309 DesktopBackgroundController* controller = |
199 Shell::GetInstance()->desktop_background_controller(); | 310 Shell::GetInstance()->desktop_background_controller(); |
200 controller->CreateEmptyWallpaper(); | 311 controller->CreateEmptyWallpaper(); |
201 | 312 |
202 // Run wallpaper show animation to completion. | 313 // Run wallpaper show animation to completion. |
203 RootWindow* root = Shell::GetPrimaryRootWindow(); | 314 RunDesktopControllerAnimation(); |
204 ASSERT_NO_FATAL_FAILURE( | |
205 RunAnimationForWidget( | |
206 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> | |
207 widget())); | |
208 | 315 |
209 // Change to a new wallpaper. | 316 // Change to a new wallpaper. |
210 controller->CreateEmptyWallpaper(); | 317 controller->CreateEmptyWallpaper(); |
211 | 318 |
212 DesktopBackgroundWidgetController* animatingController = | 319 RootWindow* root = Shell::GetPrimaryRootWindow(); |
320 DesktopBackgroundWidgetController* animating_controller = | |
213 root->GetProperty(kAnimatingDesktopController)->GetController(false); | 321 root->GetProperty(kAnimatingDesktopController)->GetController(false); |
214 EXPECT_TRUE(animatingController); | 322 EXPECT_TRUE(animating_controller); |
215 EXPECT_TRUE(root->GetProperty(kDesktopController)); | 323 EXPECT_TRUE(root->GetProperty(kDesktopController)); |
216 | 324 |
217 // Change to another wallpaper before animation finished. | 325 // Change to another wallpaper before animation finished. |
218 controller->CreateEmptyWallpaper(); | 326 controller->CreateEmptyWallpaper(); |
219 | 327 |
220 // The animating controller should immediately move to desktop controller. | 328 // The animating controller should immediately move to desktop controller. |
221 EXPECT_EQ(animatingController, root->GetProperty(kDesktopController)); | 329 EXPECT_EQ(animating_controller, root->GetProperty(kDesktopController)); |
222 | 330 |
223 // Cache the new animating controller. | 331 // Cache the new animating controller. |
224 animatingController = | 332 animating_controller = |
225 root->GetProperty(kAnimatingDesktopController)->GetController(false); | 333 root->GetProperty(kAnimatingDesktopController)->GetController(false); |
226 | 334 |
227 // Run wallpaper show animation to completion. | 335 // Run wallpaper show animation to completion. |
228 ASSERT_NO_FATAL_FAILURE( | 336 ASSERT_NO_FATAL_FAILURE( |
229 RunAnimationForWidget( | 337 RunAnimationForWidget( |
230 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> | 338 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> |
231 widget())); | 339 widget())); |
232 | 340 |
233 EXPECT_TRUE(root->GetProperty(kDesktopController)); | 341 EXPECT_TRUE(root->GetProperty(kDesktopController)); |
234 EXPECT_FALSE( | 342 EXPECT_FALSE( |
235 root->GetProperty(kAnimatingDesktopController)->GetController(false)); | 343 root->GetProperty(kAnimatingDesktopController)->GetController(false)); |
236 // The desktop controller should be the last created animating controller. | 344 // The desktop controller should be the last created animating controller. |
237 EXPECT_EQ(animatingController, root->GetProperty(kDesktopController)); | 345 EXPECT_EQ(animating_controller, root->GetProperty(kDesktopController)); |
346 } | |
347 | |
348 // Tests that SetDefaultWallpaper() loads default wallpaper from disk when | |
349 // instructed to do so via command-line flags. | |
350 TEST_F(DesktopBackgroundControllerTest, SetDefaultWallpaper) { | |
351 // We cannot short-circuit animations for this test. | |
352 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | |
353 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
354 | |
355 DesktopBackgroundController* controller = | |
356 Shell::GetInstance()->desktop_background_controller(); | |
357 TestObserver observer(controller); | |
358 | |
359 base::ScopedTempDir temp_dir; | |
360 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
361 | |
362 const base::FilePath kLargePath = | |
363 temp_dir.path().Append(FILE_PATH_LITERAL("large.jpg")); | |
364 const SkColor kLargeColor = SK_ColorRED; | |
365 ASSERT_TRUE(WriteJPEGFile(kLargePath, kLargeWallpaperMaxWidth, | |
366 kLargeWallpaperMaxHeight, kLargeColor)); | |
367 | |
368 const base::FilePath kSmallPath = | |
369 temp_dir.path().Append(FILE_PATH_LITERAL("small.jpg")); | |
370 const SkColor kSmallColor = SK_ColorGREEN; | |
371 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kSmallWallpaperMaxWidth, | |
372 kSmallWallpaperMaxHeight, kSmallColor)); | |
373 | |
374 const base::FilePath kLargeGuestPath = | |
375 temp_dir.path().Append(FILE_PATH_LITERAL("guest_large.jpg")); | |
376 const SkColor kLargeGuestColor = SK_ColorBLUE; | |
377 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kLargeWallpaperMaxWidth, | |
378 kLargeWallpaperMaxHeight, kLargeGuestColor)); | |
379 | |
380 const base::FilePath kSmallGuestPath = | |
381 temp_dir.path().Append(FILE_PATH_LITERAL("guest_small.jpg")); | |
382 const SkColor kSmallGuestColor = SK_ColorYELLOW; | |
383 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kSmallWallpaperMaxWidth, | |
384 kSmallWallpaperMaxHeight, kSmallGuestColor)); | |
385 | |
386 CommandLine command_line(CommandLine::NO_PROGRAM); | |
387 command_line.AppendSwitchPath( | |
388 switches::kAshDefaultWallpaperLarge, kLargePath); | |
389 command_line.AppendSwitchPath( | |
390 switches::kAshDefaultWallpaperSmall, kSmallPath); | |
391 command_line.AppendSwitchPath( | |
392 switches::kAshDefaultGuestWallpaperLarge, kLargeGuestPath); | |
393 command_line.AppendSwitchPath( | |
394 switches::kAshDefaultGuestWallpaperSmall, kSmallGuestPath); | |
395 controller->set_command_line_for_testing(&command_line); | |
396 | |
397 // At 800x600, the small wallpaper should be loaded. | |
398 test::DisplayManagerTestApi display_manager_test_api( | |
399 Shell::GetInstance()->display_manager()); | |
400 display_manager_test_api.UpdateDisplay("800x600"); | |
401 ASSERT_TRUE(controller->SetDefaultWallpaper(false)); | |
402 observer.WaitForWallpaperDataChanged(); | |
403 RunDesktopControllerAnimation(); | |
404 EXPECT_TRUE(ImageIsNearColor(controller->GetWallpaper(), kSmallColor)); | |
405 | |
406 // Requesting the same wallpaper again should be a no-op. | |
407 EXPECT_FALSE(controller->SetDefaultWallpaper(false)); | |
408 | |
409 // It should still be a no-op after adding a second small display (i.e. | |
410 // the controller should continue using the same wallpaper). | |
411 display_manager_test_api.UpdateDisplay("800x600,800x600"); | |
412 EXPECT_FALSE(controller->SetDefaultWallpaper(false)); | |
413 | |
414 // Switch to guest mode and check that the small guest wallpaper is loaded. | |
415 ASSERT_TRUE(controller->SetDefaultWallpaper(true)); | |
416 observer.WaitForWallpaperDataChanged(); | |
bshe
2013/06/21 00:43:14
Your new test if still good.
For the old test, I j
Daniel Erat
2013/06/21 00:53:31
Yeah, I noticed this too when I was updating the t
| |
417 EXPECT_TRUE(ImageIsNearColor(controller->GetWallpaper(), kSmallGuestColor)); | |
418 | |
419 // Switch to a larger display and check that the large wallpaper is loaded. | |
420 display_manager_test_api.UpdateDisplay("1600x1200"); | |
421 ASSERT_TRUE(controller->SetDefaultWallpaper(false)); | |
422 observer.WaitForWallpaperDataChanged(); | |
423 RunDesktopControllerAnimation(); | |
424 EXPECT_TRUE(ImageIsNearColor(controller->GetWallpaper(), kLargeColor)); | |
425 | |
426 // Switch to the guest wallpaper while still at a higher resolution. | |
427 ASSERT_TRUE(controller->SetDefaultWallpaper(true)); | |
428 observer.WaitForWallpaperDataChanged(); | |
429 RunDesktopControllerAnimation(); | |
430 EXPECT_TRUE(ImageIsNearColor(controller->GetWallpaper(), kLargeGuestColor)); | |
238 } | 431 } |
239 | 432 |
240 } // namespace internal | 433 } // namespace internal |
241 } // namespace ash | 434 } // namespace ash |
OLD | NEW |