Commit cac62e3f authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

wallpaper refactoring: Move SetDefaultWallpaper to WallpaperController

1) Emphasize the default wallpaper selection order in
   DoSetDefaultWallpaper (renamed to SetDefaultWallpaperImpl).
   Create two additional member variables to store the customized
   default wallpaper file paths to make the distinction with a regular
   default wallpaper (ie. from the command line). Previously, these
   two are mixed in the code.

2) Rename |SetDefaultWallpaperPath| to
   |SetCustomizedDefaultWallpaperImpl|.

3) |SetDefaultWallpaperPathsFromCommandLine| is removed. We don't have
   the need to cache the values which come from the command line.

TBR=oshima@chromium.org, ochang@chromium.org

Test: Manual (device/Linux build), ash_unittests, browser tests
Bug: 792233
Change-Id: I09876e23ea7609c7b7e876d4daf79c4fa35088c5
Reviewed-on: https://chromium-review.googlesource.com/808092Reviewed-by: default avatarWenzhao (Colin) Zang <wzang@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarOliver Chang <ochang@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523324}
parent b2a17033
......@@ -80,7 +80,7 @@ interface WallpaperController {
// Sets wallpaper from policy or from a local file. Saves the custom wallpaper
// to file, posts task to generate thumbnail and updates local state.
// |user_info|: The user's information related to wallpaper.
// |wallpaper_files_id|: The unique id of each wallpaper file.
// |wallpaper_files_id|: The file id for user_info.account_id.
// |file_name|: The name of the wallpaper file.
// |layout|: The layout of the wallpaper, used for wallpaper resizing.
// |type|: The type of the wallpaper, e.g., default, policy etc.
......@@ -111,9 +111,13 @@ interface WallpaperController {
bool show_wallpaper);
// Sets the user's wallpaper to be the default wallpaper. Note: different user
// types may have different default wallpapers. If |show_wallpaper| is false,
// don't show the default wallpaper now.
SetDefaultWallpaper(WallpaperUserInfo user_info, bool show_wallpaper);
// types may have different default wallpapers.
// |wallpaper_files_id|: The file id for user_info.account_id.
// |show_wallpaper|: If false, don't show the new wallpaper now but only
// update cache.
SetDefaultWallpaper(WallpaperUserInfo user_info,
string wallpaper_files_id,
bool show_wallpaper);
// Sets a customized default wallpaper to be used wherever a default wallpaper
// is needed. Note: it doesn't change the default wallpaper for guest and
......@@ -139,7 +143,7 @@ interface WallpaperController {
ShowSigninWallpaper();
// Removes all of the user's saved wallpapers and related info.
// |wallpaper_files_id|: The unique id of each wallpaper file.
// |wallpaper_files_id|: The file id for user_info.account_id.
RemoveUserWallpaper(WallpaperUserInfo user_info, string wallpaper_files_id);
// TODO(crbug.com/776464): This is only used by WallpaperManager. Remove this
......
This diff is collapsed.
This diff is collapsed.
......@@ -229,7 +229,7 @@ void ArcWallpaperService::SetDefaultWallpaper() {
// ImageDecoder::ImageRequest.
decode_request_.reset();
const PrimaryAccount& account = GetPrimaryAccount();
chromeos::WallpaperManager::Get()->SetDefaultWallpaper(
WallpaperControllerClient::Get()->SetDefaultWallpaper(
account.id, account.is_active /* show_wallpaper */);
}
......
......@@ -144,10 +144,10 @@ class ArcWallpaperServiceTest : public ash::AshTestBase {
protected:
arc::ArcWallpaperService* service_ = nullptr;
std::unique_ptr<arc::FakeWallpaperInstance> wallpaper_instance_ = nullptr;
private:
std::unique_ptr<WallpaperControllerClient> wallpaper_controller_client_;
TestWallpaperController test_wallpaper_controller_;
private:
chromeos::FakeChromeUserManager* const user_manager_ = nullptr;
user_manager::ScopedUserManager user_manager_enabler_;
arc::ArcServiceManager arc_service_manager_;
......@@ -161,12 +161,10 @@ class ArcWallpaperServiceTest : public ash::AshTestBase {
} // namespace
TEST_F(ArcWallpaperServiceTest, SetDefaultWallpaper) {
test_wallpaper_controller_.ClearCounts();
service_->SetDefaultWallpaper();
RunAllPendingInMessageLoop();
// Wait until wallpaper loading is done.
chromeos::wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
ASSERT_EQ(1u, wallpaper_instance_->changed_ids().size());
EXPECT_EQ(-1, wallpaper_instance_->changed_ids()[0]);
wallpaper_controller_client_->FlushForTesting();
EXPECT_EQ(1, test_wallpaper_controller_.set_default_wallpaper_count());
}
TEST_F(ArcWallpaperServiceTest, SetAndGetWallpaper) {
......
......@@ -8,8 +8,8 @@
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ash/wallpaper/wallpaper_controller_observer.h"
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/time/time.h"
......@@ -56,32 +56,30 @@ const char kServicesManifest[] =
// Expected minimal wallpaper download retry interval in milliseconds.
const int kDownloadRetryIntervalMS = 100;
class TestWallpaperObserver : public WallpaperManager::Observer {
class TestWallpaperObserver : public ash::WallpaperControllerObserver {
public:
explicit TestWallpaperObserver(WallpaperManager* wallpaper_manager)
: finished_(false),
wallpaper_manager_(wallpaper_manager) {
DCHECK(wallpaper_manager_);
wallpaper_manager_->AddObserver(this);
explicit TestWallpaperObserver(ash::WallpaperController* wallpaper_controller)
: finished_(false), wallpaper_controller_(wallpaper_controller) {
wallpaper_controller_->AddObserver(this);
}
~TestWallpaperObserver() override {
wallpaper_manager_->RemoveObserver(this);
wallpaper_controller_->RemoveObserver(this);
}
void OnWallpaperAnimationFinished(const AccountId&) override {
void OnWallpaperDataChanged() override {
finished_ = true;
base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void WaitForWallpaperAnimationFinished() {
void WaitForWallpaperDataChanged() {
while (!finished_)
base::RunLoop().Run();
}
private:
bool finished_;
WallpaperManager* wallpaper_manager_;
ash::WallpaperController* wallpaper_controller_;
DISALLOW_COPY_AND_ASSIGN(TestWallpaperObserver);
};
......@@ -191,7 +189,7 @@ class WallpaperImageFetcherFactory {
SkColor color,
const size_t require_retries) {
std::vector<unsigned char> oem_wallpaper_;
ASSERT_TRUE(wallpaper_manager_test_utils::CreateJPEGImage(
ASSERT_TRUE(ash::WallpaperController::CreateJPEGImageForTesting(
width, height, color, &oem_wallpaper_));
url_callback_.reset(new TestWallpaperImageURLFetcherCallback(
......@@ -226,81 +224,59 @@ class CustomizationWallpaperDownloaderBrowserTest
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
}
protected:
void CreateCmdlineWallpapers() {
cmdline_wallpaper_dir_.reset(new base::ScopedTempDir);
ASSERT_TRUE(cmdline_wallpaper_dir_->CreateUniqueTempDir());
wallpaper_manager_test_utils::CreateCmdlineWallpapers(
*cmdline_wallpaper_dir_, &wallpaper_manager_command_line_);
}
std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_;
// Directory created by CreateCmdlineWallpapersAndSetFlags() to store default
// wallpaper images.
std::unique_ptr<base::ScopedTempDir> cmdline_wallpaper_dir_;
private:
DISALLOW_COPY_AND_ASSIGN(CustomizationWallpaperDownloaderBrowserTest);
};
IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
OEMWallpaperIsPresent) {
CreateCmdlineWallpapers();
WallpaperManager::Get()->SetDefaultWallpaper(EmptyAccountId(),
true /* update_wallpaper */);
wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
ash::Shell::Get()->wallpaper_controller()->GetWallpaper(),
wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
ash::WallpaperController* wallpaper_controller =
ash::Shell::Get()->wallpaper_controller();
wallpaper_controller->ShowDefaultWallpaperForTesting();
WallpaperImageFetcherFactory url_factory(
GURL(kOEMWallpaperURL),
GURL(kOEMWallpaperURL), wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kCustomWallpaperColor,
wallpaper_manager_test_utils::kLargeCustomWallpaperColor,
0 /* require_retries */);
TestWallpaperObserver observer(WallpaperManager::Get());
TestWallpaperObserver observer(wallpaper_controller);
chromeos::ServicesCustomizationDocument* customization =
chromeos::ServicesCustomizationDocument::GetInstance();
EXPECT_TRUE(
customization->LoadManifestFromString(std::string(kServicesManifest)));
observer.WaitForWallpaperAnimationFinished();
observer.WaitForWallpaperDataChanged();
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
ash::Shell::Get()->wallpaper_controller()->GetWallpaper(),
wallpaper_manager_test_utils::kCustomWallpaperColor));
wallpaper_controller->GetWallpaper(),
wallpaper_manager_test_utils::kLargeCustomWallpaperColor));
EXPECT_EQ(1U, url_factory.num_attempts());
}
IN_PROC_BROWSER_TEST_F(CustomizationWallpaperDownloaderBrowserTest,
OEMWallpaperRetryFetch) {
CreateCmdlineWallpapers();
WallpaperManager::Get()->SetDefaultWallpaper(EmptyAccountId(),
true /* update_wallpaper */);
wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
ash::Shell::Get()->wallpaper_controller()->GetWallpaper(),
wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
ash::WallpaperController* wallpaper_controller =
ash::Shell::Get()->wallpaper_controller();
wallpaper_controller->ShowDefaultWallpaperForTesting();
WallpaperImageFetcherFactory url_factory(
GURL(kOEMWallpaperURL),
GURL(kOEMWallpaperURL), wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kWallpaperSize,
wallpaper_manager_test_utils::kCustomWallpaperColor,
wallpaper_manager_test_utils::kLargeCustomWallpaperColor,
1 /* require_retries */);
TestWallpaperObserver observer(WallpaperManager::Get());
TestWallpaperObserver observer(wallpaper_controller);
chromeos::ServicesCustomizationDocument* customization =
chromeos::ServicesCustomizationDocument::GetInstance();
EXPECT_TRUE(
customization->LoadManifestFromString(std::string(kServicesManifest)));
observer.WaitForWallpaperAnimationFinished();
observer.WaitForWallpaperDataChanged();
EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
ash::Shell::Get()->wallpaper_controller()->GetWallpaper(),
wallpaper_manager_test_utils::kCustomWallpaperColor));
wallpaper_controller->GetWallpaper(),
wallpaper_manager_test_utils::kLargeCustomWallpaperColor));
EXPECT_EQ(2U, url_factory.num_attempts());
}
......
......@@ -210,8 +210,9 @@ void WallpaperSetWallpaperFunction::GenerateThumbnail(
image->height(), &original_data, NULL);
chromeos::WallpaperManager::Get()->ResizeImage(
*image, wallpaper::WALLPAPER_LAYOUT_STRETCH,
chromeos::kWallpaperThumbnailWidth, chromeos::kWallpaperThumbnailHeight,
&thumbnail_data, NULL);
ash::WallpaperController::kWallpaperThumbnailWidth,
ash::WallpaperController::kWallpaperThumbnailHeight, &thumbnail_data,
NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(&WallpaperSetWallpaperFunction::ThumbnailGenerated, this,
......
......@@ -12,6 +12,7 @@
#include <vector>
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ash/wallpaper/wallpaper_window_state_manager.h"
#include "base/command_line.h"
#include "base/files/file_enumerator.h"
......@@ -278,15 +279,15 @@ bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() {
base::FilePath wallpaper_path;
base::FilePath fallback_path;
chromeos::WallpaperManager::WallpaperResolution resolution =
wallpaper_manager->GetAppropriateResolution();
ash::WallpaperController::WallpaperResolution resolution =
ash::WallpaperController::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_base::WALLPAPER_LAYOUT_STRETCH &&
resolution == chromeos::WallpaperManager::WALLPAPER_RESOLUTION_SMALL) {
resolution == ash::WallpaperController::WALLPAPER_RESOLUTION_SMALL) {
file_name = base::FilePath(file_name)
.InsertBeforeExtension(chromeos::kSmallWallpaperSuffix)
.value();
......@@ -417,8 +418,8 @@ void WallpaperPrivateSetWallpaperFunction::SaveToFile() {
// maintain the aspect ratio after resize.
chromeos::WallpaperManager::Get()->ResizeAndSaveWallpaper(
wallpaper_, file_path, wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED,
chromeos::kSmallWallpaperMaxWidth, chromeos::kSmallWallpaperMaxHeight,
NULL);
ash::WallpaperController::kSmallWallpaperMaxWidth,
ash::WallpaperController::kSmallWallpaperMaxHeight, NULL);
} else {
std::string error = base::StringPrintf(
"Failed to create/write wallpaper to %s.", file_name.c_str());
......@@ -460,12 +461,11 @@ bool WallpaperPrivateResetWallpaperFunction::RunAsync() {
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
// Do not change wallpaper if policy is in effect.
chromeos::WallpaperManager* wallpaper_manager =
chromeos::WallpaperManager::Get();
if (wallpaper_manager->IsPolicyControlled(account_id))
if (chromeos::WallpaperManager::Get()->IsPolicyControlled(account_id))
return false;
wallpaper_manager->SetDefaultWallpaper(account_id, true /* show_wallpaper */);
WallpaperControllerClient::Get()->SetDefaultWallpaper(
account_id, true /* show_wallpaper */);
Profile* profile = Profile::FromBrowserContext(browser_context());
// This API is only available to the component wallpaper picker. We do not
......@@ -548,8 +548,8 @@ void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail(
scoped_refptr<base::RefCountedBytes> data;
chromeos::WallpaperManager::Get()->ResizeImage(
*image, wallpaper::WALLPAPER_LAYOUT_STRETCH,
chromeos::kWallpaperThumbnailWidth, chromeos::kWallpaperThumbnailHeight,
&data, NULL);
ash::WallpaperController::kWallpaperThumbnailWidth,
ash::WallpaperController::kWallpaperThumbnailHeight, &data, NULL);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(
......
......@@ -69,29 +69,14 @@ extern const char kWallpaperSequenceTokenName[];
extern const char kSmallWallpaperSuffix[];
extern const char kLargeWallpaperSuffix[];
// 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;
class WallpaperManager : public content::NotificationObserver,
public wm::ActivationChangeObserver,
public aura::WindowObserver {
public:
class PendingWallpaper;
enum WallpaperResolution {
WALLPAPER_RESOLUTION_LARGE,
WALLPAPER_RESOLUTION_SMALL
};
using MovableOnDestroyCallbackHolder =
ash::WallpaperController::MovableOnDestroyCallbackHolder;
class CustomizedWallpaperRescaledFiles {
public:
......@@ -128,24 +113,6 @@ class WallpaperManager : public content::NotificationObserver,
DISALLOW_COPY_AND_ASSIGN(CustomizedWallpaperRescaledFiles);
};
// This object is passed between several threads while wallpaper is being
// loaded. It will notify callback when last reference to it is removed
// (thus indicating that the last load action has finished).
class MovableOnDestroyCallback {
public:
explicit MovableOnDestroyCallback(const base::Closure& callback);
~MovableOnDestroyCallback();
private:
base::Closure callback_;
DISALLOW_COPY_AND_ASSIGN(MovableOnDestroyCallback);
};
using MovableOnDestroyCallbackHolder =
std::unique_ptr<MovableOnDestroyCallback>;
class TestApi {
public:
explicit TestApi(WallpaperManager* wallpaper_manager);
......@@ -240,11 +207,6 @@ class WallpaperManager : public content::NotificationObserver,
const gfx::ImageSkia& image,
bool show_wallpaper);
// Sets |account_id|'s wallpaper to be the default wallpaper. Note: different
// user types may have different default wallpapers. If |show_wallpaper| is
// false, don't show the default wallpaper now.
void SetDefaultWallpaper(const AccountId& account_id, bool show_wallpaper);
// Sets a customized default wallpaper to be used wherever a default wallpaper
// is needed. Note: it doesn't change the default wallpaper for guest and
// child accounts.
......@@ -286,18 +248,12 @@ class WallpaperManager : public content::NotificationObserver,
// from gfx::ImageSkia by using WallpaperResizer::GetImageId().
bool IsPendingWallpaper(uint32_t image_id);
// Returns the appropriate wallpaper resolution for all root windows.
WallpaperResolution GetAppropriateResolution();
// Gets wallpaper information of logged in user.
bool GetLoggedInUserWallpaperInfo(wallpaper::WallpaperInfo* info);
// Adds |this| as an observer to various settings.
void AddObservers();
// Sets command line and initialize |*default_*_wallpaper_file_|.
void SetCommandLineForTesting(base::CommandLine* command_line);
// Loads wallpaper asynchronously if the current wallpaper is not the
// wallpaper of logged in user.
void EnsureLoggedInUserWallpaperLoaded();
......@@ -343,10 +299,6 @@ class WallpaperManager : public content::NotificationObserver,
// aura::WindowObserver:
void OnWindowDestroying(aura::Window* window) override;
// Shows the default wallpaper based on the user type of |account_id|. For
// testing purpose only.
void ShowDefaultWallpaperForTesting(const AccountId& account_id);
private:
friend class WallpaperManagerBrowserTest;
friend class WallpaperManagerBrowserTestDefaultWallpaper;
......@@ -390,8 +342,7 @@ class WallpaperManager : public content::NotificationObserver,
gfx::ImageSkia* small_wallpaper_image,
gfx::ImageSkia* large_wallpaper_image);
// Initialize wallpaper info for the user to default and saves the settings
// in local state.
// A wrapper of |WallpaperController::InitializeUserWallpaperInfo|.
void InitializeUserWallpaperInfo(const AccountId& account_id);
// If the device is enterprise managed and the device wallpaper policy exists,
......@@ -477,10 +428,9 @@ class WallpaperManager : public content::NotificationObserver,
MovableOnDestroyCallbackHolder on_finish,
std::unique_ptr<user_manager::UserImage> user_image);
// Sets wallpaper to default if |update_wallpaper| is true. Otherwise just
// load defaut wallpaper to cache.
void DoSetDefaultWallpaper(const AccountId& account_id,
bool update_wallpaper,
// A wrapper of |WallpaperController::SetDefaultWallpaperImpl|.
void SetDefaultWallpaperImpl(const AccountId& account_id,
bool show_wallpaper,
MovableOnDestroyCallbackHolder on_finish);
// Starts to load wallpaper at |wallpaper_path|. If |wallpaper_path| is
......@@ -523,37 +473,12 @@ class WallpaperManager : public content::NotificationObserver,
std::unique_ptr<gfx::ImageSkia> small_wallpaper_image,
std::unique_ptr<gfx::ImageSkia> large_wallpaper_image);
// Init |*default_*_wallpaper_file_| from given command line and
// clear |default_wallpaper_image_|.
void SetDefaultWallpaperPathsFromCommandLine(base::CommandLine* command_line);
// Sets wallpaper to decoded default if |update_wallpaper| is true.
void OnDefaultWallpaperDecoded(
const base::FilePath& path,
const wallpaper::WallpaperLayout layout,
bool update_wallpaper,
std::unique_ptr<user_manager::UserImage>* result,
MovableOnDestroyCallbackHolder on_finish,
std::unique_ptr<user_manager::UserImage> user_image);
// Start decoding given default wallpaper and set it as wallpaper if
// |update_wallpaper| is true.
void StartLoadAndSetDefaultWallpaper(
const base::FilePath& path,
const wallpaper::WallpaperLayout layout,
bool update_wallpaper,
MovableOnDestroyCallbackHolder on_finish,
std::unique_ptr<user_manager::UserImage>* result_out);
// Record the Wallpaper App that the user is using right now on Chrome OS.
void RecordWallpaperAppType();
// Returns wallpaper subdirectory name for current resolution.
const char* GetCustomWallpaperSubdirForCurrentResolution();
// Init default_wallpaper_image_ with 1x1 image of default color.
void CreateSolidDefaultWallpaper();
// Callback function for GetCustomWallpaperInternal().
void OnCustomWallpaperFileNotFound(const AccountId& account_id,
const base::FilePath& expected_path,
......@@ -598,12 +523,8 @@ class WallpaperManager : public content::NotificationObserver,
const AccountId& account_id,
std::unique_ptr<user_manager::UserImage> user_image);
// Use given files as new default wallpaper.
// Reloads current wallpaper, if old default was loaded.
// Current value of default_wallpaper_image_ is destroyed.
// Sets default_wallpaper_image_ either to |small_wallpaper_image| or
// |large_wallpaper_image| depending on GetAppropriateResolution().
void SetDefaultWallpaperPath(
// A wrapper of |WallpaperController::SetCustomizedDefaultWallpaperImpl|.
void SetCustomizedDefaultWallpaperImpl(
const base::FilePath& customized_default_wallpaper_file_small,
std::unique_ptr<gfx::ImageSkia> small_wallpaper_image,
const base::FilePath& customized_default_wallpaper_file_large,
......@@ -656,18 +577,6 @@ class WallpaperManager : public content::NotificationObserver,
// last N wallpaper loads times.
base::circular_deque<base::TimeDelta> last_load_times_;
base::FilePath default_small_wallpaper_file_;
base::FilePath default_large_wallpaper_file_;
base::FilePath guest_small_wallpaper_file_;
base::FilePath guest_large_wallpaper_file_;
base::FilePath child_small_wallpaper_file_;
base::FilePath child_large_wallpaper_file_;
// Current decoded default image is stored in cache.
std::unique_ptr<user_manager::UserImage> default_wallpaper_image_;
bool retry_download_if_failed_ = true;
// Pointer to last inactive (waiting) entry of 'loading_' list.
......
......@@ -6,19 +6,15 @@
#include <stddef.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chromeos/chromeos_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
......@@ -65,33 +61,11 @@ class TestWallpaperObserverPendingListEmpty
namespace wallpaper_manager_test_utils {
const SkColor kLargeDefaultWallpaperColor = SK_ColorRED;
const SkColor kSmallDefaultWallpaperColor = SK_ColorGREEN;
const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE;
const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW;
const SkColor kLargeChildWallpaperColor = SK_ColorCYAN;
const SkColor kSmallChildWallpaperColor = SK_ColorMAGENTA;
const SkColor kCustomWallpaperColor = SK_ColorMAGENTA;
const SkColor kLargeCustomWallpaperColor = SK_ColorDKGRAY;
const SkColor kSmallCustomWallpaperColor = SK_ColorLTGRAY;
const int kWallpaperSize = 2;
bool CreateJPEGImage(int width,
int height,
SkColor color,
std::vector<unsigned char>* output) {
SkBitmap bitmap;
bitmap.allocN32Pixels(width, height);
bitmap.eraseColor(color);
constexpr int kQuality = 80;
if (!gfx::JPEGCodec::Encode(bitmap, kQuality, output)) {
LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap";
return false;
}
return true;
}
gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) {
SkBitmap bitmap;
bitmap.allocN32Pixels(width, height);
......@@ -99,25 +73,6 @@ gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) {
return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
}
bool WriteJPEGFile(const base::FilePath& path,
int width,
int height,
SkColor color) {
base::ScopedAllowBlockingForTesting allow_blocking;
std::vector<unsigned char> output;
if (!CreateJPEGImage(width, height, color, &output))
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;
}
bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) {
if (image.size().IsEmpty()) {
LOG(ERROR) << "Image is empty";
......@@ -155,62 +110,6 @@ void WaitAsyncWallpaperLoadFinished() {
observer.WaitForPendingListEmpty();
}
void CreateCmdlineWallpapers(const base::ScopedTempDir& dir,
std::unique_ptr<base::CommandLine>* command_line) {
std::vector<std::string> options;
options.push_back(std::string("WM_Test_cmdline"));
const base::FilePath small_file =
dir.GetPath().Append(FILE_PATH_LITERAL("small.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kDefaultWallpaperSmall + "=" +
small_file.value());
const base::FilePath large_file =
dir.GetPath().Append(FILE_PATH_LITERAL("large.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kDefaultWallpaperLarge + "=" +
large_file.value());
const base::FilePath guest_small_file =
dir.GetPath().Append(FILE_PATH_LITERAL("guest_small.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kGuestWallpaperSmall + "=" +
guest_small_file.value());
const base::FilePath guest_large_file =
dir.GetPath().Append(FILE_PATH_LITERAL("guest_large.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kGuestWallpaperLarge + "=" +
guest_large_file.value());
const base::FilePath child_small_file =
dir.GetPath().Append(FILE_PATH_LITERAL("child_small.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kChildWallpaperSmall + "=" +
child_small_file.value());
const base::FilePath child_large_file =
dir.GetPath().Append(FILE_PATH_LITERAL("child_large.jpg"));
options.push_back(std::string("--") +
chromeos::switches::kChildWallpaperLarge + "=" +
child_large_file.value());
ASSERT_TRUE(WriteJPEGFile(small_file, kWallpaperSize, kWallpaperSize,
kSmallDefaultWallpaperColor));
ASSERT_TRUE(WriteJPEGFile(large_file, kWallpaperSize, kWallpaperSize,
kLargeDefaultWallpaperColor));
ASSERT_TRUE(WriteJPEGFile(guest_small_file, kWallpaperSize, kWallpaperSize,
kSmallGuestWallpaperColor));
ASSERT_TRUE(WriteJPEGFile(guest_large_file, kWallpaperSize, kWallpaperSize,
kLargeGuestWallpaperColor));
ASSERT_TRUE(WriteJPEGFile(child_small_file, kWallpaperSize, kWallpaperSize,
kSmallChildWallpaperColor));
ASSERT_TRUE(WriteJPEGFile(child_large_file, kWallpaperSize, kWallpaperSize,
kLargeChildWallpaperColor));
command_line->reset(new base::CommandLine(options));
WallpaperManager::Get()->SetCommandLineForTesting(command_line->get());
}
} // namespace wallpaper_manager_test_utils
} // namespace chromeos
......@@ -10,50 +10,21 @@
#include "ash/ash_constants.h"
#include "ui/gfx/image/image_skia.h"
namespace base {
class CommandLine;
class FilePath;
class ScopedTempDir;
} // namespace base
namespace chromeos {
namespace wallpaper_manager_test_utils {
// Colors used for different default wallpapers by CreateCmdlineWallpapers().
extern const SkColor kLargeDefaultWallpaperColor;
extern const SkColor kSmallDefaultWallpaperColor;
extern const SkColor kLargeGuestWallpaperColor;
extern const SkColor kSmallGuestWallpaperColor;
extern const SkColor kLargeChildWallpaperColor;
extern const SkColor kSmallChildWallpaperColor;
// A custom color, specifically chosen to not
// conflict with any of the default wallpaper colors.
extern const SkColor kCustomWallpaperColor;
// Custom wallpaper colors.
extern const SkColor kLargeCustomWallpaperColor;
extern const SkColor kSmallCustomWallpaperColor;
// 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.
extern const int kWallpaperSize;
// Creates compressed JPEG image of solid color.
// Result bytes are written to |output|.
// Returns true if gfx::JPEGCodec::Encode() succeeds.
bool CreateJPEGImage(int width,
int height,
SkColor color,
std::vector<unsigned char>* output);
// Creates a test image of given size.
gfx::ImageSkia CreateTestImage(int width, int height, SkColor color);
// 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);
// 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.)
......@@ -63,13 +34,6 @@ bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color);
// a stable state.
void WaitAsyncWallpaperLoadFinished();
// 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 CreateCmdlineWallpapers(const base::ScopedTempDir& dir,
std::unique_ptr<base::CommandLine>* command_line);
} // namespace wallpaper_manager_test_utils
} // namespace chromeos
......
......@@ -49,8 +49,9 @@ void TestWallpaperController::SetOnlineWallpaper(
void TestWallpaperController::SetDefaultWallpaper(
ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id,
bool show_wallpaper) {
NOTIMPLEMENTED();
set_default_wallpaper_count_++;
}
void TestWallpaperController::SetCustomizedDefaultWallpaper(
......
......@@ -19,10 +19,13 @@ class TestWallpaperController : ash::mojom::WallpaperController {
~TestWallpaperController() override;
void ClearCounts();
bool was_client_set() const { return was_client_set_; }
int remove_user_wallpaper_count() { return remove_user_wallpaper_count_; }
int remove_user_wallpaper_count() const {
return remove_user_wallpaper_count_;
}
int set_default_wallpaper_count() const {
return set_default_wallpaper_count_;
}
// Returns a mojo interface pointer bound to this object.
ash::mojom::WallpaperControllerPtr CreateInterfacePtr();
......@@ -46,6 +49,7 @@ class TestWallpaperController : ash::mojom::WallpaperController {
wallpaper::WallpaperLayout layout,
bool show_wallpaper) override;
void SetDefaultWallpaper(ash::mojom::WallpaperUserInfoPtr user_info,
const std::string& wallpaper_files_id,
bool show_wallpaper) override;
void SetCustomizedDefaultWallpaper(
const GURL& wallpaper_url,
......@@ -65,8 +69,8 @@ class TestWallpaperController : ash::mojom::WallpaperController {
mojo::Binding<ash::mojom::WallpaperController> binding_;
bool was_client_set_ = false;
int remove_user_wallpaper_count_ = 0;
int set_default_wallpaper_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(TestWallpaperController);
};
......
......@@ -178,8 +178,8 @@ void WallpaperControllerClient::SetDefaultWallpaper(const AccountId& account_id,
AccountIdToWallpaperUserInfo(account_id);
if (!user_info)
return;
wallpaper_controller_->SetDefaultWallpaper(std::move(user_info),
show_wallpaper);
wallpaper_controller_->SetDefaultWallpaper(
std::move(user_info), GetFilesId(account_id).id(), show_wallpaper);
}
void WallpaperControllerClient::SetCustomizedDefaultWallpaper(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment