Commit 7819ffcd authored by derat@chromium.org's avatar derat@chromium.org

ash: Add test for wallpaper-switching bug.

Add a test for the DesktopBackgroundController
wallpaper-switching bug that was fixed by r242579.

BUG=327443

Review URL: https://codereview.chromium.org/115263004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243761 0039d316-1c4b-4281-b951-d872f2087c98
parent bb8467dd
...@@ -129,16 +129,21 @@ class DesktopBackgroundControllerTest : public test::AshTestBase { ...@@ -129,16 +129,21 @@ class DesktopBackgroundControllerTest : public test::AshTestBase {
static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE;
static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW;
// A color that can be passed to CreateImage(). Specifically chosen to not
// conflict with any of the default wallpaper colors.
static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA;
// Dimension used for width and height of default wallpaper images. A // Dimension used for width and height of default wallpaper images. A
// small value is used to minimize the amount of time spent compressing // small value is used to minimize the amount of time spent compressing
// and writing images. // and writing images.
static const int kWallpaperSize = 2; static const int kWallpaperSize = 2;
// Creates an image of size |size|. // Creates an image of size |size|.
gfx::ImageSkia CreateImage(int width, int height) { gfx::ImageSkia CreateImage(int width, int height, SkColor color) {
SkBitmap bitmap; SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
bitmap.allocPixels(); bitmap.allocPixels();
bitmap.eraseColor(color);
gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
return image; return image;
} }
...@@ -440,7 +445,7 @@ TEST_F(DesktopBackgroundControllerTest, DisplayChange) { ...@@ -440,7 +445,7 @@ TEST_F(DesktopBackgroundControllerTest, DisplayChange) {
// Set the wallpaper to ensure that UpdateWallpaper() will be called when the // Set the wallpaper to ensure that UpdateWallpaper() will be called when the
// display configuration changes. // display configuration changes.
gfx::ImageSkia image = CreateImage(640, 480); gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
wallpaper_delegate_->set_custom_wallpaper(image); wallpaper_delegate_->set_custom_wallpaper(image);
controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
...@@ -603,7 +608,7 @@ TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { ...@@ -603,7 +608,7 @@ TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) {
Shell::GetInstance()->display_manager()); Shell::GetInstance()->display_manager());
display_manager_test_api.UpdateDisplay("320x200"); display_manager_test_api.UpdateDisplay("320x200");
gfx::ImageSkia image = CreateImage(640, 480); gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
// Set the image as custom wallpaper, wait for the resize to finish, and check // Set the image as custom wallpaper, wait for the resize to finish, and check
// that the resized image is the expected size. // that the resized image is the expected size.
...@@ -665,4 +670,27 @@ TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { ...@@ -665,4 +670,27 @@ TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) {
DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
} }
TEST_F(DesktopBackgroundControllerTest, SwitchBetweenDefaultAndCustom) {
// Start loading the default wallpaper.
UpdateDisplay("640x480");
WriteWallpapersAndSetFlags();
ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
// Custom wallpaper should be applied immediately, canceling the default
// wallpaper load task.
gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
kCustomWallpaperColor));
// A call to SetDefaultWallpaper() should return true now, indicating that a
// new load task was started (since the previous one was interrupted by
// SetCustomWallpaper()). See http://crbug.com/327443.
TestObserver observer(controller_);
ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
observer.WaitForWallpaperDataChanged();
EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
kSmallWallpaperColor));
}
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment