15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/desktop_background/desktop_background_controller.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <cmath> 8eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <cstdlib> 9eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/ash_switches.h" 11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/desktop_background/desktop_background_controller_observer.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/desktop_background/desktop_background_widget_controller.h" 13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/root_window_controller.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_window_ids.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ash/test/display_manager_test_api.h" 1868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/test/test_user_wallpaper_delegate.h" 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/command_line.h" 20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/file_util.h" 21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/file_path.h" 22eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/scoped_temp_dir.h" 23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/message_loop/message_loop.h" 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/threading/sequenced_worker_pool.h" 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/browser/browser_thread.h" 26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/test/test_browser_thread.h" 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/public/test/test_utils.h" 28eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "third_party/skia/include/core/SkBitmap.h" 29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "third_party/skia/include/core/SkColor.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h" 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/test/layer_animator_test_controller.h" 33eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/codec/jpeg_codec.h" 34eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/point.h" 35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/rect.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using aura::RootWindow; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using aura::Window; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnamespace ash { 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Containers IDs used for tests. 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDesktopBackgroundId = 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ash::internal::kShellWindowId_DesktopBackgroundContainer; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kLockScreenBackgroundId = 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ash::internal::kShellWindowId_LockScreenBackgroundContainer; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns number of child windows in a shell window container. 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ChildCountForContainer(int container_id) { 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Window* root = ash::Shell::GetPrimaryRootWindow(); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* container = root->GetChildById(container_id); 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return static_cast<int>(container->children().size()); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass TestObserver : public DesktopBackgroundControllerObserver { 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch public: 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch explicit TestObserver(DesktopBackgroundController* controller) 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch : controller_(controller) { 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(controller_); 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->AddObserver(this); 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual ~TestObserver() { 65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->RemoveObserver(this); 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void WaitForWallpaperDataChanged() { 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::MessageLoop::current()->Run(); 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // DesktopBackgroundControllerObserver overrides: 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void OnWallpaperDataChanged() OVERRIDE { 74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::MessageLoop::current()->Quit(); 75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private: 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundController* controller_; 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Steps a widget's layer animation until it is completed. Animations must be 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// enabled. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RunAnimationForWidget(views::Widget* widget) { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Animations must be enabled for stepping to work. 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::Layer* layer = widget->GetNativeView()->layer(); 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::LayerAnimatorTestController controller(layer->GetAnimator()); 90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::AnimationContainerElement* element = layer->GetAnimator(); 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Multiple steps are required to complete complex animations. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(vollick): This should not be necessary. crbug.com/154017 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) while (controller.animator()->is_animating()) { 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.StartThreadedAnimationsIfNeeded(); 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks step_time = controller.animator()->last_step_time(); 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 102868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DesktopBackgroundControllerTest : public test::AshTestBase { 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundControllerTest() 105a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch : command_line_(CommandLine::NO_PROGRAM), 106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_(NULL) { 107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DesktopBackgroundControllerTest() {} 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test::AshTestBase::SetUp(); 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ash shell initialization creates wallpaper. Reset it so we can manually 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // control wallpaper creation and animation in our tests. 11468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController* root_window_controller = 115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->SetWallpaperController(NULL); 117eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->SetAnimatingWallpaperController(NULL); 118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_ = Shell::GetInstance()->desktop_background_controller(); 11968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( 12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Shell::GetInstance()->user_wallpaper_delegate()); 12168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) controller_->set_wallpaper_reload_delay_for_test(0); 122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch protected: 125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Colors used for different default wallpapers by 126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // WriteWallpapersAndSetFlags(). 127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kLargeWallpaperColor = SK_ColorRED; 128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kSmallWallpaperColor = SK_ColorGREEN; 129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; 130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; 131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Dimension used for width and height of default wallpaper images. A 133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // small value is used to minimize the amount of time spent compressing 134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // and writing images. 135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const int kWallpaperSize = 2; 136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Creates an image of size |size|. 138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::ImageSkia CreateImage(int width, int height) { 139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SkBitmap bitmap; 140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bitmap.allocPixels(); 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return image; 144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Runs kAnimatingDesktopController's animation to completion. 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(bshe): Don't require tests to run animations; it's slow. 148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void RunDesktopControllerAnimation() { 14968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::DesktopBackgroundWidgetController* controller = 150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController()-> 151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_wallpaper_controller()->GetController(false); 152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); 153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns true if the color at the center of |image| is close to 156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // |expected_color|. (The center is used so small wallpaper images can be 157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // used.) 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { 159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (image.size().IsEmpty()) { 160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Image is empty"; 161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const SkBitmap* bitmap = image.bitmap(); 165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!bitmap) { 166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Unable to get bitmap from image"; 167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap->lockPixels(); 171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::Point center = gfx::Rect(image.size()).CenterPoint(); 172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkColor image_color = bitmap->getColor(center.x(), center.y()); 173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap->unlockPixels(); 174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const int kDiff = 3; 176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (std::abs(static_cast<int>(SkColorGetA(image_color)) - 177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetA(expected_color))) > kDiff || 178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetR(image_color)) - 179eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetR(expected_color))) > kDiff || 180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetG(image_color)) - 181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetG(expected_color))) > kDiff || 182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetB(image_color)) - 183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetB(expected_color))) > kDiff) { 184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color 185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch << " but got 0x" << image_color; 186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return true; 190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Writes a JPEG image of the specified size and color to |path|. Returns 193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // true on success. 194eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool WriteJPEGFile(const base::FilePath& path, 195eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int width, 196eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int height, 197eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkColor color) { 198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkBitmap bitmap; 199eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); 200eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.allocPixels(); 201eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.eraseColor(color); 202eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 203eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const int kQuality = 80; 204eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<unsigned char> output; 205eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!gfx::JPEGCodec::Encode( 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<const unsigned char*>(bitmap.getPixels()), 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(), 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kQuality, &output)) { 209eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; 210eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 211eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 212eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 213eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch size_t bytes_written = file_util::WriteFile( 214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch path, reinterpret_cast<const char*>(&output[0]), output.size()); 215eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (bytes_written != output.size()) { 216eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " 217eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch << output.size() << " to " << path.value(); 218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return true; 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // passes |controller_| a command line instructing it to use the images. 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Only needs to be called (once) by tests that want to test loading of 227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // default wallpapers. 228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void WriteWallpapersAndSetFlags() { 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_.reset(new base::ScopedTempDir); 230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); 231eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kLargePath = 233eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); 234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, 235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeWallpaperColor)); 236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultWallpaperLarge, kLargePath); 238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kSmallPath = 240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); 241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, 242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallWallpaperColor)); 243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultWallpaperSmall, kSmallPath); 245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kLargeGuestPath = 247eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); 248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, 249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeGuestWallpaperColor)); 250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 2514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) switches::kAshGuestWallpaperLarge, kLargeGuestPath); 252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kSmallGuestPath = 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, 256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallGuestWallpaperColor)); 257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 2584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) switches::kAshGuestWallpaperSmall, kSmallGuestPath); 259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->set_command_line_for_testing(&command_line_); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Custom command line passed to DesktopBackgroundController by 264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // WriteWallpapersAndSetFlags(). 265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CommandLine command_line_; 266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Directory created by WriteWallpapersAndSetFlags() to store default 268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // wallpaper images. 269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<base::ScopedTempDir> wallpaper_dir_; 270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundController* controller_; // Not owned. 272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 27368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) test::TestUserWallpaperDelegate* wallpaper_delegate_; 27468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Wallpaper view/window exists in the desktop background container and 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nothing is in the lock screen background container. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moving background to lock container should succeed the first time but 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // subsequent calls should do nothing. 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(controller->MoveDesktopToLockedContainer()); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(controller->MoveDesktopToLockedContainer()); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One window is moved from desktop to lock container. 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kLockScreenBackgroundId)); 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moving background to desktop container should succeed the first time. 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(controller->MoveDesktopToUnlockedContainer()); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(controller->MoveDesktopToUnlockedContainer()); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One window is moved from lock to desktop container. 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create wallpaper and background view. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The new wallpaper is ready to start animating. kAnimatingDesktopController 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // holds the widget controller instance. kDesktopController will get it later. 31968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController* root_window_controller = 320eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> 322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // kDesktopController will receive the widget controller when the animation 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is done. 326eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->wallpaper_controller()); 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Force the widget's layer animation to play to completion. 329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ownership has moved from kAnimatingDesktopController to kDesktopController. 332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> 333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// move all desktop views if there are more than one. 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reset wallpaper state, see ControllerOwnership above. 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 350eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // User locks the screen, which moves the background forward. 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->MoveDesktopToLockedContainer(); 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // background that will animate in on top of the old one. 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In this state we have two desktop background views stored in different 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // properties. Both are in the lock screen background container. 36168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController* root_window_controller = 362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> 364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Before the wallpaper's animation completes, user unlocks the screen, which 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // moves the desktop to the back. 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->MoveDesktopToUnlockedContainer(); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ensure both desktop backgrounds have moved. 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Finish the new desktop background animation. 378eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now there is one desktop background, in the back. 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test for crbug.com/156542. Animating wallpaper should immediately finish 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// animation and replace current wallpaper before next animation starts. 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 3902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reset wallpaper state, see ControllerOwnership above. 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 398eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change to a new wallpaper. 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::RootWindowController* root_window_controller = 404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 40568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) internal::DesktopBackgroundWidgetController* animating_controller = 406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->animating_wallpaper_controller()-> 407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false); 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(animating_controller); 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change to another wallpaper before animation finished. 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The animating controller should immediately move to desktop controller. 415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(animating_controller, 416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->wallpaper_controller()); 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cache the new animating controller. 419eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_controller = root_window_controller-> 420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_wallpaper_controller()->GetController(false); 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RunAnimationForWidget( 425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->animating_wallpaper_controller()-> 426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)->widget())); 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> 430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The desktop controller should be the last created animating controller. 432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(animating_controller, 433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->wallpaper_controller()); 434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 43668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, DisplayChange) { 43768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. 43868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!SupportsHostWindowResize()) 439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 441f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set the wallpaper to ensure that UpdateWallpaper() will be called when the 442f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // display configuration changes. 443f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::ImageSkia image = CreateImage(640, 480); 444f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) wallpaper_delegate_->set_custom_wallpaper(image); 445f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Small wallpaper images should be used for configurations less than or 448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if 449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // multiple displays are connected. 450f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) test::DisplayManagerTestApi display_manager_test_api( 451f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Shell::GetInstance()->display_manager()); 452eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 45368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 454eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 455eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 456f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 45768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600,800x600"); 45968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 460eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 461eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 462f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 46368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 464eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1366x800"); 46568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 467eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 468f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 469eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 470eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // At larger sizes, large wallpapers should be used. 471eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1367x800"); 47268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 473eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 475f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 47668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 477eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1367x801"); 47868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 480eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 481f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 48268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 483eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("2560x1700"); 48468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 48568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 48668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) controller_->GetAppropriateResolution()); 487f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 48868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 48968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Rotated smaller screen may use larger image. 49068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) display_manager_test_api.UpdateDisplay("800x600/r"); 49168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 49268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 49368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) controller_->GetAppropriateResolution()); 494f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 49568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 49668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) display_manager_test_api.UpdateDisplay("800x600/r,800x600"); 49768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 49868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 49968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) controller_->GetAppropriateResolution()); 500f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 50168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) display_manager_test_api.UpdateDisplay("1366x800/r"); 50268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 503eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 504eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 505f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 50668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 50768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Max display size didn't chagne. 50868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); 50968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) RunAllPendingInMessageLoop(); 510f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 511eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 512eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 513eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Test that DesktopBackgroundController loads the appropriate wallpaper 514eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// images as specified via command-line flags in various situations. 515eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Splitting these into separate tests avoids needing to run animations. 516eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// TODO(derat): Combine these into a single test -- see 517eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// RunDesktopControllerAnimation()'s TODO. 518eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 520eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 521eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 522eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 523eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 524eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 525eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // At 800x600, the small wallpaper should be loaded. 526eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 527eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 528eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 529eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 530eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 531eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 532eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallWallpaperColor)); 533eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 534eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Requesting the same wallpaper again should be a no-op. 535eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_FALSE(controller_->SetDefaultWallpaper(false)); 536eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 537eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 538eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) { 539eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 540eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 541eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 542eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 543eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 544eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 545eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 546eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1600x1200"); 547eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 548eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 549eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 550eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeWallpaperColor)); 551eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 552eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 55368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaperWhenRotated) { 55468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!SupportsMultipleDisplays()) 55568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return; 55668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) WriteWallpapersAndSetFlags(); 55768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) TestObserver observer(controller_); 55868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) test::DisplayManagerTestApi display_manager_test_api( 55968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Shell::GetInstance()->display_manager()); 56068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 56168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) display_manager_test_api.UpdateDisplay("1200x800/r"); 56268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 56368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) observer.WaitForWallpaperDataChanged(); 56468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 56568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) kLargeWallpaperColor)); 56668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 56768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 568eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) { 569eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 570eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 571eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 572eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 573eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 574eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 575eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 576eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 577eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 578eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 579eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 580eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallGuestWallpaperColor)); 581eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 582eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 583eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) { 584eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 585eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 586eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 587eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 588eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 589eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 590eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 591eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1600x1200"); 592eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 593eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 594eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 595eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeGuestWallpaperColor)); 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 598f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { 599f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!SupportsMultipleDisplays()) 600f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 601f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 602f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) test::DisplayManagerTestApi display_manager_test_api( 603f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Shell::GetInstance()->display_manager()); 604f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) display_manager_test_api.UpdateDisplay("320x200"); 605f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 606f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::ImageSkia image = CreateImage(640, 480); 607f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 608f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Set the image as custom wallpaper, wait for the resize to finish, and check 609f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // that the resized image is the expected size. 610f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 611f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); 612f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content::BrowserThread::GetBlockingPool()->FlushForTesting(); 613f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content::RunAllPendingInMessageLoop(); 614f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) gfx::ImageSkia resized_image = controller_->GetWallpaper(); 615f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); 616f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); 617f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 618f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Load the original wallpaper again and check that we're still using the 619f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // previously-resized image instead of doing another resize 620f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // (http://crbug.com/321402). 621f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 622f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content::BrowserThread::GetBlockingPool()->FlushForTesting(); 623f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) content::RunAllPendingInMessageLoop(); 624f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); 625f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 626f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 62768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { 62868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Device scale factor shouldn't affect the native size. 62968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("1000x300*2"); 63068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 63168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "1000x300", 63268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 63368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 63468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Rotated display should return the rotated size. 63568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("1000x300*2/r"); 63668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 63768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "300x1000", 63868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 63968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 64068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // UI Scaling shouldn't affect the native size. 64168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("1000x300*2@1.5"); 64268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 64368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "1000x300", 64468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 64568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 64668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) if (!SupportsMultipleDisplays()) 64768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) return; 64868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 64968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // First display has maximum size. 65068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("400x300,100x100"); 65168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 65268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "400x300", 65368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 65468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 65568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Second display has maximum size. 65668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("400x300,500x600"); 65768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 65868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "500x600", 65968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 66068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 66168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Maximum width and height belongs to different displays. 66268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) UpdateDisplay("400x300,100x500"); 66368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) EXPECT_EQ( 66468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) "400x500", 66568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 66668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)} 66768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 669