desktop_background_controller_unittest.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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" 18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/command_line.h" 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/file_util.h" 20eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/file_path.h" 21eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/files/scoped_temp_dir.h" 22eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/message_loop/message_loop.h" 23eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/test/test_browser_thread.h" 24eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "third_party/skia/include/core/SkBitmap.h" 25eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "third_party/skia/include/core/SkColor.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_animation_duration_scale_mode.h" 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/test/layer_animator_test_controller.h" 29eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/codec/jpeg_codec.h" 30eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/point.h" 31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/gfx/rect.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using aura::RootWindow; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using aura::Window; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnamespace ash { 37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochnamespace internal { 38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Containers IDs used for tests. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kDesktopBackgroundId = 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ash::internal::kShellWindowId_DesktopBackgroundContainer; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kLockScreenBackgroundId = 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ash::internal::kShellWindowId_LockScreenBackgroundContainer; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns number of child windows in a shell window container. 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ChildCountForContainer(int container_id) { 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RootWindow* root = ash::Shell::GetPrimaryRootWindow(); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Window* container = root->GetChildById(container_id); 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return static_cast<int>(container->children().size()); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochclass TestObserver : public DesktopBackgroundControllerObserver { 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch public: 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch explicit TestObserver(DesktopBackgroundController* controller) 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch : controller_(controller) { 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DCHECK(controller_); 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->AddObserver(this); 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual ~TestObserver() { 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->RemoveObserver(this); 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void WaitForWallpaperDataChanged() { 67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::MessageLoop::current()->Run(); 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // DesktopBackgroundControllerObserver overrides: 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch virtual void OnWallpaperDataChanged() OVERRIDE { 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch base::MessageLoop::current()->Quit(); 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private: 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundController* controller_; 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}; 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Steps a widget's layer animation until it is completed. Animations must be 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// enabled. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RunAnimationForWidget(views::Widget* widget) { 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Animations must be enabled for stepping to work. 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::Layer* layer = widget->GetNativeView()->layer(); 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::LayerAnimatorTestController controller(layer->GetAnimator()); 88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::AnimationContainerElement* element = layer->GetAnimator(); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Multiple steps are required to complete complex animations. 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(vollick): This should not be necessary. crbug.com/154017 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) while (controller.animator()->is_animating()) { 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.StartThreadedAnimationsIfNeeded(); 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks step_time = controller.animator()->last_step_time(); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class DesktopBackgroundControllerTest : public test::AshTestBase { 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 102eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundControllerTest() 103a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch : command_line_(CommandLine::NO_PROGRAM), 104eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_(NULL) { 105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DesktopBackgroundControllerTest() {} 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) test::AshTestBase::SetUp(); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ash shell initialization creates wallpaper. Reset it so we can manually 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // control wallpaper creation and animation in our tests. 112eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RootWindowController* root_window_controller = 113eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 114eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->SetWallpaperController(NULL); 115eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->SetAnimatingWallpaperController(NULL); 116eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_ = Shell::GetInstance()->desktop_background_controller(); 117eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 118eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 119eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch protected: 120eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Colors used for different default wallpapers by 121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // WriteWallpapersAndSetFlags(). 122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kLargeWallpaperColor = SK_ColorRED; 123eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kSmallWallpaperColor = SK_ColorGREEN; 124eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; 125eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; 126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Dimension used for width and height of default wallpaper images. A 128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // small value is used to minimize the amount of time spent compressing 129eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // and writing images. 130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static const int kWallpaperSize = 2; 131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Runs kAnimatingDesktopController's animation to completion. 133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(bshe): Don't require tests to run animations; it's slow. 134eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void RunDesktopControllerAnimation() { 135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundWidgetController* controller = 136eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController()-> 137eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_wallpaper_controller()->GetController(false); 138eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); 139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 140eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Returns true if the color at the center of |image| is close to 142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // |expected_color|. (The center is used so small wallpaper images can be 143eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // used.) 144eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { 145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (image.size().IsEmpty()) { 146eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Image is empty"; 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 148eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 149eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 150eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const SkBitmap* bitmap = image.bitmap(); 151eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!bitmap) { 152eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Unable to get bitmap from image"; 153eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 155eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 156eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap->lockPixels(); 157eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::Point center = gfx::Rect(image.size()).CenterPoint(); 158eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkColor image_color = bitmap->getColor(center.x(), center.y()); 159eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap->unlockPixels(); 160eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 161eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const int kDiff = 3; 162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (std::abs(static_cast<int>(SkColorGetA(image_color)) - 163eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetA(expected_color))) > kDiff || 164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetR(image_color)) - 165eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetR(expected_color))) > kDiff || 166eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetG(image_color)) - 167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetG(expected_color))) > kDiff || 168eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::abs(static_cast<int>(SkColorGetB(image_color)) - 169eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<int>(SkColorGetB(expected_color))) > kDiff) { 170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color 171eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch << " but got 0x" << image_color; 172eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 173eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 175eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return true; 176eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 177eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 178eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Writes a JPEG image of the specified size and color to |path|. Returns 179eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // true on success. 180eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool WriteJPEGFile(const base::FilePath& path, 181eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int width, 182eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch int height, 183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkColor color) { 184eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch SkBitmap bitmap; 185eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); 186eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.allocPixels(); 187eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bitmap.eraseColor(color); 188eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const int kQuality = 80; 190eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch std::vector<unsigned char> output; 191eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!gfx::JPEGCodec::Encode( 192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch static_cast<const unsigned char*>(bitmap.getPixels()), 193eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(), 194eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kQuality, &output)) { 195eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; 196eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 197eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 198eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 199eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch size_t bytes_written = file_util::WriteFile( 200eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch path, reinterpret_cast<const char*>(&output[0]), output.size()); 201eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (bytes_written != output.size()) { 202eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " 203eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch << output.size() << " to " << path.value(); 204eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return false; 205eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return true; 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 209eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 210eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and 211eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // passes |controller_| a command line instructing it to use the images. 212eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Only needs to be called (once) by tests that want to test loading of 213eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // default wallpapers. 214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch void WriteWallpapersAndSetFlags() { 215eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_.reset(new base::ScopedTempDir); 216eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); 217eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kLargePath = 219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeWallpaperColor)); 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultWallpaperLarge, kLargePath); 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kSmallPath = 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); 227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, 228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallWallpaperColor)); 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultWallpaperSmall, kSmallPath); 231eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kLargeGuestPath = 233eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); 234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, 235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeGuestWallpaperColor)); 236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultGuestWallpaperLarge, kLargeGuestPath); 238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const base::FilePath kSmallGuestPath = 240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); 241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, 242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallGuestWallpaperColor)); 243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch command_line_.AppendSwitchPath( 244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch switches::kAshDefaultGuestWallpaperSmall, kSmallGuestPath); 245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->set_command_line_for_testing(&command_line_); 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Custom command line passed to DesktopBackgroundController by 250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // WriteWallpapersAndSetFlags(). 251eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CommandLine command_line_; 252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Directory created by WriteWallpapersAndSetFlags() to store default 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // wallpaper images. 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch scoped_ptr<base::ScopedTempDir> wallpaper_dir_; 256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundController* controller_; // Not owned. 258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Wallpaper view/window exists in the desktop background container and 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nothing is in the lock screen background container. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moving background to lock container should succeed the first time but 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // subsequent calls should do nothing. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(controller->MoveDesktopToLockedContainer()); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(controller->MoveDesktopToLockedContainer()); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One window is moved from desktop to lock container. 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kLockScreenBackgroundId)); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Moving background to desktop container should succeed the first time. 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(controller->MoveDesktopToUnlockedContainer()); 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(controller->MoveDesktopToUnlockedContainer()); 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One window is moved from lock to desktop container. 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, ControllerOwnership) { 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create wallpaper and background view. 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The new wallpaper is ready to start animating. kAnimatingDesktopController 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // holds the widget controller instance. kDesktopController will get it later. 303eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RootWindowController* root_window_controller = 304eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 305eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> 306eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // kDesktopController will receive the widget controller when the animation 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is done. 310eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->wallpaper_controller()); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Force the widget's layer animation to play to completion. 313eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ownership has moved from kAnimatingDesktopController to kDesktopController. 316eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> 317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 318eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// move all desktop views if there are more than one. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reset wallpaper state, see ControllerOwnership above. 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // User locks the screen, which moves the background forward. 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->MoveDesktopToLockedContainer(); 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // background that will animate in on top of the old one. 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In this state we have two desktop background views stored in different 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // properties. Both are in the lock screen background container. 345eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RootWindowController* root_window_controller = 346eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> 348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Before the wallpaper's animation completes, user unlocks the screen, which 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // moves the desktop to the back. 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->MoveDesktopToUnlockedContainer(); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Ensure both desktop backgrounds have moved. 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Finish the new desktop background animation. 362eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Now there is one desktop background, in the back. 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test for crbug.com/156542. Animating wallpaper should immediately finish 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// animation and replace current wallpaper before next animation starts. 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We cannot short-circuit animations for this test. 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode normal_duration_mode( 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reset wallpaper state, see ControllerOwnership above. 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DesktopBackgroundController* controller = 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetInstance()->desktop_background_controller(); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 382eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RunDesktopControllerAnimation(); 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change to a new wallpaper. 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 387eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch RootWindowController* root_window_controller = 388eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetPrimaryRootWindowController(); 389eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch DesktopBackgroundWidgetController* animating_controller = 390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->animating_wallpaper_controller()-> 391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false); 392eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(animating_controller); 393eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Change to another wallpaper before animation finished. 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) controller->CreateEmptyWallpaper(); 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The animating controller should immediately move to desktop controller. 399eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(animating_controller, 400eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->wallpaper_controller()); 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cache the new animating controller. 403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_controller = root_window_controller-> 404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch animating_wallpaper_controller()->GetController(false); 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Run wallpaper show animation to completion. 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_NO_FATAL_FAILURE( 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RunAnimationForWidget( 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->animating_wallpaper_controller()-> 410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)->widget())); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 412eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(root_window_controller->wallpaper_controller()); 413eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> 414eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch GetController(false)); 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The desktop controller should be the last created animating controller. 416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(animating_controller, 417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch root_window_controller->wallpaper_controller()); 418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 419eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 420eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, GetAppropriateResolution) { 421eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(derat|oshima|bshe): Configuring desktops seems busted on Win8, 422eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // even when just a single display is being used -- the small wallpaper 423eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // is used instead of the large one. Track down the cause of the problem 424eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // and only use a SupportsMultipleDisplays() clause for the dual-display 425eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // code below. 426eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 427eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 428eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 429eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 430eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 431eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 432eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Small wallpaper images should be used for configurations less than or 433eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if 434eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // multiple displays are connected. 435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600,800x600"); 439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1366x800"); 442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 445eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // At larger sizes, large wallpapers should be used. 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1367x800"); 447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1367x801"); 450eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 451eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 452eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("2560x1700"); 453eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 454eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch controller_->GetAppropriateResolution()); 455eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 456eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 457eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Test that DesktopBackgroundController loads the appropriate wallpaper 458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// images as specified via command-line flags in various situations. 459eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Splitting these into separate tests avoids needing to run animations. 460eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// TODO(derat): Combine these into a single test -- see 461eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// RunDesktopControllerAnimation()'s TODO. 462eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { 463eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 464eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 465eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 467eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 468eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 469eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // At 800x600, the small wallpaper should be loaded. 470eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 471eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 472eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 473eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 474eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 475eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 476eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallWallpaperColor)); 477eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 478eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Requesting the same wallpaper again should be a no-op. 479eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_FALSE(controller_->SetDefaultWallpaper(false)); 480eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 481eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 482eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) { 483eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 484eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 485eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 486eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 487eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 488eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 489eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 490eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1600x1200"); 491eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 492eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 494eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeWallpaperColor)); 495eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 496eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 497eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) { 498eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 499eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 500eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 501eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 502eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 503eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 504eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("800x600"); 506eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 507eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 508eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 509eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kSmallGuestWallpaperColor)); 510eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 511eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 512eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) { 513eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (!SupportsMultipleDisplays()) 514eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 515eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 516eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch WriteWallpapersAndSetFlags(); 517eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch TestObserver observer(controller_); 518eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::DisplayManagerTestApi display_manager_test_api( 519eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch Shell::GetInstance()->display_manager()); 520eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch display_manager_test_api.UpdateDisplay("1600x1200"); 521eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 522eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch observer.WaitForWallpaperDataChanged(); 523eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 524eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch kLargeGuestWallpaperColor)); 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace internal 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 529