Index: ash/desktop_background/desktop_background_controller_unittest.cc |
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc |
index 1c4810598756e008649fb3165bedc6eac567b903..9eb8fb32a501d8b854da96a8f93e43913dcd88e7 100644 |
--- a/ash/desktop_background/desktop_background_controller_unittest.cc |
+++ b/ash/desktop_background/desktop_background_controller_unittest.cc |
@@ -8,7 +8,6 @@ |
#include <cstdlib> |
#include "ash/ash_switches.h" |
-#include "ash/desktop_background/desktop_background_controller_observer.h" |
#include "ash/desktop_background/desktop_background_widget_controller.h" |
#include "ash/root_window_controller.h" |
#include "ash/shell.h" |
@@ -16,10 +15,6 @@ |
#include "ash/test/ash_test_base.h" |
#include "ash/test/display_manager_test_api.h" |
#include "ash/test/test_user_wallpaper_delegate.h" |
-#include "base/command_line.h" |
-#include "base/file_util.h" |
-#include "base/files/file_path.h" |
-#include "base/files/scoped_temp_dir.h" |
#include "base/message_loop/message_loop.h" |
#include "base/threading/sequenced_worker_pool.h" |
#include "content/public/browser/browser_thread.h" |
@@ -30,9 +25,6 @@ |
#include "ui/aura/window_event_dispatcher.h" |
#include "ui/compositor/scoped_animation_duration_scale_mode.h" |
#include "ui/compositor/test/layer_animator_test_controller.h" |
-#include "ui/gfx/codec/jpeg_codec.h" |
-#include "ui/gfx/point.h" |
-#include "ui/gfx/rect.h" |
using aura::RootWindow; |
using aura::Window; |
@@ -53,31 +45,6 @@ int ChildCountForContainer(int container_id) { |
return static_cast<int>(container->children().size()); |
} |
-class TestObserver : public DesktopBackgroundControllerObserver { |
- public: |
- explicit TestObserver(DesktopBackgroundController* controller) |
- : controller_(controller) { |
- DCHECK(controller_); |
- controller_->AddObserver(this); |
- } |
- |
- virtual ~TestObserver() { |
- controller_->RemoveObserver(this); |
- } |
- |
- void WaitForWallpaperDataChanged() { |
- base::MessageLoop::current()->Run(); |
- } |
- |
- // DesktopBackgroundControllerObserver overrides: |
- virtual void OnWallpaperDataChanged() OVERRIDE { |
- base::MessageLoop::current()->Quit(); |
- } |
- |
- private: |
- DesktopBackgroundController* controller_; |
-}; |
- |
// Steps a widget's layer animation until it is completed. Animations must be |
// enabled. |
void RunAnimationForWidget(views::Widget* widget) { |
@@ -102,8 +69,7 @@ void RunAnimationForWidget(views::Widget* widget) { |
class DesktopBackgroundControllerTest : public test::AshTestBase { |
public: |
DesktopBackgroundControllerTest() |
- : command_line_(CommandLine::NO_PROGRAM), |
- controller_(NULL) { |
+ : controller_(NULL) { |
} |
virtual ~DesktopBackgroundControllerTest() {} |
@@ -122,22 +88,10 @@ class DesktopBackgroundControllerTest : public test::AshTestBase { |
} |
protected: |
- // Colors used for different default wallpapers by |
- // WriteWallpapersAndSetFlags(). |
- static const SkColor kLargeWallpaperColor = SK_ColorRED; |
- static const SkColor kSmallWallpaperColor = SK_ColorGREEN; |
- static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; |
- 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 |
- // small value is used to minimize the amount of time spent compressing |
- // and writing images. |
- static const int kWallpaperSize = 2; |
- |
// Creates an image of size |size|. |
gfx::ImageSkia CreateImage(int width, int height, SkColor color) { |
SkBitmap bitmap; |
@@ -157,122 +111,6 @@ class DesktopBackgroundControllerTest : public test::AshTestBase { |
ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
} |
- // Returns true if the color at the center of |image| is close to |
- // |expected_color|. (The center is used so small wallpaper images can be |
- // used.) |
- bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { |
- if (image.size().IsEmpty()) { |
- LOG(ERROR) << "Image is empty"; |
- return false; |
- } |
- |
- const SkBitmap* bitmap = image.bitmap(); |
- if (!bitmap) { |
- LOG(ERROR) << "Unable to get bitmap from image"; |
- return false; |
- } |
- |
- bitmap->lockPixels(); |
- gfx::Point center = gfx::Rect(image.size()).CenterPoint(); |
- SkColor image_color = bitmap->getColor(center.x(), center.y()); |
- bitmap->unlockPixels(); |
- |
- const int kDiff = 3; |
- if (std::abs(static_cast<int>(SkColorGetA(image_color)) - |
- static_cast<int>(SkColorGetA(expected_color))) > kDiff || |
- std::abs(static_cast<int>(SkColorGetR(image_color)) - |
- static_cast<int>(SkColorGetR(expected_color))) > kDiff || |
- std::abs(static_cast<int>(SkColorGetG(image_color)) - |
- static_cast<int>(SkColorGetG(expected_color))) > kDiff || |
- std::abs(static_cast<int>(SkColorGetB(image_color)) - |
- static_cast<int>(SkColorGetB(expected_color))) > kDiff) { |
- LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color |
- << " but got 0x" << image_color; |
- return false; |
- } |
- |
- return true; |
- } |
- |
- // Writes a JPEG image of the specified size and color to |path|. Returns |
- // true on success. |
- bool WriteJPEGFile(const base::FilePath& path, |
- int width, |
- int height, |
- SkColor color) { |
- SkBitmap bitmap; |
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); |
- bitmap.allocPixels(); |
- bitmap.eraseColor(color); |
- |
- const int kQuality = 80; |
- std::vector<unsigned char> output; |
- if (!gfx::JPEGCodec::Encode( |
- static_cast<const unsigned char*>(bitmap.getPixels()), |
- gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(), |
- kQuality, &output)) { |
- LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; |
- return false; |
- } |
- |
- size_t bytes_written = base::WriteFile( |
- path, reinterpret_cast<const char*>(&output[0]), output.size()); |
- if (bytes_written != output.size()) { |
- LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " |
- << output.size() << " to " << path.value(); |
- return false; |
- } |
- |
- return true; |
- } |
- |
- // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and |
- // passes |controller_| a command line instructing it to use the images. |
- // Only needs to be called (once) by tests that want to test loading of |
- // default wallpapers. |
- void WriteWallpapersAndSetFlags() { |
- wallpaper_dir_.reset(new base::ScopedTempDir); |
- ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); |
- |
- const base::FilePath kLargePath = |
- wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); |
- ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, |
- kLargeWallpaperColor)); |
- command_line_.AppendSwitchPath( |
- switches::kAshDefaultWallpaperLarge, kLargePath); |
- |
- const base::FilePath kSmallPath = |
- wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); |
- ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, |
- kSmallWallpaperColor)); |
- command_line_.AppendSwitchPath( |
- switches::kAshDefaultWallpaperSmall, kSmallPath); |
- |
- const base::FilePath kLargeGuestPath = |
- wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); |
- ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, |
- kLargeGuestWallpaperColor)); |
- command_line_.AppendSwitchPath( |
- switches::kAshGuestWallpaperLarge, kLargeGuestPath); |
- |
- const base::FilePath kSmallGuestPath = |
- wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); |
- ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, |
- kSmallGuestWallpaperColor)); |
- command_line_.AppendSwitchPath( |
- switches::kAshGuestWallpaperSmall, kSmallGuestPath); |
- |
- controller_->set_command_line_for_testing(&command_line_); |
- } |
- |
- // Custom command line passed to DesktopBackgroundController by |
- // WriteWallpapersAndSetFlags(). |
- CommandLine command_line_; |
- |
- // Directory created by WriteWallpapersAndSetFlags() to store default |
- // wallpaper images. |
- scoped_ptr<base::ScopedTempDir> wallpaper_dir_; |
- |
DesktopBackgroundController* controller_; // Not owned. |
test::TestUserWallpaperDelegate* wallpaper_delegate_; |
@@ -447,7 +285,7 @@ TEST_F(DesktopBackgroundControllerTest, DisplayChange) { |
// display configuration changes. |
gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); |
wallpaper_delegate_->set_custom_wallpaper(image); |
- controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
+ controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
// Small wallpaper images should be used for configurations less than or |
// equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if |
@@ -515,90 +353,6 @@ TEST_F(DesktopBackgroundControllerTest, DisplayChange) { |
EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
} |
-// Test that DesktopBackgroundController loads the appropriate wallpaper |
-// images as specified via command-line flags in various situations. |
-// Splitting these into separate tests avoids needing to run animations. |
-// TODO(derat): Combine these into a single test -- see |
-// RunDesktopControllerAnimation()'s TODO. |
-TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { |
- if (!SupportsMultipleDisplays()) |
- return; |
- |
- WriteWallpapersAndSetFlags(); |
- TestObserver observer(controller_); |
- |
- // At 800x600, the small wallpaper should be loaded. |
- test::DisplayManagerTestApi display_manager_test_api( |
- Shell::GetInstance()->display_manager()); |
- display_manager_test_api.UpdateDisplay("800x600"); |
- ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); |
- observer.WaitForWallpaperDataChanged(); |
- EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
- kSmallWallpaperColor)); |
- |
- // Requesting the same wallpaper again should be a no-op. |
- ASSERT_FALSE(controller_->SetDefaultWallpaper(false)); |
-} |
- |
-TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) { |
- if (!SupportsMultipleDisplays()) |
- return; |
- |
- WriteWallpapersAndSetFlags(); |
- TestObserver observer(controller_); |
- test::DisplayManagerTestApi display_manager_test_api( |
- Shell::GetInstance()->display_manager()); |
- display_manager_test_api.UpdateDisplay("1600x1200"); |
- ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); |
- observer.WaitForWallpaperDataChanged(); |
- EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
- kLargeWallpaperColor)); |
-} |
- |
-TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaperWhenRotated) { |
- if (!SupportsMultipleDisplays()) |
- return; |
- WriteWallpapersAndSetFlags(); |
- TestObserver observer(controller_); |
- test::DisplayManagerTestApi display_manager_test_api( |
- Shell::GetInstance()->display_manager()); |
- |
- display_manager_test_api.UpdateDisplay("1200x800/r"); |
- ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); |
- observer.WaitForWallpaperDataChanged(); |
- EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
- kLargeWallpaperColor)); |
-} |
- |
-TEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) { |
- if (!SupportsMultipleDisplays()) |
- return; |
- |
- WriteWallpapersAndSetFlags(); |
- TestObserver observer(controller_); |
- test::DisplayManagerTestApi display_manager_test_api( |
- Shell::GetInstance()->display_manager()); |
- display_manager_test_api.UpdateDisplay("800x600"); |
- ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); |
- observer.WaitForWallpaperDataChanged(); |
- EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
- kSmallGuestWallpaperColor)); |
-} |
- |
-TEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) { |
- if (!SupportsMultipleDisplays()) |
- return; |
- |
- WriteWallpapersAndSetFlags(); |
- TestObserver observer(controller_); |
- test::DisplayManagerTestApi display_manager_test_api( |
- Shell::GetInstance()->display_manager()); |
- display_manager_test_api.UpdateDisplay("1600x1200"); |
- ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); |
- observer.WaitForWallpaperDataChanged(); |
- EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
- kLargeGuestWallpaperColor)); |
-} |
TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
if (!SupportsMultipleDisplays()) |
@@ -612,7 +366,7 @@ TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
// Set the image as custom wallpaper, wait for the resize to finish, and check |
// that the resized image is the expected size. |
- controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
+ controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); |
content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
content::RunAllPendingInMessageLoop(); |
@@ -623,7 +377,7 @@ TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
// Load the original wallpaper again and check that we're still using the |
// previously-resized image instead of doing another resize |
// (http://crbug.com/321402). |
- controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
+ controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
content::RunAllPendingInMessageLoop(); |
EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
@@ -670,27 +424,5 @@ TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { |
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 |