Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: ash/desktop_background/desktop_background_controller_unittest.cc

Issue 115263004: ash: Add test for wallpaper-switching bug. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/desktop_background/desktop_background_controller.h" 5 #include "ash/desktop_background/desktop_background_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 protected: 124 protected:
125 // Colors used for different default wallpapers by 125 // Colors used for different default wallpapers by
126 // WriteWallpapersAndSetFlags(). 126 // WriteWallpapersAndSetFlags().
127 static const SkColor kLargeWallpaperColor = SK_ColorRED; 127 static const SkColor kLargeWallpaperColor = SK_ColorRED;
128 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; 128 static const SkColor kSmallWallpaperColor = SK_ColorGREEN;
129 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; 129 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE;
130 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; 130 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW;
131 131
132 // A color that can be passed to CreateImage(). Specifically chosen to not
133 // conflict with any of the default wallpaper colors.
134 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA;
135
132 // Dimension used for width and height of default wallpaper images. A 136 // Dimension used for width and height of default wallpaper images. A
133 // small value is used to minimize the amount of time spent compressing 137 // small value is used to minimize the amount of time spent compressing
134 // and writing images. 138 // and writing images.
135 static const int kWallpaperSize = 2; 139 static const int kWallpaperSize = 2;
136 140
137 // Creates an image of size |size|. 141 // Creates an image of size |size|.
138 gfx::ImageSkia CreateImage(int width, int height) { 142 gfx::ImageSkia CreateImage(int width, int height, SkColor color) {
139 SkBitmap bitmap; 143 SkBitmap bitmap;
140 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 144 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
141 bitmap.allocPixels(); 145 bitmap.allocPixels();
146 bitmap.eraseColor(color);
142 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 147 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
143 return image; 148 return image;
144 } 149 }
145 150
146 // Runs kAnimatingDesktopController's animation to completion. 151 // Runs kAnimatingDesktopController's animation to completion.
147 // TODO(bshe): Don't require tests to run animations; it's slow. 152 // TODO(bshe): Don't require tests to run animations; it's slow.
148 void RunDesktopControllerAnimation() { 153 void RunDesktopControllerAnimation() {
149 internal::DesktopBackgroundWidgetController* controller = 154 internal::DesktopBackgroundWidgetController* controller =
150 Shell::GetPrimaryRootWindowController()-> 155 Shell::GetPrimaryRootWindowController()->
151 animating_wallpaper_controller()->GetController(false); 156 animating_wallpaper_controller()->GetController(false);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 root_window_controller->wallpaper_controller()); 438 root_window_controller->wallpaper_controller());
434 } 439 }
435 440
436 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { 441 TEST_F(DesktopBackgroundControllerTest, DisplayChange) {
437 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. 442 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8.
438 if (!SupportsHostWindowResize()) 443 if (!SupportsHostWindowResize())
439 return; 444 return;
440 445
441 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the 446 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the
442 // display configuration changes. 447 // display configuration changes.
443 gfx::ImageSkia image = CreateImage(640, 480); 448 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
444 wallpaper_delegate_->set_custom_wallpaper(image); 449 wallpaper_delegate_->set_custom_wallpaper(image);
445 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 450 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
446 451
447 // Small wallpaper images should be used for configurations less than or 452 // Small wallpaper images should be used for configurations less than or
448 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if 453 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if
449 // multiple displays are connected. 454 // multiple displays are connected.
450 test::DisplayManagerTestApi display_manager_test_api( 455 test::DisplayManagerTestApi display_manager_test_api(
451 Shell::GetInstance()->display_manager()); 456 Shell::GetInstance()->display_manager());
452 display_manager_test_api.UpdateDisplay("800x600"); 457 display_manager_test_api.UpdateDisplay("800x600");
453 RunAllPendingInMessageLoop(); 458 RunAllPendingInMessageLoop();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 601 }
597 602
598 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { 603 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) {
599 if (!SupportsMultipleDisplays()) 604 if (!SupportsMultipleDisplays())
600 return; 605 return;
601 606
602 test::DisplayManagerTestApi display_manager_test_api( 607 test::DisplayManagerTestApi display_manager_test_api(
603 Shell::GetInstance()->display_manager()); 608 Shell::GetInstance()->display_manager());
604 display_manager_test_api.UpdateDisplay("320x200"); 609 display_manager_test_api.UpdateDisplay("320x200");
605 610
606 gfx::ImageSkia image = CreateImage(640, 480); 611 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
607 612
608 // Set the image as custom wallpaper, wait for the resize to finish, and check 613 // Set the image as custom wallpaper, wait for the resize to finish, and check
609 // that the resized image is the expected size. 614 // that the resized image is the expected size.
610 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 615 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
611 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); 616 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper()));
612 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 617 content::BrowserThread::GetBlockingPool()->FlushForTesting();
613 content::RunAllPendingInMessageLoop(); 618 content::RunAllPendingInMessageLoop();
614 gfx::ImageSkia resized_image = controller_->GetWallpaper(); 619 gfx::ImageSkia resized_image = controller_->GetWallpaper();
615 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); 620 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image));
616 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); 621 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 "500x600", 663 "500x600",
659 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 664 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
660 665
661 // Maximum width and height belongs to different displays. 666 // Maximum width and height belongs to different displays.
662 UpdateDisplay("400x300,100x500"); 667 UpdateDisplay("400x300,100x500");
663 EXPECT_EQ( 668 EXPECT_EQ(
664 "400x500", 669 "400x500",
665 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 670 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
666 } 671 }
667 672
673 TEST_F(DesktopBackgroundControllerTest, SwitchBetweenDefaultAndCustom) {
674 // Start loading the default wallpaper.
675 UpdateDisplay("640x480");
676 WriteWallpapersAndSetFlags();
677 ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
678
679 // Custom wallpaper should be applied immediately, canceling the default
680 // wallpaper load task.
681 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
682 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
683 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
684 kCustomWallpaperColor));
685
686 // A call to SetDefaultWallpaper() should return true now, indicating that a
687 // new load task was started (since the previous one was interrupted by
688 // SetCustomWallpaper()). See http://crbug.com/327443.
689 TestObserver observer(controller_);
690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
691 observer.WaitForWallpaperDataChanged();
692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
693 kSmallWallpaperColor));
694 }
695
668 } // namespace ash 696 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698