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> | 7 #include <cmath> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 controller.StartThreadedAnimationsIfNeeded(); | 94 controller.StartThreadedAnimationsIfNeeded(); |
95 base::TimeTicks step_time = controller.animator()->last_step_time(); | 95 base::TimeTicks step_time = controller.animator()->last_step_time(); |
96 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); | 96 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 } // namespace | 100 } // namespace |
101 | 101 |
102 class DesktopBackgroundControllerTest : public test::AshTestBase { | 102 class DesktopBackgroundControllerTest : public test::AshTestBase { |
103 public: | 103 public: |
104 DesktopBackgroundControllerTest() | 104 DesktopBackgroundControllerTest() : controller_(NULL) {} |
105 : command_line_(CommandLine::NO_PROGRAM), | |
106 controller_(NULL) { | |
107 } | |
108 virtual ~DesktopBackgroundControllerTest() {} | 105 virtual ~DesktopBackgroundControllerTest() {} |
109 | 106 |
110 virtual void SetUp() OVERRIDE { | 107 virtual void SetUp() OVERRIDE { |
111 test::AshTestBase::SetUp(); | 108 test::AshTestBase::SetUp(); |
112 // Ash shell initialization creates wallpaper. Reset it so we can manually | 109 // Ash shell initialization creates wallpaper. Reset it so we can manually |
113 // control wallpaper creation and animation in our tests. | 110 // control wallpaper creation and animation in our tests. |
114 internal::RootWindowController* root_window_controller = | 111 internal::RootWindowController* root_window_controller = |
115 Shell::GetPrimaryRootWindowController(); | 112 Shell::GetPrimaryRootWindowController(); |
116 root_window_controller->SetWallpaperController(NULL); | 113 root_window_controller->SetWallpaperController(NULL); |
117 root_window_controller->SetAnimatingWallpaperController(NULL); | 114 root_window_controller->SetAnimatingWallpaperController(NULL); |
118 controller_ = Shell::GetInstance()->desktop_background_controller(); | 115 controller_ = Shell::GetInstance()->desktop_background_controller(); |
119 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( | 116 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( |
120 Shell::GetInstance()->user_wallpaper_delegate()); | 117 Shell::GetInstance()->user_wallpaper_delegate()); |
121 controller_->set_wallpaper_reload_delay_for_test(0); | 118 controller_->set_wallpaper_reload_delay_for_test(base::TimeDelta()); |
122 } | 119 } |
123 | 120 |
124 protected: | 121 protected: |
125 // Colors used for different default wallpapers by | 122 // Colors used for different default wallpapers by |
126 // WriteWallpapersAndSetFlags(). | 123 // WriteWallpapersAndSetFlags(). |
127 static const SkColor kLargeWallpaperColor = SK_ColorRED; | 124 static const SkColor kLargeWallpaperColor = SK_ColorRED; |
128 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | 125 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; |
129 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | 126 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; |
130 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | 127 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; |
131 | 128 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 221 } |
225 | 222 |
226 return true; | 223 return true; |
227 } | 224 } |
228 | 225 |
229 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and | 226 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and |
230 // passes |controller_| a command line instructing it to use the images. | 227 // passes |controller_| a command line instructing it to use the images. |
231 // Only needs to be called (once) by tests that want to test loading of | 228 // Only needs to be called (once) by tests that want to test loading of |
232 // default wallpapers. | 229 // default wallpapers. |
233 void WriteWallpapersAndSetFlags() { | 230 void WriteWallpapersAndSetFlags() { |
| 231 base::CommandLine cl(base::CommandLine::NO_PROGRAM); |
| 232 |
234 wallpaper_dir_.reset(new base::ScopedTempDir); | 233 wallpaper_dir_.reset(new base::ScopedTempDir); |
235 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | 234 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); |
236 | 235 |
237 const base::FilePath kLargePath = | 236 const base::FilePath kLargePath = |
238 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); | 237 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); |
239 ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, | 238 ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, |
240 kLargeWallpaperColor)); | 239 kLargeWallpaperColor)); |
241 command_line_.AppendSwitchPath( | 240 cl.AppendSwitchPath(switches::kAshDefaultWallpaperLarge, kLargePath); |
242 switches::kAshDefaultWallpaperLarge, kLargePath); | |
243 | 241 |
244 const base::FilePath kSmallPath = | 242 const base::FilePath kSmallPath = |
245 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); | 243 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); |
246 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, | 244 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, |
247 kSmallWallpaperColor)); | 245 kSmallWallpaperColor)); |
248 command_line_.AppendSwitchPath( | 246 cl.AppendSwitchPath(switches::kAshDefaultWallpaperSmall, kSmallPath); |
249 switches::kAshDefaultWallpaperSmall, kSmallPath); | |
250 | 247 |
251 const base::FilePath kLargeGuestPath = | 248 const base::FilePath kLargeGuestPath = |
252 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); | 249 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); |
253 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, | 250 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, |
254 kLargeGuestWallpaperColor)); | 251 kLargeGuestWallpaperColor)); |
255 command_line_.AppendSwitchPath( | 252 cl.AppendSwitchPath(switches::kAshGuestWallpaperLarge, kLargeGuestPath); |
256 switches::kAshGuestWallpaperLarge, kLargeGuestPath); | |
257 | 253 |
258 const base::FilePath kSmallGuestPath = | 254 const base::FilePath kSmallGuestPath = |
259 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); | 255 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); |
260 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, | 256 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, |
261 kSmallGuestWallpaperColor)); | 257 kSmallGuestWallpaperColor)); |
262 command_line_.AppendSwitchPath( | 258 cl.AppendSwitchPath(switches::kAshGuestWallpaperSmall, kSmallGuestPath); |
263 switches::kAshGuestWallpaperSmall, kSmallGuestPath); | |
264 | 259 |
265 controller_->set_command_line_for_testing(&command_line_); | 260 controller_->InitWallpaperPathsFromCommandLine(&cl); |
266 } | 261 } |
267 | 262 |
268 // Custom command line passed to DesktopBackgroundController by | |
269 // WriteWallpapersAndSetFlags(). | |
270 CommandLine command_line_; | |
271 | |
272 // Directory created by WriteWallpapersAndSetFlags() to store default | 263 // Directory created by WriteWallpapersAndSetFlags() to store default |
273 // wallpaper images. | 264 // wallpaper images. |
274 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | 265 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; |
275 | 266 |
276 DesktopBackgroundController* controller_; // Not owned. | 267 DesktopBackgroundController* controller_; // Not owned. |
277 | 268 |
278 test::TestUserWallpaperDelegate* wallpaper_delegate_; | 269 test::TestUserWallpaperDelegate* wallpaper_delegate_; |
279 | 270 |
280 private: | 271 private: |
281 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); | 272 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 // new load task was started (since the previous one was interrupted by | 678 // new load task was started (since the previous one was interrupted by |
688 // SetCustomWallpaper()). See http://crbug.com/327443. | 679 // SetCustomWallpaper()). See http://crbug.com/327443. |
689 TestObserver observer(controller_); | 680 TestObserver observer(controller_); |
690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | 681 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); |
691 observer.WaitForWallpaperDataChanged(); | 682 observer.WaitForWallpaperDataChanged(); |
692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | 683 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
693 kSmallWallpaperColor)); | 684 kSmallWallpaperColor)); |
694 } | 685 } |
695 | 686 |
696 } // namespace ash | 687 } // namespace ash |
OLD | NEW |