summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 23:53:07 +0000
committeralemate@chromium.org <alemate@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-09 23:53:07 +0000
commit3f4c26ecd470540a43b9d422408aad64e3fedf96 (patch)
treee504b8820bffcc2a4d103bfdb6030666e0f00b5c
parent19db94feaaa7e875d09ac8022e88aee455b88887 (diff)
downloadchromium_src-3f4c26ecd470540a43b9d422408aad64e3fedf96.zip
chromium_src-3f4c26ecd470540a43b9d422408aad64e3fedf96.tar.gz
chromium_src-3f4c26ecd470540a43b9d422408aad64e3fedf96.tar.bz2
Move all wallpaper file loading and decoding from DesktopBackgroundController to WallpaperManager.
To simplify DesktopBackgroundController and allow customized default wallpapers, we need to move all "default" wallpaper loading to WallpaperManager. BUG=348136 TEST=unittests Review URL: https://codereview.chromium.org/215293003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262862 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/accelerators/debug_commands.cc6
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/desktop_background/desktop_background_controller.cc299
-rw-r--r--ash/desktop_background/desktop_background_controller.h99
-rw-r--r--ash/desktop_background/desktop_background_controller_test_api.cc19
-rw-r--r--ash/desktop_background/desktop_background_controller_test_api.h24
-rw-r--r--ash/desktop_background/desktop_background_controller_unittest.cc352
-rw-r--r--ash/desktop_background/wallpaper_resizer.cc9
-rw-r--r--ash/desktop_background/wallpaper_resizer.h7
-rw-r--r--ash/shell/content_client/shell_browser_main_parts.cc3
-rw-r--r--ash/test/ash_test_base.cc14
-rw-r--r--ash/test/ash_test_base.h6
-rw-r--r--ash/test/ash_test_helper.cc22
-rw-r--r--ash/test/ash_test_helper.h8
-rw-r--r--ash/test/test_user_wallpaper_delegate.cc2
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_api.cc7
-rw-r--r--chrome/browser/chromeos/extensions/wallpaper_private_api.cc18
-rw-r--r--chrome/browser/chromeos/login/wallpaper_manager.cc227
-rw-r--r--chrome/browser/chromeos/login/wallpaper_manager.h73
-rw-r--r--chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc400
-rw-r--r--chrome/browser/chromeos/login/wallpaper_manager_unittest.cc107
-rw-r--r--chrome/browser/ui/ash/user_wallpaper_delegate_win.cc5
22 files changed, 833 insertions, 876 deletions
diff --git a/ash/accelerators/debug_commands.cc b/ash/accelerators/debug_commands.cc
index 4ca1720..beca39f 100644
--- a/ash/accelerators/debug_commands.cc
+++ b/ash/accelerators/debug_commands.cc
@@ -44,17 +44,17 @@ bool CycleDesktopBackgroundMode() {
InitializeWallpaper();
break;
case 1:
- desktop_background_controller->SetCustomWallpaper(
+ desktop_background_controller->SetWallpaperImage(
CreateWallpaperImage(SK_ColorRED, SK_ColorBLUE),
WALLPAPER_LAYOUT_STRETCH);
break;
case 2:
- desktop_background_controller->SetCustomWallpaper(
+ desktop_background_controller->SetWallpaperImage(
CreateWallpaperImage(SK_ColorBLUE, SK_ColorGREEN),
WALLPAPER_LAYOUT_CENTER);
break;
case 3:
- desktop_background_controller->SetCustomWallpaper(
+ desktop_background_controller->SetWallpaperImage(
CreateWallpaperImage(SK_ColorGREEN, SK_ColorRED),
WALLPAPER_LAYOUT_CENTER_CROPPED);
break;
diff --git a/ash/ash.gyp b/ash/ash.gyp
index d14c6d8c..dc07d3c 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -756,6 +756,8 @@
'ash_resources',
],
'sources': [
+ 'desktop_background/desktop_background_controller_test_api.cc',
+ 'desktop_background/desktop_background_controller_test_api.h',
'shell/keyboard_controller_proxy_stub.cc',
'shell/keyboard_controller_proxy_stub.h',
'shell/toplevel_window.cc',
diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
index 7305586..fe111c0 100644
--- a/ash/desktop_background/desktop_background_controller.cc
+++ b/ash/desktop_background/desktop_background_controller.cc
@@ -24,7 +24,6 @@
#include "base/synchronization/cancellation_flag.h"
#include "base/threading/worker_pool.h"
#include "content/public/browser/browser_thread.h"
-#include "grit/ash_resources.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
@@ -44,127 +43,14 @@ const int kWallpaperReloadDelayMs = 2000;
} // namespace
-const int kSmallWallpaperMaxWidth = 1366;
-const int kSmallWallpaperMaxHeight = 800;
-const int kLargeWallpaperMaxWidth = 2560;
-const int kLargeWallpaperMaxHeight = 1700;
-const int kWallpaperThumbnailWidth = 108;
-const int kWallpaperThumbnailHeight = 68;
-
-// DesktopBackgroundController::WallpaperLoader wraps background wallpaper
-// loading.
-class DesktopBackgroundController::WallpaperLoader
- : public base::RefCountedThreadSafe<
- DesktopBackgroundController::WallpaperLoader> {
- public:
- // If set, |file_path| must be a trusted (i.e. read-only,
- // non-user-controlled) file containing a JPEG image.
- WallpaperLoader(const base::FilePath& file_path,
- WallpaperLayout file_layout,
- int resource_id,
- WallpaperLayout resource_layout)
- : file_path_(file_path),
- file_layout_(file_layout),
- resource_id_(resource_id),
- resource_layout_(resource_layout) {
- }
-
- void LoadOnWorkerPoolThread() {
- DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (cancel_flag_.IsSet())
- return;
-
- if (!file_path_.empty()) {
- VLOG(1) << "Loading " << file_path_.value();
- file_bitmap_ = LoadSkBitmapFromJPEGFile(file_path_);
- }
-
- if (cancel_flag_.IsSet())
- return;
-
- if (file_bitmap_) {
- gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(*file_bitmap_);
- wallpaper_resizer_.reset(new WallpaperResizer(
- image, GetMaxDisplaySizeInNative(), file_layout_));
- } else {
- wallpaper_resizer_.reset(new WallpaperResizer(
- resource_id_, GetMaxDisplaySizeInNative(), resource_layout_));
- }
- }
-
- const base::FilePath& file_path() const { return file_path_; }
- int resource_id() const { return resource_id_; }
-
- void Cancel() {
- cancel_flag_.Set();
- }
-
- bool IsCanceled() {
- return cancel_flag_.IsSet();
- }
-
- WallpaperResizer* ReleaseWallpaperResizer() {
- return wallpaper_resizer_.release();
- }
-
- private:
- friend class base::RefCountedThreadSafe<
- DesktopBackgroundController::WallpaperLoader>;
-
- // Loads a JPEG image from |path|, a trusted file -- note that the image
- // is not loaded in a sandboxed process. Returns an empty pointer on
- // error.
- static scoped_ptr<SkBitmap> LoadSkBitmapFromJPEGFile(
- const base::FilePath& path) {
- std::string data;
- if (!base::ReadFileToString(path, &data)) {
- LOG(ERROR) << "Unable to read data from " << path.value();
- return scoped_ptr<SkBitmap>();
- }
-
- scoped_ptr<SkBitmap> bitmap(gfx::JPEGCodec::Decode(
- reinterpret_cast<const unsigned char*>(data.data()), data.size()));
- if (!bitmap)
- LOG(ERROR) << "Unable to decode JPEG data from " << path.value();
- return bitmap.Pass();
- }
-
- ~WallpaperLoader() {}
-
- base::CancellationFlag cancel_flag_;
-
- // Bitmap loaded from |file_path_|.
- scoped_ptr<SkBitmap> file_bitmap_;
-
- scoped_ptr<WallpaperResizer> wallpaper_resizer_;
-
- // Path to a trusted JPEG file.
- base::FilePath file_path_;
-
- // Layout to be used when displaying the image from |file_path_|.
- WallpaperLayout file_layout_;
-
- // ID of an image resource to use if |file_path_| is empty or unloadable.
- int resource_id_;
-
- // Layout to be used when displaying |resource_id_|.
- WallpaperLayout resource_layout_;
-
- DISALLOW_COPY_AND_ASSIGN(WallpaperLoader);
-};
-
DesktopBackgroundController::DesktopBackgroundController()
- : command_line_for_testing_(NULL),
- locked_(false),
+ : locked_(false),
desktop_background_mode_(BACKGROUND_NONE),
- current_default_wallpaper_resource_id_(-1),
- weak_ptr_factory_(this),
wallpaper_reload_delay_(kWallpaperReloadDelayMs) {
Shell::GetInstance()->display_controller()->AddObserver(this);
}
DesktopBackgroundController::~DesktopBackgroundController() {
- CancelDefaultWallpaperLoader();
Shell::GetInstance()->display_controller()->RemoveObserver(this);
}
@@ -207,80 +93,44 @@ void DesktopBackgroundController::OnRootWindowAdded(aura::Window* root_window) {
InstallDesktopController(root_window);
}
-bool DesktopBackgroundController::SetDefaultWallpaper(bool is_guest) {
- VLOG(1) << "SetDefaultWallpaper: is_guest=" << is_guest;
- const bool use_large =
- GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE;
-
- base::FilePath file_path;
- WallpaperLayout file_layout = use_large ? WALLPAPER_LAYOUT_CENTER_CROPPED :
- WALLPAPER_LAYOUT_CENTER;
- int resource_id = use_large ? IDR_AURA_WALLPAPER_DEFAULT_LARGE :
- IDR_AURA_WALLPAPER_DEFAULT_SMALL;
- WallpaperLayout resource_layout = WALLPAPER_LAYOUT_TILE;
-
- CommandLine* command_line = command_line_for_testing_ ?
- command_line_for_testing_ : CommandLine::ForCurrentProcess();
- const char* switch_name = NULL;
- if (is_guest) {
- switch_name = use_large ? switches::kAshGuestWallpaperLarge :
- switches::kAshGuestWallpaperSmall;
- } else {
- switch_name = use_large ? switches::kAshDefaultWallpaperLarge :
- switches::kAshDefaultWallpaperSmall;
- }
- file_path = command_line->GetSwitchValuePath(switch_name);
+bool DesktopBackgroundController::SetWallpaperImage(const gfx::ImageSkia& image,
+ WallpaperLayout layout) {
+ VLOG(1) << "SetWallpaper: image_id=" << WallpaperResizer::GetImageId(image)
+ << " layout=" << layout;
- if (DefaultWallpaperIsAlreadyLoadingOrLoaded(file_path, resource_id)) {
- VLOG(1) << "Default wallpaper is already loading or loaded";
+ if (WallpaperIsAlreadyLoaded(&image, kInvalidResourceID, layout)) {
+ VLOG(1) << "Wallpaper is already loaded";
return false;
}
- CancelDefaultWallpaperLoader();
- default_wallpaper_loader_ = new WallpaperLoader(
- file_path, file_layout, resource_id, resource_layout);
- base::WorkerPool::PostTaskAndReply(
- FROM_HERE,
- base::Bind(&WallpaperLoader::LoadOnWorkerPoolThread,
- default_wallpaper_loader_),
- base::Bind(&DesktopBackgroundController::OnDefaultWallpaperLoadCompleted,
- weak_ptr_factory_.GetWeakPtr(),
- default_wallpaper_loader_),
- true /* task_is_slow */);
+ current_wallpaper_.reset(
+ new WallpaperResizer(image, GetMaxDisplaySizeInNative(), layout));
+ current_wallpaper_->StartResize();
+
+ FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver,
+ observers_,
+ OnWallpaperDataChanged());
+ SetDesktopBackgroundImageMode();
return true;
}
-void DesktopBackgroundController::SetCustomWallpaper(
- const gfx::ImageSkia& image,
- WallpaperLayout layout) {
- VLOG(1) << "SetCustomWallpaper: image_id="
- << WallpaperResizer::GetImageId(image) << " layout=" << layout;
- CancelDefaultWallpaperLoader();
+bool DesktopBackgroundController::SetWallpaperResource(int resource_id,
+ WallpaperLayout layout) {
+ VLOG(1) << "SetWallpaper: resource_id=" << resource_id
+ << " layout=" << layout;
- if (CustomWallpaperIsAlreadyLoaded(image)) {
- VLOG(1) << "Custom wallpaper is already loaded";
- return;
+ if (WallpaperIsAlreadyLoaded(NULL, resource_id, layout)) {
+ VLOG(1) << "Wallpaper is already loaded";
+ return false;
}
-
- current_wallpaper_.reset(new WallpaperResizer(
- image, GetMaxDisplaySizeInNative(), layout));
+ current_wallpaper_.reset(
+ new WallpaperResizer(resource_id, GetMaxDisplaySizeInNative(), layout));
current_wallpaper_->StartResize();
- current_default_wallpaper_path_ = base::FilePath();
- current_default_wallpaper_resource_id_ = -1;
-
FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
OnWallpaperDataChanged());
SetDesktopBackgroundImageMode();
-}
-
-void DesktopBackgroundController::CancelDefaultWallpaperLoader() {
- // Set canceled flag of previous request to skip unneeded loading.
- if (default_wallpaper_loader_.get())
- default_wallpaper_loader_->Cancel();
-
- // Cancel reply callback for previous request.
- weak_ptr_factory_.InvalidateWeakPtrs();
+ return true;
}
void DesktopBackgroundController::CreateEmptyWallpaper() {
@@ -288,14 +138,6 @@ void DesktopBackgroundController::CreateEmptyWallpaper() {
SetDesktopBackgroundImageMode();
}
-WallpaperResolution DesktopBackgroundController::GetAppropriateResolution() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- gfx::Size size = GetMaxDisplaySizeInNative();
- return (size.width() > kSmallWallpaperMaxWidth ||
- size.height() > kSmallWallpaperMaxHeight) ?
- WALLPAPER_RESOLUTION_LARGE : WALLPAPER_RESOLUTION_SMALL;
-}
-
bool DesktopBackgroundController::MoveDesktopToLockedContainer() {
if (locked_)
return false;
@@ -327,23 +169,44 @@ void DesktopBackgroundController::OnDisplayConfigurationChanged() {
}
}
-bool DesktopBackgroundController::DefaultWallpaperIsAlreadyLoadingOrLoaded(
- const base::FilePath& image_file,
- int image_resource_id) const {
- return (default_wallpaper_loader_.get() &&
- !default_wallpaper_loader_->IsCanceled() &&
- default_wallpaper_loader_->file_path() == image_file &&
- default_wallpaper_loader_->resource_id() == image_resource_id) ||
- (current_wallpaper_.get() &&
- current_default_wallpaper_path_ == image_file &&
- current_default_wallpaper_resource_id_ == image_resource_id);
+// static
+gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() {
+ int width = 0;
+ int height = 0;
+ std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays();
+ DisplayManager* display_manager = Shell::GetInstance()->display_manager();
+
+ for (std::vector<gfx::Display>::iterator iter = displays.begin();
+ iter != displays.end(); ++iter) {
+ // Don't use size_in_pixel because we want to use the native pixel size.
+ gfx::Size size_in_pixel =
+ display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size();
+ if (iter->rotation() == gfx::Display::ROTATE_90 ||
+ iter->rotation() == gfx::Display::ROTATE_270) {
+ size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width());
+ }
+ width = std::max(size_in_pixel.width(), width);
+ height = std::max(size_in_pixel.height(), height);
+ }
+ return gfx::Size(width, height);
}
-bool DesktopBackgroundController::CustomWallpaperIsAlreadyLoaded(
- const gfx::ImageSkia& image) const {
- return current_wallpaper_.get() &&
- (WallpaperResizer::GetImageId(image) ==
- current_wallpaper_->original_image_id());
+bool DesktopBackgroundController::WallpaperIsAlreadyLoaded(
+ const gfx::ImageSkia* image,
+ int resource_id,
+ WallpaperLayout layout) const {
+ if (!current_wallpaper_.get())
+ return false;
+
+ if (layout != current_wallpaper_->layout())
+ return false;
+
+ if (image) {
+ return WallpaperResizer::GetImageId(*image) ==
+ current_wallpaper_->original_image_id();
+ }
+
+ return current_wallpaper_->resource_id() == resource_id;
}
void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
@@ -351,22 +214,6 @@ void DesktopBackgroundController::SetDesktopBackgroundImageMode() {
InstallDesktopControllerForAllWindows();
}
-void DesktopBackgroundController::OnDefaultWallpaperLoadCompleted(
- scoped_refptr<WallpaperLoader> loader) {
- VLOG(1) << "OnDefaultWallpaperLoadCompleted";
- current_wallpaper_.reset(loader->ReleaseWallpaperResizer());
- current_wallpaper_->StartResize();
- current_default_wallpaper_path_ = loader->file_path();
- current_default_wallpaper_resource_id_ = loader->resource_id();
- FOR_EACH_OBSERVER(DesktopBackgroundControllerObserver, observers_,
- OnWallpaperDataChanged());
-
- SetDesktopBackgroundImageMode();
-
- DCHECK(loader.get() == default_wallpaper_loader_.get());
- default_wallpaper_loader_ = NULL;
-}
-
void DesktopBackgroundController::InstallDesktopController(
aura::Window* root_window) {
DesktopBackgroundWidgetController* component = NULL;
@@ -443,32 +290,8 @@ int DesktopBackgroundController::GetBackgroundContainerId(bool locked) {
void DesktopBackgroundController::UpdateWallpaper() {
current_wallpaper_.reset(NULL);
- current_default_wallpaper_path_ = base::FilePath();
- current_default_wallpaper_resource_id_ = -1;
ash::Shell::GetInstance()->user_wallpaper_delegate()->
UpdateWallpaper(true /* clear cache */);
}
-// static
-gfx::Size DesktopBackgroundController::GetMaxDisplaySizeInNative() {
- int width = 0;
- int height = 0;
- std::vector<gfx::Display> displays = Shell::GetScreen()->GetAllDisplays();
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
-
- for (std::vector<gfx::Display>::iterator iter = displays.begin();
- iter != displays.end(); ++iter) {
- // Don't use size_in_pixel because we want to use the native pixel size.
- gfx::Size size_in_pixel =
- display_manager->GetDisplayInfo(iter->id()).bounds_in_native().size();
- if (iter->rotation() == gfx::Display::ROTATE_90 ||
- iter->rotation() == gfx::Display::ROTATE_270) {
- size_in_pixel = gfx::Size(size_in_pixel.height(), size_in_pixel.width());
- }
- width = std::max(size_in_pixel.width(), width);
- height = std::max(size_in_pixel.height(), height);
- }
- return gfx::Size(width, height);
-}
-
} // namespace ash
diff --git a/ash/desktop_background/desktop_background_controller.h b/ash/desktop_background/desktop_background_controller.h
index 505f744..219e3c8 100644
--- a/ash/desktop_background/desktop_background_controller.h
+++ b/ash/desktop_background/desktop_background_controller.h
@@ -23,10 +23,6 @@ namespace aura {
class Window;
}
-namespace base {
-class CommandLine;
-}
-
namespace ash {
enum WallpaperLayout {
@@ -43,34 +39,17 @@ enum WallpaperLayout {
WALLPAPER_LAYOUT_TILE,
};
-enum WallpaperResolution {
- WALLPAPER_RESOLUTION_LARGE,
- WALLPAPER_RESOLUTION_SMALL
-};
-
const SkColor kLoginWallpaperColor = 0xFEFEFE;
-// The width and height of small/large resolution wallpaper. When screen size is
-// smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the
-// small resolution wallpaper should be used. Otherwise, uses the large
-// resolution wallpaper.
-ASH_EXPORT extern const int kSmallWallpaperMaxWidth;
-ASH_EXPORT extern const int kSmallWallpaperMaxHeight;
-ASH_EXPORT extern const int kLargeWallpaperMaxWidth;
-ASH_EXPORT extern const int kLargeWallpaperMaxHeight;
-
-// The width and heigh of wallpaper thumbnails.
-ASH_EXPORT extern const int kWallpaperThumbnailWidth;
-ASH_EXPORT extern const int kWallpaperThumbnailHeight;
-
class DesktopBackgroundControllerObserver;
class WallpaperResizer;
-// Loads selected desktop wallpaper from file system asynchronously and updates
-// background layer if loaded successfully.
+// Updates background layer if necessary.
class ASH_EXPORT DesktopBackgroundController
: public DisplayController::Observer {
public:
+ class TestAPI;
+
enum BackgroundMode {
BACKGROUND_NONE,
BACKGROUND_IMAGE,
@@ -83,10 +62,6 @@ class ASH_EXPORT DesktopBackgroundController
return desktop_background_mode_;
}
- void set_command_line_for_testing(base::CommandLine* command_line) {
- command_line_for_testing_ = command_line;
- }
-
// Add/Remove observers.
void AddObserver(DesktopBackgroundControllerObserver* observer);
void RemoveObserver(DesktopBackgroundControllerObserver* observer);
@@ -100,18 +75,13 @@ class ASH_EXPORT DesktopBackgroundController
// Initialize root window's background.
void OnRootWindowAdded(aura::Window* root_window);
- // Loads builtin wallpaper asynchronously and sets to current wallpaper
- // after loaded. Returns true if the controller started loading the
- // wallpaper and false otherwise (i.e. the appropriate wallpaper was
- // already loading or loaded).
- bool SetDefaultWallpaper(bool is_guest);
-
- // Sets the user selected custom wallpaper. Called when user selected a file
- // from file system or changed the layout of wallpaper.
- void SetCustomWallpaper(const gfx::ImageSkia& image, WallpaperLayout layout);
-
- // Cancels |default_wallpaper_loader_| if non-NULL.
- void CancelDefaultWallpaperLoader();
+ // Sets wallpaper. This is mostly called by WallpaperManager to set
+ // the default or user selected custom wallpaper.
+ // Returns true if new image was actually set. And false when duplicate set
+ // request detected.
+ bool SetWallpaperImage(const gfx::ImageSkia& image, WallpaperLayout layout);
+ // The same, but image from resources is used.
+ bool SetWallpaperResource(int resource_id, WallpaperLayout layout);
// Creates an empty wallpaper. Some tests require a wallpaper widget is ready
// when running. However, the wallpaper widgets are now created
@@ -121,9 +91,6 @@ class ASH_EXPORT DesktopBackgroundController
// crashes. An example test is SystemGestureEventFilterTest.ThreeFingerSwipe.
void CreateEmptyWallpaper();
- // Returns the appropriate wallpaper resolution for all root windows.
- WallpaperResolution GetAppropriateResolution();
-
// Move all desktop widgets to locked container.
// Returns true if the desktop moved.
bool MoveDesktopToLockedContainer();
@@ -135,30 +102,28 @@ class ASH_EXPORT DesktopBackgroundController
// Overrides DisplayController::Observer:
virtual void OnDisplayConfigurationChanged() OVERRIDE;
+ // Returns the maximum size of all displays combined in native
+ // resolutions. Note that this isn't the bounds of the display who
+ // has maximum resolutions. Instead, this returns the size of the
+ // maximum width of all displays, and the maximum height of all displays.
+ static gfx::Size GetMaxDisplaySizeInNative();
+
private:
friend class DesktopBackgroundControllerTest;
+ // friend class chromeos::WallpaperManagerBrowserTestDefaultWallpaper;
FRIEND_TEST_ALL_PREFIXES(DesktopBackgroundControllerTest, GetMaxDisplaySize);
- // An operation to asynchronously loads wallpaper.
- class WallpaperLoader;
-
- // Returns true if the specified default wallpaper is already being
- // loaded by |wallpaper_loader_| or stored in |current_wallpaper_|.
- bool DefaultWallpaperIsAlreadyLoadingOrLoaded(
- const base::FilePath& image_file, int image_resource_id) const;
-
- // Returns true if the specified custom wallpaper is already stored
+ // Returns true if the specified wallpaper is already stored
// in |current_wallpaper_|.
- bool CustomWallpaperIsAlreadyLoaded(const gfx::ImageSkia& image) const;
+ // If |image| is NULL, resource_id is compared.
+ bool WallpaperIsAlreadyLoaded(const gfx::ImageSkia* image,
+ int resource_id,
+ WallpaperLayout layout) const;
// Creates view for all root windows, or notifies them to repaint if they
// already exist.
void SetDesktopBackgroundImageMode();
- // Creates a new background widget and sets the background mode to image mode.
- // Called after a default wallpaper has been loaded successfully.
- void OnDefaultWallpaperLoadCompleted(scoped_refptr<WallpaperLoader> loader);
-
// Creates and adds component for current mode (either Widget or Layer) to
// |root_window|.
void InstallDesktopController(aura::Window* root_window);
@@ -184,15 +149,6 @@ class ASH_EXPORT DesktopBackgroundController
wallpaper_reload_delay_ = value;
}
- // Returns the maximum size of all displays combined in native
- // resolutions. Note that this isn't the bounds of the display who
- // has maximum resolutions. Instead, this returns the size of the
- // maximum width of all displays, and the maximum height of all displays.
- static gfx::Size GetMaxDisplaySizeInNative();
-
- // If non-NULL, used in place of the real command line.
- base::CommandLine* command_line_for_testing_;
-
// Can change at runtime.
bool locked_;
@@ -205,19 +161,8 @@ class ASH_EXPORT DesktopBackgroundController
// The current wallpaper.
scoped_ptr<WallpaperResizer> current_wallpaper_;
- // If a default wallpaper is stored in |current_wallpaper_|, the path and
- // resource ID that were passed to WallpaperLoader when loading it.
- // Otherwise, empty and -1, respectively.
- base::FilePath current_default_wallpaper_path_;
- int current_default_wallpaper_resource_id_;
-
gfx::Size current_max_display_size_;
- // Loads default wallpaper from disk.
- scoped_refptr<WallpaperLoader> default_wallpaper_loader_;
-
- base::WeakPtrFactory<DesktopBackgroundController> weak_ptr_factory_;
-
base::OneShotTimer<DesktopBackgroundController> timer_;
int wallpaper_reload_delay_;
diff --git a/ash/desktop_background/desktop_background_controller_test_api.cc b/ash/desktop_background/desktop_background_controller_test_api.cc
new file mode 100644
index 0000000..5bb7c0d
--- /dev/null
+++ b/ash/desktop_background/desktop_background_controller_test_api.cc
@@ -0,0 +1,19 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/desktop_background/desktop_background_controller_test_api.h"
+
+namespace ash {
+
+DesktopBackgroundController::TestAPI::TestAPI(
+ DesktopBackgroundController* controller)
+ : controller_(controller) {
+}
+
+void DesktopBackgroundController::TestAPI::set_wallpaper_reload_delay_for_test(
+ bool value) {
+ controller_->set_wallpaper_reload_delay_for_test(value);
+}
+
+} // namespace ash
diff --git a/ash/desktop_background/desktop_background_controller_test_api.h b/ash/desktop_background/desktop_background_controller_test_api.h
new file mode 100644
index 0000000..1fc28df
--- /dev/null
+++ b/ash/desktop_background/desktop_background_controller_test_api.h
@@ -0,0 +1,24 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_TEST_API_H_
+#define ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_TEST_API_H_
+
+#include "ash/desktop_background/desktop_background_controller.h"
+
+namespace ash {
+
+class DesktopBackgroundController::TestAPI {
+ public:
+ explicit TestAPI(DesktopBackgroundController* controller);
+
+ void set_wallpaper_reload_delay_for_test(bool value);
+
+ private:
+ DesktopBackgroundController* controller_;
+};
+
+} // namespace ash
+
+#endif // ASH_DESKTOP_BACKGROUND_DESKTOP_BACKGROUND_CONTROLLER_TEST_API_H_
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc
index bdfc578..53a90eb 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;
@@ -52,31 +44,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) {
@@ -101,8 +68,7 @@ void RunAnimationForWidget(views::Widget* widget) {
class DesktopBackgroundControllerTest : public test::AshTestBase {
public:
DesktopBackgroundControllerTest()
- : command_line_(CommandLine::NO_PROGRAM),
- controller_(NULL) {
+ : controller_(NULL) {
}
virtual ~DesktopBackgroundControllerTest() {}
@@ -121,22 +87,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_;
@@ -438,168 +276,6 @@ TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) {
root_window_controller->wallpaper_controller());
}
-TEST_F(DesktopBackgroundControllerTest, DisplayChange) {
- // TODO(derat|oshima|bshe): Host windows can't be resized on Win8.
- if (!SupportsHostWindowResize())
- return;
-
- // Set the wallpaper to ensure that UpdateWallpaper() will be called when the
- // display configuration changes.
- gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
- wallpaper_delegate_->set_custom_wallpaper(image);
- controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
-
- // Small wallpaper images should be used for configurations less than or
- // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if
- // multiple displays are connected.
- test::DisplayManagerTestApi display_manager_test_api(
- Shell::GetInstance()->display_manager());
- display_manager_test_api.UpdateDisplay("800x600");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- display_manager_test_api.UpdateDisplay("800x600,800x600");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- display_manager_test_api.UpdateDisplay("1366x800");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- // At larger sizes, large wallpapers should be used.
- display_manager_test_api.UpdateDisplay("1367x800");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- display_manager_test_api.UpdateDisplay("1367x801");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- display_manager_test_api.UpdateDisplay("2560x1700");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- // Rotated smaller screen may use larger image.
- display_manager_test_api.UpdateDisplay("800x600/r");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- display_manager_test_api.UpdateDisplay("800x600/r,800x600");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
- display_manager_test_api.UpdateDisplay("1366x800/r");
- RunAllPendingInMessageLoop();
- EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
- controller_->GetAppropriateResolution());
- EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
-
- // Max display size didn't chagne.
- display_manager_test_api.UpdateDisplay("900x800/r,400x1366");
- RunAllPendingInMessageLoop();
- 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())
return;
@@ -612,7 +288,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_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH);
EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper()));
content::BrowserThread::GetBlockingPool()->FlushForTesting();
content::RunAllPendingInMessageLoop();
@@ -623,7 +299,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_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH);
content::BrowserThread::GetBlockingPool()->FlushForTesting();
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper()));
@@ -670,27 +346,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
diff --git a/ash/desktop_background/wallpaper_resizer.cc b/ash/desktop_background/wallpaper_resizer.cc
index 06d8c97..46497b2 100644
--- a/ash/desktop_background/wallpaper_resizer.cc
+++ b/ash/desktop_background/wallpaper_resizer.cc
@@ -93,6 +93,8 @@ void Resize(SkBitmap orig_bitmap,
} // namespace
+const int kInvalidResourceID = -1;
+
// static
uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(1.0f);
@@ -102,9 +104,11 @@ uint32_t WallpaperResizer::GetImageId(const gfx::ImageSkia& image) {
WallpaperResizer::WallpaperResizer(int image_resource_id,
const gfx::Size& target_size,
WallpaperLayout layout)
- : image_(*(ui::ResourceBundle::GetSharedInstance().
- GetImageNamed(image_resource_id).ToImageSkia())),
+ : image_(*(ui::ResourceBundle::GetSharedInstance()
+ .GetImageNamed(image_resource_id)
+ .ToImageSkia())),
original_image_id_(GetImageId(image_)),
+ resource_id_(image_resource_id),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
@@ -116,6 +120,7 @@ WallpaperResizer::WallpaperResizer(const gfx::ImageSkia& image,
WallpaperLayout layout)
: image_(image),
original_image_id_(GetImageId(image_)),
+ resource_id_(kInvalidResourceID),
target_size_(target_size),
layout_(layout),
weak_ptr_factory_(this) {
diff --git a/ash/desktop_background/wallpaper_resizer.h b/ash/desktop_background/wallpaper_resizer.h
index fadfb44..2b867994 100644
--- a/ash/desktop_background/wallpaper_resizer.h
+++ b/ash/desktop_background/wallpaper_resizer.h
@@ -18,6 +18,8 @@ namespace ash {
class WallpaperResizerObserver;
+extern const int kInvalidResourceID;
+
// Stores the current wallpaper data and resize it to |target_size| if needed.
class ASH_EXPORT WallpaperResizer {
public:
@@ -40,6 +42,8 @@ class ASH_EXPORT WallpaperResizer {
uint32_t original_image_id() const { return original_image_id_; }
WallpaperLayout layout() const { return layout_; }
+ int resource_id() const { return resource_id_; }
+
// Called on the UI thread to run Resize() on the worker pool and post an
// OnResizeFinished() task back to the UI thread on completion.
void StartResize();
@@ -63,6 +67,9 @@ class ASH_EXPORT WallpaperResizer {
// Unique identifier corresponding to the original (i.e. pre-resize) |image_|.
uint32_t original_image_id_;
+ // kInvalidResourceID if image was not obtained from resources.
+ const int resource_id_;
+
gfx::Size target_size_;
WallpaperLayout layout_;
diff --git a/ash/shell/content_client/shell_browser_main_parts.cc b/ash/shell/content_client/shell_browser_main_parts.cc
index 7a745c6..7223920 100644
--- a/ash/shell/content_client/shell_browser_main_parts.cc
+++ b/ash/shell/content_client/shell_browser_main_parts.cc
@@ -134,9 +134,6 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
ash::shell::InitWindowTypeLauncher();
- Shell::GetInstance()->desktop_background_controller()->SetDefaultWallpaper(
- false /* is_guest */);
-
ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
}
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 21bbbd7..49f1d08 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -207,22 +207,12 @@ aura::test::EventGenerator& AshTestBase::GetEventGenerator() {
return *event_generator_.get();
}
-// static
bool AshTestBase::SupportsMultipleDisplays() {
-#if defined(OS_WIN)
- return base::win::GetVersion() < base::win::VERSION_WIN8;
-#else
- return true;
-#endif
+ return AshTestHelper::SupportsMultipleDisplays();
}
-// static
bool AshTestBase::SupportsHostWindowResize() {
-#if defined(OS_WIN)
- return base::win::GetVersion() < base::win::VERSION_WIN8;
-#else
- return true;
-#endif
+ return AshTestHelper::SupportsHostWindowResize();
}
void AshTestBase::UpdateDisplay(const std::string& display_specs) {
diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h
index 193e71a..4ac828e 100644
--- a/ash/test/ash_test_base.h
+++ b/ash/test/ash_test_base.h
@@ -102,12 +102,10 @@ class AshTestBase : public testing::Test {
NUMBER_OF_BLOCK_REASONS
};
- // True if the running environment supports multiple displays,
- // or false otherwise (e.g. win8 bot).
+ // Proxy to AshTestHelper::SupportsMultipleDisplays().
static bool SupportsMultipleDisplays();
- // True if the running environment supports host window resize,
- // or false otherwise (e.g. win8 bot).
+ // Proxy to AshTestHelper::SupportsHostWindowResize().
static bool SupportsHostWindowResize();
void set_start_session(bool start_session) { start_session_ = start_session; }
diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc
index f66c6ce..75034c5 100644
--- a/ash/test/ash_test_helper.cc
+++ b/ash/test/ash_test_helper.cc
@@ -30,6 +30,10 @@
#include "ui/keyboard/keyboard.h"
#endif
+#if defined(OS_WIN)
+#include "base/win/windows_version.h"
+#endif
+
#if defined(USE_X11)
#include "ui/aura/window_tree_host_x11.h"
#endif
@@ -147,5 +151,23 @@ aura::Window* AshTestHelper::CurrentContext() {
return root_window;
}
+// static
+bool AshTestHelper::SupportsMultipleDisplays() {
+#if defined(OS_WIN)
+ return base::win::GetVersion() < base::win::VERSION_WIN8;
+#else
+ return true;
+#endif
+}
+
+// static
+bool AshTestHelper::SupportsHostWindowResize() {
+#if defined(OS_WIN)
+ return base::win::GetVersion() < base::win::VERSION_WIN8;
+#else
+ return true;
+#endif
+}
+
} // namespace test
} // namespace ash
diff --git a/ash/test/ash_test_helper.h b/ash/test/ash_test_helper.h
index 39ab10d..6fb266f 100644
--- a/ash/test/ash_test_helper.h
+++ b/ash/test/ash_test_helper.h
@@ -61,6 +61,14 @@ class AshTestHelper {
return test_screenshot_delegate_;
}
+ // True if the running environment supports multiple displays,
+ // or false otherwise (e.g. win8 bot).
+ static bool SupportsMultipleDisplays();
+
+ // True if the running environment supports host window resize,
+ // or false otherwise (e.g. win8 bot).
+ static bool SupportsHostWindowResize();
+
private:
base::MessageLoopForUI* message_loop_; // Not owned.
TestShellDelegate* test_shell_delegate_; // Owned by ash::Shell.
diff --git a/ash/test/test_user_wallpaper_delegate.cc b/ash/test/test_user_wallpaper_delegate.cc
index 24ab287e..050f635 100644
--- a/ash/test/test_user_wallpaper_delegate.cc
+++ b/ash/test/test_user_wallpaper_delegate.cc
@@ -18,7 +18,7 @@ TestUserWallpaperDelegate::~TestUserWallpaperDelegate() {}
void TestUserWallpaperDelegate::UpdateWallpaper(bool clear_cache) {
DefaultUserWallpaperDelegate::UpdateWallpaper(clear_cache);
if (!custom_wallpaper_.isNull()) {
- Shell::GetInstance()->desktop_background_controller()->SetCustomWallpaper(
+ Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
custom_wallpaper_, WALLPAPER_LAYOUT_STRETCH);
}
update_wallpaper_count_++;
diff --git a/chrome/browser/chromeos/extensions/wallpaper_api.cc b/chrome/browser/chromeos/extensions/wallpaper_api.cc
index c60a458..1c9e50a 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_api.cc
@@ -176,9 +176,10 @@ void WallpaperSetWallpaperFunction::GenerateThumbnail(
chromeos::WallpaperManager::Get()->ResizeWallpaper(
wallpaper,
ash::WALLPAPER_LAYOUT_STRETCH,
- ash::kWallpaperThumbnailWidth,
- ash::kWallpaperThumbnailHeight,
- &data);
+ chromeos::kWallpaperThumbnailWidth,
+ chromeos::kWallpaperThumbnailHeight,
+ &data,
+ NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
diff --git a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
index fa4c567..5a58f08 100644
--- a/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
+++ b/chrome/browser/chromeos/extensions/wallpaper_private_api.cc
@@ -293,15 +293,15 @@ bool WallpaperPrivateSetWallpaperIfExistsFunction::RunImpl() {
base::FilePath wallpaper_path;
base::FilePath fallback_path;
- ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
- desktop_background_controller()->GetAppropriateResolution();
+ chromeos::WallpaperManager::WallpaperResolution resolution =
+ chromeos::WallpaperManager::GetAppropriateResolution();
std::string file_name = GURL(params->url).ExtractFileName();
CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS,
&wallpaper_path));
fallback_path = wallpaper_path.Append(file_name);
if (params->layout != wallpaper_private::WALLPAPER_LAYOUT_STRETCH &&
- resolution == ash::WALLPAPER_RESOLUTION_SMALL) {
+ resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name).InsertBeforeExtension(
chromeos::kSmallWallpaperSuffix).value();
}
@@ -444,8 +444,9 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
wallpaper,
file_path,
ash::WALLPAPER_LAYOUT_CENTER_CROPPED,
- ash::kSmallWallpaperMaxWidth,
- ash::kSmallWallpaperMaxHeight);
+ chromeos::kSmallWallpaperMaxWidth,
+ chromeos::kSmallWallpaperMaxHeight,
+ NULL);
} else {
std::string error = base::StringPrintf(
"Failed to create/write wallpaper to %s.", file_name.c_str());
@@ -586,9 +587,10 @@ void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
chromeos::WallpaperManager::Get()->ResizeWallpaper(
wallpaper,
ash::WALLPAPER_LAYOUT_STRETCH,
- ash::kWallpaperThumbnailWidth,
- ash::kWallpaperThumbnailHeight,
- &data);
+ chromeos::kWallpaperThumbnailWidth,
+ chromeos::kWallpaperThumbnailHeight,
+ &data,
+ NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc
index 6c0f2bc..d59ae0a 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc
@@ -7,6 +7,8 @@
#include <numeric>
#include <vector>
+#include "ash/ash_switches.h"
+#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
@@ -39,6 +41,7 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
+#include "grit/ash_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/image/image_skia_operations.h"
@@ -46,6 +49,8 @@
using content::BrowserThread;
+namespace chromeos {
+
namespace {
// The amount of delay before starts to move custom wallpapers to the new place.
@@ -114,8 +119,6 @@ bool MoveCustomWallpaperDirectory(const char* sub_dir,
} // namespace
-namespace chromeos {
-
const char kWallpaperSequenceTokenName[] = "wallpaper-sequence";
const char kSmallWallpaperSuffix[] = "_small";
@@ -126,6 +129,13 @@ const char kLargeWallpaperSubDir[] = "large";
const char kOriginalWallpaperSubDir[] = "original";
const char kThumbnailWallpaperSubDir[] = "thumb";
+const int kSmallWallpaperMaxWidth = 1366;
+const int kSmallWallpaperMaxHeight = 800;
+const int kLargeWallpaperMaxWidth = 2560;
+const int kLargeWallpaperMaxHeight = 1700;
+const int kWallpaperThumbnailWidth = 108;
+const int kWallpaperThumbnailHeight = 68;
+
static WallpaperManager* g_wallpaper_manager = NULL;
// This object is passed between several threads while wallpaper is being
@@ -208,9 +218,9 @@ void WallpaperManager::PendingWallpaper::ProcessRequest() {
if (default_) {
manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass());
} else if (!user_wallpaper_.isNull()) {
- ash::Shell::GetInstance()->
- desktop_background_controller()->
- SetCustomWallpaper(user_wallpaper_, info_.layout);
+ ash::Shell::GetInstance()
+ ->desktop_background_controller()
+ ->SetWallpaperImage(user_wallpaper_, info_.layout);
} else if (!wallpaper_path_.empty()) {
manager->task_runner_->PostTask(
FROM_HERE,
@@ -306,6 +316,8 @@ WallpaperManager::WallpaperManager()
should_cache_wallpaper_(false),
weak_factory_(this),
pending_inactive_(NULL) {
+ SetDefaultWallpaperPathsFromCommandLine(
+ base::CommandLine::ForCurrentProcess());
registrar_.Add(this,
chrome::NOTIFICATION_LOGIN_USER_CHANGED,
content::NotificationService::AllSources());
@@ -432,7 +444,7 @@ void WallpaperManager::InitializeWallpaper() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
UserManager* user_manager = UserManager::Get();
- CommandLine* command_line = GetComandLine();
+ CommandLine* command_line = GetCommandLine();
if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
// Guest wallpaper should be initialized when guest login.
// Note: This maybe called before login. So IsLoggedInAsGuest can not be
@@ -477,7 +489,7 @@ void WallpaperManager::Observe(int type,
break;
}
case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: {
- if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) {
+ if (!GetCommandLine()->HasSwitch(switches::kDisableBootAnimation)) {
BrowserThread::PostDelayedTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&WallpaperManager::CacheUsersWallpapers,
@@ -520,7 +532,8 @@ bool WallpaperManager::ResizeWallpaper(
ash::WallpaperLayout layout,
int preferred_width,
int preferred_height,
- scoped_refptr<base::RefCountedBytes>* output) const {
+ scoped_refptr<base::RefCountedBytes>* output,
+ gfx::ImageSkia* output_skia) const {
DCHECK(BrowserThread::GetBlockingPool()->
IsRunningSequenceOnCurrentThread(sequence_token_));
int width = wallpaper.image().width();
@@ -567,27 +580,39 @@ bool WallpaperManager::ResizeWallpaper(
image.height(),
image.width() * image.bytesPerPixel(),
kDefaultEncodingQuality, &(*output)->data());
+
+ if (output_skia) {
+ resized_image.MakeThreadSafe();
+ *output_skia = resized_image;
+ }
+
return true;
}
-void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper,
- const base::FilePath& path,
- ash::WallpaperLayout layout,
- int preferred_width,
- int preferred_height) const {
+bool WallpaperManager::ResizeAndSaveWallpaper(
+ const UserImage& wallpaper,
+ const base::FilePath& path,
+ ash::WallpaperLayout layout,
+ int preferred_width,
+ int preferred_height,
+ gfx::ImageSkia* result_out) const {
if (layout == ash::WALLPAPER_LAYOUT_CENTER) {
// TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
if (base::PathExists(path))
base::DeleteFile(path, false);
- return;
+ return false;
}
scoped_refptr<base::RefCountedBytes> data;
- if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height,
- &data)) {
- SaveWallpaperInternal(path,
- reinterpret_cast<const char*>(data->front()),
- data->size());
+ if (ResizeWallpaper(wallpaper,
+ layout,
+ preferred_width,
+ preferred_height,
+ &data,
+ result_out)) {
+ return SaveWallpaperInternal(
+ path, reinterpret_cast<const char*>(data->front()), data->size());
}
+ return false;
}
bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const {
@@ -628,6 +653,18 @@ void WallpaperManager::OnPolicyFetched(const std::string& policy,
user_id));
}
+// static
+WallpaperManager::WallpaperResolution
+WallpaperManager::GetAppropriateResolution() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ gfx::Size size =
+ ash::DesktopBackgroundController::GetMaxDisplaySizeInNative();
+ return (size.width() > kSmallWallpaperMaxWidth ||
+ size.height() > kSmallWallpaperMaxHeight)
+ ? WALLPAPER_RESOLUTION_LARGE
+ : WALLPAPER_RESOLUTION_SMALL;
+}
+
void WallpaperManager::SetPolicyControlledWallpaper(
const std::string& user_id,
const UserImage& wallpaper) {
@@ -742,9 +779,43 @@ void WallpaperManager::DoSetDefaultWallpaper(
// up the tests.
if (!ash::Shell::HasInstance())
return;
- if (ash::Shell::GetInstance()->desktop_background_controller()->
- SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest()))
- loaded_wallpapers_++;
+
+ WallpaperResolution resolution = GetAppropriateResolution();
+ const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL);
+
+ const base::FilePath* file = NULL;
+
+ if (UserManager::Get()->IsLoggedInAsGuest()) {
+ file =
+ use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_;
+ } else {
+ file = use_small ? &default_small_wallpaper_file_
+ : &default_large_wallpaper_file_;
+ }
+ const ash::WallpaperLayout layout =
+ use_small ? ash::WALLPAPER_LAYOUT_CENTER
+ : ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
+ DCHECK(file);
+ if (!default_wallpaper_image_.get() ||
+ default_wallpaper_image_->url().spec() != file->value()) {
+ default_wallpaper_image_.reset();
+ if (!file->empty()) {
+ loaded_wallpapers_++;
+ StartLoadAndSetDefaultWallpaper(
+ *file, layout, on_finish.Pass(), &default_wallpaper_image_);
+ return;
+ }
+
+ const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL
+ : IDR_AURA_WALLPAPER_DEFAULT_LARGE;
+
+ loaded_wallpapers_ += ash::Shell::GetInstance()
+ ->desktop_background_controller()
+ ->SetWallpaperResource(resource_id, layout);
+ return;
+ }
+ ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
+ default_wallpaper_image_->image(), layout);
}
void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id,
@@ -829,14 +900,7 @@ void WallpaperManager::ScheduleSetUserWallpaper(const std::string& user_id,
->ResetSetWallpaperImage(user_wallpaper, info);
} else {
if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
- ash::WallpaperResolution resolution =
- ash::Shell::GetInstance()->
- desktop_background_controller()->
- GetAppropriateResolution();
- const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL)
- ? kSmallWallpaperSubDir
- : kLargeWallpaperSubDir;
-
+ const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
// Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER.
// Original wallpaper should be used in this case.
// TODO(bshe): Generates cropped custom wallpaper for CENTER layout.
@@ -888,6 +952,7 @@ void WallpaperManager::SetWallpaperFromImageSkia(
}
void WallpaperManager::UpdateWallpaper(bool clear_cache) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting());
if (clear_cache)
wallpaper_cache_.clear();
current_wallpaper_path_.clear();
@@ -953,10 +1018,7 @@ void WallpaperManager::CacheUserWallpaper(const std::string& user_id) {
base::FilePath wallpaper_dir;
base::FilePath wallpaper_path;
if (info.type == User::CUSTOMIZED || info.type == User::POLICY) {
- ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
- desktop_background_controller()->GetAppropriateResolution();
- const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ?
- kSmallWallpaperSubDir : kLargeWallpaperSubDir;
+ const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution();
base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
wallpaper_path = wallpaper_path.Append(info.file);
task_runner_->PostTask(
@@ -1070,7 +1132,13 @@ void WallpaperManager::EnsureCustomWallpaperDirectories(
base::CreateDirectory(dir);
}
-CommandLine* WallpaperManager::GetComandLine() {
+void WallpaperManager::SetCommandLineForTesting(
+ base::CommandLine* command_line) {
+ command_line_for_testing_ = command_line;
+ SetDefaultWallpaperPathsFromCommandLine(command_line);
+}
+
+CommandLine* WallpaperManager::GetCommandLine() {
CommandLine* command_line = command_line_for_testing_ ?
command_line_for_testing_ : CommandLine::ForCurrentProcess();
return command_line;
@@ -1080,8 +1148,8 @@ void WallpaperManager::InitializeRegisteredDeviceWallpaper() {
if (UserManager::Get()->IsUserLoggedIn())
return;
- bool disable_boot_animation = GetComandLine()->
- HasSwitch(switches::kDisableBootAnimation);
+ bool disable_boot_animation =
+ GetCommandLine()->HasSwitch(switches::kDisableBootAnimation);
bool show_users = true;
bool result = CrosSettings::Get()->GetBoolean(
kAccountsPrefShowUserNamesOnSignIn, &show_users);
@@ -1110,12 +1178,11 @@ void WallpaperManager::LoadWallpaper(const std::string& user_id,
base::FilePath wallpaper_path;
if (info.type == User::ONLINE) {
std::string file_name = GURL(info.file).ExtractFileName();
- ash::WallpaperResolution resolution = ash::Shell::GetInstance()->
- desktop_background_controller()->GetAppropriateResolution();
+ WallpaperResolution resolution = GetAppropriateResolution();
// Only solid color wallpapers have stretch layout and they have only one
// resolution.
if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH &&
- resolution == ash::WALLPAPER_RESOLUTION_SMALL) {
+ resolution == WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name).InsertBeforeExtension(
kSmallWallpaperSuffix).value();
}
@@ -1323,8 +1390,9 @@ void WallpaperManager::OnWallpaperDecoded(
}
if (update_wallpaper) {
- ash::Shell::GetInstance()->desktop_background_controller()->
- SetCustomWallpaper(wallpaper.image(), layout);
+ ash::Shell::GetInstance()
+ ->desktop_background_controller()
+ ->SetWallpaperImage(wallpaper.image(), layout);
}
}
@@ -1359,19 +1427,27 @@ void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash,
// Re-encode orginal file to jpeg format and saves the result in case that
// resized wallpaper is not generated (i.e. chrome shutdown before resized
// wallpaper is saved).
- ResizeAndSaveWallpaper(wallpaper, original_path,
+ ResizeAndSaveWallpaper(wallpaper,
+ original_path,
ash::WALLPAPER_LAYOUT_STRETCH,
wallpaper.image().width(),
- wallpaper.image().height());
+ wallpaper.image().height(),
+ NULL);
DeleteAllExcept(original_path);
- ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout,
- ash::kSmallWallpaperMaxWidth,
- ash::kSmallWallpaperMaxHeight);
+ ResizeAndSaveWallpaper(wallpaper,
+ small_wallpaper_path,
+ layout,
+ kSmallWallpaperMaxWidth,
+ kSmallWallpaperMaxHeight,
+ NULL);
DeleteAllExcept(small_wallpaper_path);
- ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout,
- ash::kLargeWallpaperMaxWidth,
- ash::kLargeWallpaperMaxHeight);
+ ResizeAndSaveWallpaper(wallpaper,
+ large_wallpaper_path,
+ layout,
+ kLargeWallpaperMaxWidth,
+ kLargeWallpaperMaxHeight,
+ NULL);
DeleteAllExcept(large_wallpaper_path);
}
@@ -1380,11 +1456,11 @@ void WallpaperManager::RecordUma(User::WallpaperType type, int index) const {
User::WALLPAPER_TYPE_COUNT);
}
-void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path,
+bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path,
const char* data,
int size) const {
int written_bytes = base::WriteFile(path, data, size);
- DCHECK(written_bytes == size);
+ return written_bytes == size;
}
void WallpaperManager::StartLoad(const std::string& user_id,
@@ -1457,4 +1533,51 @@ WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
return pending_inactive_;
}
+void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine(
+ base::CommandLine* command_line) {
+ default_small_wallpaper_file_ = command_line->GetSwitchValuePath(
+ ash::switches::kAshDefaultWallpaperSmall);
+ default_large_wallpaper_file_ = command_line->GetSwitchValuePath(
+ ash::switches::kAshDefaultWallpaperLarge);
+ guest_small_wallpaper_file_ =
+ command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall);
+ guest_large_wallpaper_file_ =
+ command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge);
+ default_wallpaper_image_.reset();
+}
+
+void WallpaperManager::OnDefaultWallpaperDecoded(
+ const base::FilePath& path,
+ const ash::WallpaperLayout layout,
+ scoped_ptr<chromeos::UserImage>* result_out,
+ MovableOnDestroyCallbackHolder on_finish,
+ const UserImage& wallpaper) {
+ result_out->reset(new UserImage(wallpaper.image()));
+ (*result_out)->set_url(GURL(path.value()));
+ ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
+ wallpaper.image(), layout);
+}
+
+void WallpaperManager::StartLoadAndSetDefaultWallpaper(
+ const base::FilePath& path,
+ const ash::WallpaperLayout layout,
+ MovableOnDestroyCallbackHolder on_finish,
+ scoped_ptr<chromeos::UserImage>* result_out) {
+ wallpaper_loader_->Start(
+ path.value(),
+ 0, // Do not crop.
+ base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded,
+ weak_factory_.GetWeakPtr(),
+ path,
+ layout,
+ base::Unretained(result_out),
+ base::Passed(on_finish.Pass())));
+}
+
+const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() {
+ WallpaperResolution resolution = GetAppropriateResolution();
+ return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir
+ : kLargeWallpaperSubDir;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/wallpaper_manager.h b/chrome/browser/chromeos/login/wallpaper_manager.h
index 203e35f..2dae2fa 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.h
+++ b/chrome/browser/chromeos/login/wallpaper_manager.h
@@ -68,10 +68,28 @@ extern const char kLargeWallpaperSubDir[];
extern const char kOriginalWallpaperSubDir[];
extern const char kThumbnailWallpaperSubDir[];
+// The width and height of small/large resolution wallpaper. When screen size is
+// smaller than |kSmallWallpaperMaxWidth| and |kSmallWallpaperMaxHeight|, the
+// small resolution wallpaper should be used. Otherwise, use the large
+// resolution wallpaper.
+extern const int kSmallWallpaperMaxWidth;
+extern const int kSmallWallpaperMaxHeight;
+extern const int kLargeWallpaperMaxWidth;
+extern const int kLargeWallpaperMaxHeight;
+
+// The width and height of wallpaper thumbnails.
+extern const int kWallpaperThumbnailWidth;
+extern const int kWallpaperThumbnailHeight;
+
// This class maintains wallpapers for users who have logged into this Chrome
// OS device.
class WallpaperManager: public content::NotificationObserver {
public:
+ enum WallpaperResolution {
+ WALLPAPER_RESOLUTION_LARGE,
+ WALLPAPER_RESOLUTION_SMALL
+ };
+
// For testing.
class TestApi {
public:
@@ -98,6 +116,7 @@ class WallpaperManager: public content::NotificationObserver {
public:
virtual ~Observer() {}
virtual void OnWallpaperAnimationFinished(const std::string& user_id) = 0;
+ virtual void OnUpdateWallpaperForTesting() {}
};
// This is "wallpaper either scheduled to load, or loading right now".
@@ -171,9 +190,7 @@ class WallpaperManager: public content::NotificationObserver {
WallpaperManager();
virtual ~WallpaperManager();
- void set_command_line_for_testing(base::CommandLine* command_line) {
- command_line_for_testing_ = command_line;
- }
+ void SetCommandLineForTesting(base::CommandLine* command_line);
// Indicates imminent shutdown, allowing the WallpaperManager to remove any
// observers it has registered.
@@ -224,16 +241,19 @@ class WallpaperManager: public content::NotificationObserver {
ash::WallpaperLayout layout,
int preferred_width,
int preferred_height,
- scoped_refptr<base::RefCountedBytes>* output) const;
+ scoped_refptr<base::RefCountedBytes>* output,
+ gfx::ImageSkia* output_skia) const;
// Resizes |wallpaper| to a resolution which is nearest to |preferred_width|
// and |preferred_height| while maintaining aspect ratio. And saves the
- // resized wallpaper to |path|.
- void ResizeAndSaveWallpaper(const UserImage& wallpaper,
+ // resized wallpaper to |path|. |result| is optional (may be NULL).
+ // Returns true on success.
+ bool ResizeAndSaveWallpaper(const UserImage& wallpaper,
const base::FilePath& path,
ash::WallpaperLayout layout,
int preferred_width,
- int preferred_height) const;
+ int preferred_height,
+ gfx::ImageSkia* result_out) const;
// Saves custom wallpaper to file, post task to generate thumbnail and updates
// local state preferences. If |update_wallpaper| is false, don't change
@@ -305,9 +325,13 @@ class WallpaperManager: public content::NotificationObserver {
const std::string& user_id,
scoped_ptr<std::string> data);
+ // Returns the appropriate wallpaper resolution for all root windows.
+ static WallpaperResolution GetAppropriateResolution();
+
private:
friend class TestApi;
friend class WallpaperManagerBrowserTest;
+ friend class WallpaperManagerBrowserTestDefaultWallpaper;
friend class WallpaperManagerPolicyTest;
typedef std::map<std::string, gfx::ImageSkia> CustomWallpaperMap;
@@ -356,7 +380,7 @@ class WallpaperManager: public content::NotificationObserver {
void EnsureCustomWallpaperDirectories(const std::string& user_id_hash);
// Gets the CommandLine representing the current process's command line.
- base::CommandLine* GetComandLine();
+ base::CommandLine* GetCommandLine();
// Initialize wallpaper of registered device after device policy is trusted.
// Note that before device is enrolled, it proceeds with untrusted setting.
@@ -427,7 +451,9 @@ class WallpaperManager: public content::NotificationObserver {
const UserImage& wallpaper);
// Saves wallpaper image raw |data| to |path| (absolute path) in file system.
- void SaveWallpaperInternal(const base::FilePath& path, const char* data,
+ // True on success.
+ bool SaveWallpaperInternal(const base::FilePath& path,
+ const char* data,
int size) const;
// Creates new PendingWallpaper request (or updates currently pending).
@@ -464,6 +490,26 @@ class WallpaperManager: public content::NotificationObserver {
// in zero delay.
base::TimeDelta GetWallpaperLoadDelay() const;
+ // Init |*default_*_wallpaper_file_| from given command line and
+ // clear |default_wallpaper_image_|.
+ void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line);
+
+ // Sets wallpaper to decoded default.
+ void OnDefaultWallpaperDecoded(const base::FilePath& path,
+ const ash::WallpaperLayout layout,
+ scoped_ptr<UserImage>* result,
+ MovableOnDestroyCallbackHolder on_finish,
+ const UserImage& wallpaper);
+
+ // Start decoding given default wallpaper.
+ void StartLoadAndSetDefaultWallpaper(const base::FilePath& path,
+ const ash::WallpaperLayout layout,
+ MovableOnDestroyCallbackHolder on_finish,
+ scoped_ptr<UserImage>* result_out);
+
+ // Returns wallpaper subdirectory name for current resolution.
+ const char* GetCustomWallpaperSubdirForCurrentResolution();
+
// The number of loaded wallpapers.
int loaded_wallpapers_;
@@ -520,6 +566,15 @@ class WallpaperManager: public content::NotificationObserver {
typedef std::vector<scoped_refptr<PendingWallpaper> > PendingList;
PendingList loading_;
+ base::FilePath default_small_wallpaper_file_;
+ base::FilePath default_large_wallpaper_file_;
+
+ base::FilePath guest_small_wallpaper_file_;
+ base::FilePath guest_large_wallpaper_file_;
+
+ // Current decoded default image is stored in cache.
+ scoped_ptr<UserImage> default_wallpaper_image_;
+
DISALLOW_COPY_AND_ASSIGN(WallpaperManager);
};
diff --git a/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc b/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc
index 821fd98..ccce769 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc
@@ -5,14 +5,21 @@
#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "ash/ash_resources/grit/ash_resources.h"
+#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/desktop_background/desktop_background_controller_observer.h"
+#include "ash/desktop_background/desktop_background_controller_test_api.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/test/ash_test_helper.h"
#include "ash/test/display_manager_test_api.h"
+#include "ash/test/test_user_wallpaper_delegate.h"
#include "base/command_line.h"
+#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/prefs/scoped_user_pref_update.h"
@@ -30,6 +37,9 @@
#include "content/public/test/test_utils.h"
#include "ui/aura/env.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/codec/jpeg_codec.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
using namespace ash;
@@ -41,9 +51,9 @@ const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE;
const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL;
int kLargeWallpaperWidth = 256;
-int kLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight;
+int kLargeWallpaperHeight = chromeos::kLargeWallpaperMaxHeight;
int kSmallWallpaperWidth = 256;
-int kSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight;
+int kSmallWallpaperHeight = chromeos::kSmallWallpaperMaxHeight;
const char kTestUser1[] = "test1@domain.com";
const char kTestUser1Hash[] = "test1@domain.com-hash";
@@ -53,7 +63,6 @@ const char kTestUser2Hash[] = "test2@domain.com-hash";
} // namespace
class WallpaperManagerBrowserTest : public InProcessBrowserTest,
- public DesktopBackgroundControllerObserver,
public testing::WithParamInterface<bool> {
public:
WallpaperManagerBrowserTest () : controller_(NULL),
@@ -64,8 +73,9 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest,
virtual void SetUpOnMainThread() OVERRIDE {
controller_ = ash::Shell::GetInstance()->desktop_background_controller();
- controller_->AddObserver(this);
local_state_ = g_browser_process->local_state();
+ DesktopBackgroundController::TestAPI(controller_)
+ .set_wallpaper_reload_delay_for_test(0);
UpdateDisplay("800x600");
}
@@ -77,7 +87,6 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest,
}
virtual void CleanUpOnMainThread() OVERRIDE {
- controller_->RemoveObserver(this);
controller_ = NULL;
}
@@ -90,22 +99,34 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest,
}
void WaitAsyncWallpaperLoadStarted() {
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
void WaitAsyncWallpaperLoadFinished() {
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
while (WallpaperManager::Get()->loading_.size()) {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
- base::MessageLoop::current()->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
}
- virtual void OnWallpaperDataChanged() OVERRIDE {
- base::MessageLoop::current()->Quit();
- }
-
protected:
+ // Colors used for different default wallpapers by
+ // WriteWallpapers().
+ 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;
+
// Return custom wallpaper path. Create directory if not exist.
base::FilePath GetCustomWallpaperPath(const char* sub_dir,
const std::string& username_hash,
@@ -143,8 +164,148 @@ class WallpaperManagerBrowserTest : public InProcessBrowserTest,
return WallpaperManager::Get()->loaded_wallpapers();
}
+ // Creates a test image of size 1x1.
+ gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ bitmap.allocPixels();
+ bitmap.eraseColor(color);
+ return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+ }
+
+ // 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 default wallpaper paths "*default_*file" and writes JPEG
+ // wallpaper images to them.
+ // Only needs to be called (once) by tests that want to test loading of
+ // default wallpapers.
+ void WriteWallpapers() {
+ wallpaper_dir_.reset(new base::ScopedTempDir);
+ ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir());
+
+ std::vector<std::string> options;
+ options.push_back(std::string("WM_Test_cmdline"));
+ const base::FilePath small_file =
+ wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg"));
+ options.push_back(std::string("--") +
+ ash::switches::kAshDefaultWallpaperSmall + "=" +
+ small_file.value());
+ const base::FilePath large_file =
+ wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg"));
+ options.push_back(std::string("--") +
+ ash::switches::kAshDefaultWallpaperLarge + "=" +
+ large_file.value());
+ const base::FilePath guest_small_file =
+ wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg"));
+ options.push_back(std::string("--") +
+ ash::switches::kAshGuestWallpaperSmall + "=" +
+ guest_small_file.value());
+ const base::FilePath guest_large_file =
+ wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg"));
+ options.push_back(std::string("--") +
+ ash::switches::kAshGuestWallpaperLarge + "=" +
+ guest_large_file.value());
+
+ ASSERT_TRUE(WriteJPEGFile(small_file,
+ kWallpaperSize,
+ kWallpaperSize,
+ kSmallWallpaperColor));
+ ASSERT_TRUE(WriteJPEGFile(large_file,
+ kWallpaperSize,
+ kWallpaperSize,
+ kLargeWallpaperColor));
+ ASSERT_TRUE(WriteJPEGFile(guest_small_file,
+ kWallpaperSize,
+ kWallpaperSize,
+ kSmallGuestWallpaperColor));
+ ASSERT_TRUE(WriteJPEGFile(guest_large_file,
+ kWallpaperSize,
+ kWallpaperSize,
+ kLargeGuestWallpaperColor));
+
+ wallpaper_manager_command_line_.reset(new base::CommandLine(options));
+ WallpaperManager::Get()->SetCommandLineForTesting(
+ wallpaper_manager_command_line_.get());
+ }
+
+ // 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;
+ }
+
DesktopBackgroundController* controller_;
PrefService* local_state_;
+ scoped_ptr<base::CommandLine> wallpaper_manager_command_line_;
+
+ // Directory created by WriteWallpapersAndSetFlags() to store default
+ // wallpaper images.
+ scoped_ptr<base::ScopedTempDir> wallpaper_dir_;
private:
DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest);
@@ -195,7 +356,7 @@ IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,
// Hook up another 800x600 display. This shouldn't trigger a reload.
UpdateDisplay("800x600,800x600");
- content::RunAllPendingInMessageLoop();
+ WaitAsyncWallpaperLoadFinished();
// The small resolution custom wallpaper is expected.
EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width());
EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height());
@@ -570,4 +731,217 @@ INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation,
WallpaperManagerBrowserTestCacheUpdate,
testing::Bool());
+// ----------------------------------------------------------------------
+// Test default wallpapers.
+
+class TestObserver : public WallpaperManager::Observer {
+ public:
+ explicit TestObserver(WallpaperManager* wallpaper_manager)
+ : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) {
+ DCHECK(wallpaper_manager_);
+ wallpaper_manager_->AddObserver(this);
+ }
+
+ virtual ~TestObserver() {
+ wallpaper_manager_->RemoveObserver(this);
+ }
+
+ virtual void OnWallpaperAnimationFinished(const std::string&) OVERRIDE {
+ }
+
+ virtual void OnUpdateWallpaperForTesting() OVERRIDE {
+ ++update_wallpaper_count_;
+ }
+
+ int GetUpdateWallpaperCountAndReset() {
+ const size_t old = update_wallpaper_count_;
+ update_wallpaper_count_ = 0;
+ return old;
+ }
+
+ private:
+ int update_wallpaper_count_;
+ WallpaperManager* wallpaper_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestObserver);
+};
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, DisplayChange) {
+ // TODO(derat|oshima|bshe): Host windows can't be resized on Win8.
+ if (!ash::test::AshTestHelper::SupportsHostWindowResize())
+ return;
+
+ TestObserver observer(WallpaperManager::Get());
+
+ // Set the wallpaper to ensure that UpdateWallpaper() will be called when the
+ // display configuration changes.
+ gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor);
+ controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH);
+
+ // Small wallpaper images should be used for configurations less than or
+ // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if
+ // multiple displays are connected.
+ UpdateDisplay("800x600");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset());
+
+ UpdateDisplay("800x600,800x600");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset());
+
+ UpdateDisplay("1366x800");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ // At larger sizes, large wallpapers should be used.
+ UpdateDisplay("1367x800");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ UpdateDisplay("1367x801");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ UpdateDisplay("2560x1700");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ // Rotated smaller screen may use larger image.
+ UpdateDisplay("800x600/r");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ UpdateDisplay("800x600/r,800x600");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+ UpdateDisplay("1366x800/r");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE,
+ WallpaperManager::Get()->GetAppropriateResolution());
+ EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset());
+
+ // Max display size didn't chagne.
+ UpdateDisplay("900x800/r,400x1366");
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset());
+}
+
+// Test that WallpaperManager 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
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallDefaultWallpaper) {
+ if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
+ return;
+
+ WriteWallpapers();
+
+ // At 800x600, the small wallpaper should be loaded.
+ UpdateDisplay("800x600");
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor));
+}
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeDefaultWallpaper) {
+ if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
+ return;
+
+ WriteWallpapers();
+ UpdateDisplay("1600x1200");
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor));
+}
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,
+ LargeDefaultWallpaperWhenRotated) {
+ if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
+ return;
+ WriteWallpapers();
+
+ UpdateDisplay("1200x800/r");
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor));
+}
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallGuestWallpaper) {
+ if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
+ return;
+ WriteWallpapers();
+ UserManager::Get()->UserLoggedIn(
+ UserManager::kGuestUserName, UserManager::kGuestUserName, false);
+ UpdateDisplay("800x600");
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kSmallGuestWallpaperColor));
+}
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeGuestWallpaper) {
+ if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
+ return;
+
+ WriteWallpapers();
+ UserManager::Get()->UserLoggedIn(
+ UserManager::kGuestUserName, UserManager::kGuestUserName, false);
+ UpdateDisplay("1600x1200");
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kLargeGuestWallpaperColor));
+}
+
+IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest,
+ SwitchBetweenDefaultAndCustom) {
+ // Start loading the default wallpaper.
+ UpdateDisplay("640x480");
+ WriteWallpapers();
+ UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false);
+
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+
+ // Custom wallpaper should be applied immediately, canceling the default
+ // wallpaper load task.
+ gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor);
+ UserImage wallpaper(image);
+ WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser,
+ "test_hash",
+ "test-nofile.jpeg",
+ WALLPAPER_LAYOUT_STRETCH,
+ User::CUSTOMIZED,
+ wallpaper,
+ true);
+ WaitAsyncWallpaperLoadFinished();
+
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor));
+
+ WallpaperManager::Get()->SetDefaultWallpaperNow(std::string());
+ WaitAsyncWallpaperLoadFinished();
+
+ EXPECT_TRUE(
+ ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor));
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc b/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc
index c477456..e07a95d 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager_unittest.cc
@@ -7,10 +7,15 @@
#include "ash/ash_resources/grit/ash_resources.h"
#include "ash/desktop_background/desktop_background_controller.h"
+#include "ash/desktop_background/desktop_background_controller_observer.h"
#include "ash/shell.h"
#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/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_service.h"
@@ -20,6 +25,7 @@
#include "chrome/browser/chromeos/login/wallpaper_manager.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chromeos/chromeos_switches.h"
@@ -27,111 +33,12 @@
#include "chromeos/settings/cros_settings_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
using namespace ash;
-const char kTestUser1[] = "test-user@example.com";
-const char kTestUser1Hash[] = "test-user@example.com-hash";
-
namespace chromeos {
-class WallpaperManagerTest : public test::AshTestBase {
- public:
- WallpaperManagerTest() : command_line_(CommandLine::NO_PROGRAM) {}
-
- virtual ~WallpaperManagerTest() {}
-
- virtual void SetUp() OVERRIDE {
- test::AshTestBase::SetUp();
-
- // Register an in-memory local settings instance.
- local_state_.reset(new TestingPrefServiceSimple);
- TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get());
- UserManager::RegisterPrefs(local_state_->registry());
- // Wallpaper manager and user image managers prefs will be accessed by the
- // unit-test as well.
- UserImageManager::RegisterPrefs(local_state_->registry());
- WallpaperManager::RegisterPrefs(local_state_->registry());
-
- StartupUtils::RegisterPrefs(local_state_->registry());
- StartupUtils::MarkDeviceRegistered();
-
- ResetUserManager();
- }
-
- virtual void TearDown() OVERRIDE {
- // Unregister the in-memory local settings instance.
- TestingBrowserProcess::GetGlobal()->SetLocalState(0);
-
- // Shut down the DeviceSettingsService.
- DeviceSettingsService::Get()->UnsetSessionManager();
-
- test::AshTestBase::TearDown();
- }
-
- void ResetUserManager() {
- // Reset the UserManager singleton.
- user_manager_enabler_.reset();
- // Initialize the UserManager singleton to a fresh UserManagerImpl instance.
- user_manager_enabler_.reset(
- new ScopedUserManagerEnabler(new UserManagerImpl));
- }
-
- void AppendGuestSwitch() {
- command_line_.AppendSwitch(switches::kGuestSession);
- WallpaperManager::Get()->set_command_line_for_testing(&command_line_);
- }
-
- void WaitAsyncWallpaperLoad() {
- base::MessageLoop::current()->RunUntilIdle();
- }
-
- protected:
- CommandLine command_line_;
-
- scoped_ptr<TestingPrefServiceSimple> local_state_;
-
- ScopedTestDeviceSettingsService test_device_settings_service_;
- ScopedTestCrosSettings test_cros_settings_;
-
- scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WallpaperManagerTest);
-};
-
-// Test for crbug.com/260755. If this test fails, it is probably because the
-// wallpaper of last logged in user is set as guest wallpaper.
-TEST_F(WallpaperManagerTest, GuestUserUseGuestWallpaper) {
- UserManager::Get()->UserLoggedIn(kTestUser1, kTestUser1Hash, false);
-
- std::string relative_path =
- base::FilePath(kTestUser1Hash).Append(FILE_PATH_LITERAL("DUMMY")).value();
- // Saves wallpaper info to local state for user |kTestUser1|.
- WallpaperInfo info = {
- relative_path,
- WALLPAPER_LAYOUT_CENTER_CROPPED,
- User::CUSTOMIZED,
- base::Time::Now().LocalMidnight()
- };
- WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
- ResetUserManager();
-
- AppendGuestSwitch();
- scoped_ptr<WallpaperManager::TestApi> test_api;
- test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get()));
- // If last logged in user's wallpaper is used in function InitializeWallpaper,
- // this test will crash. InitializeWallpaper should be a noop after
- // AppendGuestSwitch being called.
- WallpaperManager::Get()->InitializeWallpaper();
- EXPECT_TRUE(test_api->current_wallpaper_path().empty());
- UserManager::Get()->UserLoggedIn(UserManager::kGuestUserName,
- UserManager::kGuestUserName, false);
- WaitAsyncWallpaperLoad();
- EXPECT_FALSE(ash::Shell::GetInstance()->desktop_background_controller()->
- SetDefaultWallpaper(true));
-}
-
class WallpaperManagerCacheTest : public test::AshTestBase {
public:
WallpaperManagerCacheTest()
diff --git a/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc b/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc
index c058b59..92ce758 100644
--- a/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc
+++ b/chrome/browser/ui/ash/user_wallpaper_delegate_win.cc
@@ -58,8 +58,9 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
}
#endif
gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
- ash::Shell::GetInstance()->desktop_background_controller()->
- SetCustomWallpaper(wallpaper, ash::WALLPAPER_LAYOUT_TILE);
+ ash::Shell::GetInstance()
+ ->desktop_background_controller()
+ ->SetWallpaperImage(wallpaper, ash::WALLPAPER_LAYOUT_TILE);
}
virtual void InitializeWallpaper() OVERRIDE {