Chromium Code Reviews| 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 "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include "ash/ash_resources/grit/ash_resources.h" | 7 #include "ash/ash_resources/grit/ash_resources.h" |
| 8 #include "ash/ash_switches.h" | |
| 8 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
| 9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 10 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| 10 #include "ash/display/display_manager.h" | 11 #include "ash/display/display_manager.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/test/ash_test_base.h" | |
| 12 #include "ash/test/display_manager_test_api.h" | 14 #include "ash/test/display_manager_test_api.h" |
| 15 #include "ash/test/test_user_wallpaper_delegate.h" | |
| 13 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 15 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 16 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 17 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 18 #include "base/prefs/scoped_user_pref_update.h" | 21 #include "base/prefs/scoped_user_pref_update.h" |
| 19 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 21 #include "base/values.h" | 24 #include "base/values.h" |
| 22 #include "chrome/browser/chromeos/login/user.h" | 25 #include "chrome/browser/chromeos/login/user.h" |
| 23 #include "chrome/browser/chromeos/login/user_manager.h" | 26 #include "chrome/browser/chromeos/login/user_manager.h" |
| 24 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 29 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 28 #include "chromeos/chromeos_switches.h" | 31 #include "chromeos/chromeos_switches.h" |
| 29 #include "chromeos/dbus/cryptohome_client.h" | 32 #include "chromeos/dbus/cryptohome_client.h" |
| 30 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
| 31 #include "ui/aura/env.h" | 34 #include "ui/aura/env.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/gfx/codec/jpeg_codec.h" | |
| 37 #include "ui/gfx/point.h" | |
| 38 #include "ui/gfx/rect.h" | |
| 33 | 39 |
| 34 using namespace ash; | 40 using namespace ash; |
| 35 | 41 |
| 36 namespace chromeos { | 42 namespace chromeos { |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| 40 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE; | 46 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE; |
| 41 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 47 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL; |
| 42 | 48 |
| 43 int kLargeWallpaperWidth = 256; | 49 int kLargeWallpaperWidth = 256; |
| 44 int kLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; | 50 int kLargeWallpaperHeight = chromeos::kLargeWallpaperMaxHeight; |
| 45 int kSmallWallpaperWidth = 256; | 51 int kSmallWallpaperWidth = 256; |
| 46 int kSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | 52 int kSmallWallpaperHeight = chromeos::kSmallWallpaperMaxHeight; |
| 47 | 53 |
| 48 const char kTestUser1[] = "test1@domain.com"; | 54 const char kTestUser1[] = "test1@domain.com"; |
| 49 const char kTestUser1Hash[] = "test1@domain.com-hash"; | 55 const char kTestUser1Hash[] = "test1@domain.com-hash"; |
| 50 const char kTestUser2[] = "test2@domain.com"; | 56 const char kTestUser2[] = "test2@domain.com"; |
| 51 const char kTestUser2Hash[] = "test2@domain.com-hash"; | 57 const char kTestUser2Hash[] = "test2@domain.com-hash"; |
| 52 | 58 |
| 53 } // namespace | 59 } // namespace |
| 54 | 60 |
| 55 class WallpaperManagerBrowserTest : public InProcessBrowserTest, | 61 class WallpaperManagerBrowserTest : public InProcessBrowserTest, |
| 56 public DesktopBackgroundControllerObserver, | |
| 57 public testing::WithParamInterface<bool> { | 62 public testing::WithParamInterface<bool> { |
| 58 public: | 63 public: |
| 59 WallpaperManagerBrowserTest () : controller_(NULL), | 64 WallpaperManagerBrowserTest () : controller_(NULL), |
| 60 local_state_(NULL) { | 65 local_state_(NULL) { |
| 61 } | 66 } |
| 62 | 67 |
| 63 virtual ~WallpaperManagerBrowserTest () {} | 68 virtual ~WallpaperManagerBrowserTest () {} |
| 64 | 69 |
| 65 virtual void SetUpOnMainThread() OVERRIDE { | 70 virtual void SetUpOnMainThread() OVERRIDE { |
| 66 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); | 71 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); |
| 67 controller_->AddObserver(this); | |
| 68 local_state_ = g_browser_process->local_state(); | 72 local_state_ = g_browser_process->local_state(); |
| 69 UpdateDisplay("800x600"); | 73 UpdateDisplay("800x600"); |
| 70 } | 74 } |
| 71 | 75 |
| 72 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 76 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 73 command_line->AppendSwitch(switches::kLoginManager); | 77 command_line->AppendSwitch(switches::kLoginManager); |
| 74 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 78 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 75 if (GetParam()) | 79 if (GetParam()) |
| 76 command_line->AppendSwitch(::switches::kMultiProfiles); | 80 command_line->AppendSwitch(::switches::kMultiProfiles); |
| 77 } | 81 } |
| 78 | 82 |
| 79 virtual void CleanUpOnMainThread() OVERRIDE { | 83 virtual void CleanUpOnMainThread() OVERRIDE { |
| 80 controller_->RemoveObserver(this); | |
| 81 controller_ = NULL; | 84 controller_ = NULL; |
| 82 } | 85 } |
| 83 | 86 |
| 84 // Update the display configuration as given in |display_specs|. See | 87 // Update the display configuration as given in |display_specs|. See |
| 85 // ash::test::DisplayManagerTestApi::UpdateDisplay for more details. | 88 // ash::test::DisplayManagerTestApi::UpdateDisplay for more details. |
| 86 void UpdateDisplay(const std::string& display_specs) { | 89 void UpdateDisplay(const std::string& display_specs) { |
| 87 ash::test::DisplayManagerTestApi display_manager_test_api( | 90 ash::test::DisplayManagerTestApi display_manager_test_api( |
| 88 ash::Shell::GetInstance()->display_manager()); | 91 ash::Shell::GetInstance()->display_manager()); |
| 89 display_manager_test_api.UpdateDisplay(display_specs); | 92 display_manager_test_api.UpdateDisplay(display_specs); |
| 90 } | 93 } |
| 91 | 94 |
| 92 void WaitAsyncWallpaperLoadStarted() { | 95 void WaitAsyncWallpaperLoadStarted() { |
| 93 base::MessageLoop::current()->RunUntilIdle(); | 96 base::MessageLoop::current()->RunUntilIdle(); |
|
oshima
2014/04/07 19:02:28
MessageLoop::RunUntilIdle is deprecated. Would you
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 94 } | 97 } |
| 95 | 98 |
| 96 void WaitAsyncWallpaperLoadFinished() { | 99 void WaitAsyncWallpaperLoadFinished() { |
| 97 base::MessageLoop::current()->RunUntilIdle(); | 100 base::MessageLoop::current()->RunUntilIdle(); |
| 98 while (WallpaperManager::Get()->loading_.size()) { | 101 while (WallpaperManager::Get()->loading_.size()) { |
| 99 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 102 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 100 base::MessageLoop::current()->RunUntilIdle(); | 103 base::MessageLoop::current()->RunUntilIdle(); |
| 101 } | 104 } |
|
oshima
2014/04/07 19:02:28
This is ugly. Isn't there a way to reliably tell w
Alexander Alekseev
2014/04/08 13:18:49
The idea is to wait until "final" wallpaper load r
| |
| 102 } | 105 } |
| 103 | 106 |
| 104 virtual void OnWallpaperDataChanged() OVERRIDE { | 107 protected: |
| 105 base::MessageLoop::current()->Quit(); | 108 // Colors used for different default wallpapers by |
| 106 } | 109 // WriteWallpapers(). |
| 110 static const SkColor kLargeWallpaperColor = SK_ColorRED; | |
| 111 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | |
| 112 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | |
| 113 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | |
| 107 | 114 |
| 108 protected: | 115 // A color that can be passed to CreateImage(). Specifically chosen to not |
| 116 // conflict with any of the default wallpaper colors. | |
| 117 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; | |
| 118 | |
| 119 // Dimension used for width and height of default wallpaper images. A | |
| 120 // small value is used to minimize the amount of time spent compressing | |
| 121 // and writing images. | |
| 122 static const int kWallpaperSize = 2; | |
| 123 | |
| 109 // Return custom wallpaper path. Create directory if not exist. | 124 // Return custom wallpaper path. Create directory if not exist. |
| 110 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | 125 base::FilePath GetCustomWallpaperPath(const char* sub_dir, |
| 111 const std::string& username_hash, | 126 const std::string& username_hash, |
| 112 const std::string& id) { | 127 const std::string& id) { |
| 113 base::FilePath wallpaper_path = | 128 base::FilePath wallpaper_path = |
| 114 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, | 129 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, |
| 115 username_hash, | 130 username_hash, |
| 116 id); | 131 id); |
| 117 if (!base::DirectoryExists(wallpaper_path.DirName())) | 132 if (!base::DirectoryExists(wallpaper_path.DirName())) |
| 118 base::CreateDirectory(wallpaper_path.DirName()); | 133 base::CreateDirectory(wallpaper_path.DirName()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 136 wallpaper_path, | 151 wallpaper_path, |
| 137 reinterpret_cast<const char*>(image_data->front()), | 152 reinterpret_cast<const char*>(image_data->front()), |
| 138 image_data->size()); | 153 image_data->size()); |
| 139 EXPECT_EQ(static_cast<int>(image_data->size()), written); | 154 EXPECT_EQ(static_cast<int>(image_data->size()), written); |
| 140 } | 155 } |
| 141 | 156 |
| 142 int LoadedWallpapers() { | 157 int LoadedWallpapers() { |
| 143 return WallpaperManager::Get()->loaded_wallpapers(); | 158 return WallpaperManager::Get()->loaded_wallpapers(); |
| 144 } | 159 } |
| 145 | 160 |
| 161 // Creates a test image of size 1x1. | |
| 162 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) { | |
| 163 SkBitmap bitmap; | |
| 164 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | |
| 165 bitmap.allocPixels(); | |
| 166 bitmap.eraseColor(color); | |
| 167 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 168 } | |
| 169 | |
| 170 // Writes a JPEG image of the specified size and color to |path|. Returns | |
| 171 // true on success. | |
| 172 bool WriteJPEGFile(const base::FilePath& path, | |
| 173 int width, | |
| 174 int height, | |
| 175 SkColor color) { | |
| 176 SkBitmap bitmap; | |
|
oshima
2014/04/07 17:16:11
optional: CreateTestImage(w,h,c).bitmap();
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 177 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); | |
| 178 bitmap.allocPixels(); | |
| 179 bitmap.eraseColor(color); | |
| 180 | |
| 181 const int kQuality = 80; | |
| 182 std::vector<unsigned char> output; | |
| 183 if (!gfx::JPEGCodec::Encode( | |
| 184 static_cast<const unsigned char*>(bitmap.getPixels()), | |
| 185 gfx::JPEGCodec::FORMAT_SkBitmap, | |
| 186 width, | |
| 187 height, | |
| 188 bitmap.rowBytes(), | |
| 189 kQuality, | |
| 190 &output)) { | |
| 191 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; | |
| 192 return false; | |
| 193 } | |
| 194 | |
| 195 size_t bytes_written = base::WriteFile( | |
| 196 path, reinterpret_cast<const char*>(&output[0]), output.size()); | |
| 197 if (bytes_written != output.size()) { | |
| 198 LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " | |
| 199 << output.size() << " to " << path.value(); | |
| 200 return false; | |
| 201 } | |
| 202 | |
| 203 return true; | |
| 204 } | |
| 205 | |
| 206 // Initializes default wallpaper paths "*default_*file" and writes JPEG | |
| 207 // wallpaper images to them. | |
| 208 // Only needs to be called (once) by tests that want to test loading of | |
| 209 // default wallpapers. | |
| 210 void WriteWallpapers() { | |
| 211 wallpaper_dir_.reset(new base::ScopedTempDir); | |
| 212 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | |
| 213 | |
| 214 std::vector<std::string> options; | |
| 215 options.push_back(std::string("WM_Test_cmdline")); | |
| 216 const base::FilePath small_file = | |
| 217 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); | |
| 218 options.push_back(std::string("--") + | |
| 219 ash::switches::kAshDefaultWallpaperSmall + "=" + | |
| 220 small_file.value()); | |
| 221 const base::FilePath large_file = | |
| 222 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); | |
| 223 options.push_back(std::string("--") + | |
| 224 ash::switches::kAshDefaultWallpaperLarge + "=" + | |
| 225 large_file.value()); | |
| 226 const base::FilePath guest_small_file = | |
| 227 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); | |
| 228 options.push_back(std::string("--") + | |
| 229 ash::switches::kAshGuestWallpaperSmall + "=" + | |
| 230 guest_small_file.value()); | |
| 231 const base::FilePath guest_large_file = | |
| 232 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); | |
| 233 options.push_back(std::string("--") + | |
| 234 ash::switches::kAshGuestWallpaperLarge + "=" + | |
| 235 guest_large_file.value()); | |
| 236 | |
| 237 ASSERT_TRUE(WriteJPEGFile(small_file, | |
| 238 kWallpaperSize, | |
| 239 kWallpaperSize, | |
| 240 kSmallWallpaperColor)); | |
| 241 ASSERT_TRUE(WriteJPEGFile(large_file, | |
| 242 kWallpaperSize, | |
| 243 kWallpaperSize, | |
| 244 kLargeWallpaperColor)); | |
| 245 ASSERT_TRUE(WriteJPEGFile(guest_small_file, | |
| 246 kWallpaperSize, | |
| 247 kWallpaperSize, | |
| 248 kSmallGuestWallpaperColor)); | |
| 249 ASSERT_TRUE(WriteJPEGFile(guest_large_file, | |
| 250 kWallpaperSize, | |
| 251 kWallpaperSize, | |
| 252 kLargeGuestWallpaperColor)); | |
| 253 | |
| 254 wallpaper_manager_command_line_.reset(new base::CommandLine(options)); | |
| 255 WallpaperManager::Get()->set_command_line_for_testing( | |
| 256 wallpaper_manager_command_line_.get()); | |
|
oshima
2014/04/07 17:16:11
What's the reason why we can't do this in SetUpCom
Alexander Alekseev
2014/04/08 13:18:49
For the old tests (i.e. not moved from unittests)
oshima
2014/04/08 21:49:38
That's because it's using one base test class for
| |
| 257 } | |
| 258 | |
| 259 // Returns true if the color at the center of |image| is close to | |
| 260 // |expected_color|. (The center is used so small wallpaper images can be | |
| 261 // used.) | |
| 262 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { | |
| 263 if (image.size().IsEmpty()) { | |
| 264 LOG(ERROR) << "Image is empty"; | |
| 265 return false; | |
| 266 } | |
| 267 | |
| 268 const SkBitmap* bitmap = image.bitmap(); | |
| 269 if (!bitmap) { | |
| 270 LOG(ERROR) << "Unable to get bitmap from image"; | |
| 271 return false; | |
| 272 } | |
| 273 | |
| 274 bitmap->lockPixels(); | |
| 275 gfx::Point center = gfx::Rect(image.size()).CenterPoint(); | |
| 276 SkColor image_color = bitmap->getColor(center.x(), center.y()); | |
| 277 bitmap->unlockPixels(); | |
| 278 | |
| 279 const int kDiff = 3; | |
| 280 if (std::abs(static_cast<int>(SkColorGetA(image_color)) - | |
| 281 static_cast<int>(SkColorGetA(expected_color))) > kDiff || | |
| 282 std::abs(static_cast<int>(SkColorGetR(image_color)) - | |
| 283 static_cast<int>(SkColorGetR(expected_color))) > kDiff || | |
| 284 std::abs(static_cast<int>(SkColorGetG(image_color)) - | |
| 285 static_cast<int>(SkColorGetG(expected_color))) > kDiff || | |
| 286 std::abs(static_cast<int>(SkColorGetB(image_color)) - | |
| 287 static_cast<int>(SkColorGetB(expected_color))) > kDiff) { | |
| 288 LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color | |
| 289 << " but got 0x" << image_color; | |
| 290 return false; | |
| 291 } | |
| 292 | |
| 293 return true; | |
| 294 } | |
| 295 | |
| 146 DesktopBackgroundController* controller_; | 296 DesktopBackgroundController* controller_; |
| 147 PrefService* local_state_; | 297 PrefService* local_state_; |
| 298 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_; | |
| 299 | |
| 300 // Directory created by WriteWallpapersAndSetFlags() to store default | |
| 301 // wallpaper images. | |
| 302 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | |
| 148 | 303 |
| 149 private: | 304 private: |
| 150 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); | 305 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); |
| 151 }; | 306 }; |
| 152 | 307 |
| 153 // Tests that the appropriate custom wallpaper (large vs. small) is loaded | 308 // Tests that the appropriate custom wallpaper (large vs. small) is loaded |
| 154 // depending on the desktop resolution. | 309 // depending on the desktop resolution. |
| 155 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | 310 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, |
| 156 LoadCustomLargeWallpaperForLargeExternalScreen) { | 311 LoadCustomLargeWallpaperForLargeExternalScreen) { |
| 157 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 312 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 188 WaitAsyncWallpaperLoadFinished(); | 343 WaitAsyncWallpaperLoadFinished(); |
| 189 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | 344 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); |
| 190 | 345 |
| 191 // Display is initialized to 800x600. The small resolution custom wallpaper is | 346 // Display is initialized to 800x600. The small resolution custom wallpaper is |
| 192 // expected. | 347 // expected. |
| 193 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | 348 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
| 194 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | 349 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
| 195 | 350 |
| 196 // Hook up another 800x600 display. This shouldn't trigger a reload. | 351 // Hook up another 800x600 display. This shouldn't trigger a reload. |
| 197 UpdateDisplay("800x600,800x600"); | 352 UpdateDisplay("800x600,800x600"); |
| 198 content::RunAllPendingInMessageLoop(); | 353 WaitAsyncWallpaperLoadFinished(); |
| 199 // The small resolution custom wallpaper is expected. | 354 // The small resolution custom wallpaper is expected. |
| 200 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | 355 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
| 201 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | 356 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
| 202 | 357 |
| 203 // Detach the secondary display. | 358 // Detach the secondary display. |
| 204 UpdateDisplay("800x600"); | 359 UpdateDisplay("800x600"); |
| 205 // Hook up a 2000x2000 display. The large resolution custom wallpaper should | 360 // Hook up a 2000x2000 display. The large resolution custom wallpaper should |
| 206 // be loaded. | 361 // be loaded. |
| 207 UpdateDisplay("800x600,2000x2000"); | 362 UpdateDisplay("800x600,2000x2000"); |
| 208 WaitAsyncWallpaperLoadFinished(); | 363 WaitAsyncWallpaperLoadFinished(); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 testing::Bool()); | 718 testing::Bool()); |
| 564 | 719 |
| 565 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, | 720 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, |
| 566 WallpaperManagerBrowserTestCrashRestore, | 721 WallpaperManagerBrowserTestCrashRestore, |
| 567 testing::Bool()); | 722 testing::Bool()); |
| 568 | 723 |
| 569 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, | 724 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, |
| 570 WallpaperManagerBrowserTestCacheUpdate, | 725 WallpaperManagerBrowserTestCacheUpdate, |
| 571 testing::Bool()); | 726 testing::Bool()); |
| 572 | 727 |
| 728 // ---------------------------------------------------------------------- | |
| 729 // Test default wallpapers. | |
| 730 | |
| 731 class TestObserver : public WallpaperManager::Observer { | |
| 732 public: | |
| 733 explicit TestObserver(WallpaperManager* wallpaper_manager) | |
| 734 : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) { | |
| 735 DCHECK(wallpaper_manager_); | |
| 736 wallpaper_manager_->AddObserver(this); | |
| 737 LOG(ERROR) << "TestObserver: Created."; | |
|
oshima
2014/04/07 17:16:11
remove debug log.
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 738 } | |
| 739 | |
| 740 virtual ~TestObserver() { | |
| 741 wallpaper_manager_->RemoveObserver(this); | |
| 742 } | |
| 743 | |
| 744 virtual void OnWallpaperAnimationFinished(const std::string&) { | |
|
oshima
2014/04/07 17:16:11
OVERRIDE
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 745 } | |
| 746 | |
| 747 virtual void OnUpdateWallpaperForTesting() OVERRIDE { | |
| 748 LOG(ERROR) << "TestObserver::OnUpdateWallpaperForTesting() called."; | |
|
oshima
2014/04/07 17:16:11
ditto
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 749 ++update_wallpaper_count_; | |
| 750 } | |
| 751 | |
| 752 int GetUpdateWallpaperCountAndReset() { | |
| 753 const size_t old = update_wallpaper_count_; | |
| 754 update_wallpaper_count_ = 0; | |
| 755 return old; | |
| 756 } | |
| 757 | |
| 758 private: | |
| 759 int update_wallpaper_count_; | |
| 760 WallpaperManager* wallpaper_manager_; | |
| 761 }; | |
|
oshima
2014/04/07 17:16:11
DISALLOW_COPY_AND_ASSIGN
Alexander Alekseev
2014/04/08 13:18:49
Done.
| |
| 762 | |
| 763 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, DisplayChange) { | |
| 764 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | |
| 765 if (!ash::test::AshTestBase::SupportsHostWindowResize()) | |
| 766 return; | |
| 767 | |
| 768 TestObserver observer(WallpaperManager::Get()); | |
| 769 | |
| 770 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the | |
| 771 // display configuration changes. | |
| 772 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); | |
| 773 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | |
| 774 | |
| 775 // Small wallpaper images should be used for configurations less than or | |
| 776 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | |
| 777 // multiple displays are connected. | |
| 778 UpdateDisplay("800x600"); | |
| 779 WaitAsyncWallpaperLoadFinished(); | |
| 780 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
| 781 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 782 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
| 783 | |
| 784 UpdateDisplay("800x600,800x600"); | |
| 785 WaitAsyncWallpaperLoadFinished(); | |
| 786 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
| 787 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 788 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
| 789 | |
| 790 UpdateDisplay("1366x800"); | |
| 791 WaitAsyncWallpaperLoadFinished(); | |
| 792 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
| 793 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 794 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 795 | |
| 796 // At larger sizes, large wallpapers should be used. | |
| 797 UpdateDisplay("1367x800"); | |
| 798 WaitAsyncWallpaperLoadFinished(); | |
| 799 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
| 800 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 801 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 802 | |
| 803 UpdateDisplay("1367x801"); | |
| 804 WaitAsyncWallpaperLoadFinished(); | |
| 805 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
| 806 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 807 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 808 | |
| 809 UpdateDisplay("2560x1700"); | |
| 810 WaitAsyncWallpaperLoadFinished(); | |
| 811 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
| 812 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 813 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 814 | |
| 815 // Rotated smaller screen may use larger image. | |
| 816 UpdateDisplay("800x600/r"); | |
| 817 WaitAsyncWallpaperLoadFinished(); | |
| 818 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
| 819 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 820 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 821 | |
| 822 UpdateDisplay("800x600/r,800x600"); | |
| 823 WaitAsyncWallpaperLoadFinished(); | |
| 824 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
| 825 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 826 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 827 UpdateDisplay("1366x800/r"); | |
| 828 WaitAsyncWallpaperLoadFinished(); | |
| 829 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
| 830 WallpaperManager::Get()->GetAppropriateResolution()); | |
| 831 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
| 832 | |
| 833 // Max display size didn't chagne. | |
| 834 UpdateDisplay("900x800/r,400x1366"); | |
| 835 WaitAsyncWallpaperLoadFinished(); | |
| 836 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
| 837 } | |
| 838 | |
| 839 // Test that WallpaperManager loads the appropriate wallpaper | |
| 840 // images as specified via command-line flags in various situations. | |
| 841 // Splitting these into separate tests avoids needing to run animations. | |
| 842 // TODO(derat): Combine these into a single test | |
| 843 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { | |
| 844 if (!ash::test::AshTestBase::SupportsMultipleDisplays()) | |
| 845 return; | |
| 846 | |
| 847 WriteWallpapers(); | |
| 848 | |
| 849 // At 800x600, the small wallpaper should be loaded. | |
| 850 UpdateDisplay("800x600"); | |
| 851 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 852 WaitAsyncWallpaperLoadFinished(); | |
| 853 EXPECT_TRUE( | |
| 854 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); | |
| 855 } | |
| 856 | |
| 857 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeDefaultWallpaper) { | |
| 858 if (!ash::test::AshTestBase::SupportsMultipleDisplays()) | |
| 859 return; | |
| 860 | |
| 861 WriteWallpapers(); | |
| 862 UpdateDisplay("1600x1200"); | |
| 863 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 864 WaitAsyncWallpaperLoadFinished(); | |
| 865 EXPECT_TRUE( | |
| 866 ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor)); | |
| 867 } | |
| 868 | |
| 869 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
| 870 LargeDefaultWallpaperWhenRotated) { | |
| 871 if (!ash::test::AshTestBase::SupportsMultipleDisplays()) | |
| 872 return; | |
| 873 WriteWallpapers(); | |
| 874 | |
| 875 UpdateDisplay("1200x800/r"); | |
| 876 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 877 WaitAsyncWallpaperLoadFinished(); | |
| 878 EXPECT_TRUE( | |
| 879 ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor)); | |
| 880 } | |
| 881 | |
| 882 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallGuestWallpaper) { | |
| 883 if (!ash::test::AshTestBase::SupportsMultipleDisplays()) | |
| 884 return; | |
| 885 WriteWallpapers(); | |
| 886 UserManager::Get()->UserLoggedIn( | |
| 887 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
| 888 UpdateDisplay("800x600"); | |
| 889 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 890 WaitAsyncWallpaperLoadFinished(); | |
| 891 EXPECT_TRUE( | |
| 892 ImageIsNearColor(controller_->GetWallpaper(), kSmallGuestWallpaperColor)); | |
| 893 } | |
| 894 | |
| 895 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeGuestWallpaper) { | |
| 896 if (!ash::test::AshTestBase::SupportsMultipleDisplays()) | |
| 897 return; | |
| 898 | |
| 899 WriteWallpapers(); | |
| 900 UserManager::Get()->UserLoggedIn( | |
| 901 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
| 902 UpdateDisplay("1600x1200"); | |
| 903 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 904 WaitAsyncWallpaperLoadFinished(); | |
| 905 EXPECT_TRUE( | |
| 906 ImageIsNearColor(controller_->GetWallpaper(), kLargeGuestWallpaperColor)); | |
| 907 } | |
| 908 | |
| 909 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
| 910 SwitchBetweenDefaultAndCustom) { | |
| 911 // Start loading the default wallpaper. | |
| 912 UpdateDisplay("640x480"); | |
| 913 WriteWallpapers(); | |
| 914 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); | |
| 915 | |
| 916 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 917 | |
| 918 // Custom wallpaper should be applied immediately, canceling the default | |
| 919 // wallpaper load task. | |
| 920 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); | |
| 921 UserImage wallpaper(image); | |
| 922 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, | |
| 923 "test_hash", | |
| 924 "test-nofile.jpeg", | |
| 925 WALLPAPER_LAYOUT_STRETCH, | |
| 926 User::CUSTOMIZED, | |
| 927 wallpaper, | |
| 928 true); | |
| 929 WaitAsyncWallpaperLoadFinished(); | |
| 930 | |
| 931 EXPECT_TRUE( | |
| 932 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor)); | |
| 933 | |
| 934 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
| 935 WaitAsyncWallpaperLoadFinished(); | |
| 936 | |
| 937 EXPECT_TRUE( | |
| 938 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); | |
| 939 } | |
| 940 | |
| 573 } // namespace chromeos | 941 } // namespace chromeos |
| OLD | NEW |