OLD | NEW |
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" |
11 #include "ash/desktop_background/desktop_background_controller_observer.h" | 11 #include "ash/desktop_background/desktop_background_controller_observer.h" |
12 #include "ash/desktop_background/desktop_background_widget_controller.h" | 12 #include "ash/desktop_background/desktop_background_widget_controller.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/display_manager_test_api.h" | 17 #include "ash/test/display_manager_test_api.h" |
18 #include "ash/test/test_user_wallpaper_delegate.h" | 18 #include "ash/test/test_user_wallpaper_delegate.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
| 26 #include "content/public/test/test_utils.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
27 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
29 #include "ui/compositor/test/layer_animator_test_controller.h" | 31 #include "ui/compositor/test/layer_animator_test_controller.h" |
30 #include "ui/gfx/codec/jpeg_codec.h" | 32 #include "ui/gfx/codec/jpeg_codec.h" |
31 #include "ui/gfx/point.h" | 33 #include "ui/gfx/point.h" |
32 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
33 | 35 |
34 using aura::RootWindow; | 36 using aura::RootWindow; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 static const SkColor kLargeWallpaperColor = SK_ColorRED; | 126 static const SkColor kLargeWallpaperColor = SK_ColorRED; |
125 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | 127 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; |
126 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | 128 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; |
127 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | 129 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; |
128 | 130 |
129 // Dimension used for width and height of default wallpaper images. A | 131 // Dimension used for width and height of default wallpaper images. A |
130 // small value is used to minimize the amount of time spent compressing | 132 // small value is used to minimize the amount of time spent compressing |
131 // and writing images. | 133 // and writing images. |
132 static const int kWallpaperSize = 2; | 134 static const int kWallpaperSize = 2; |
133 | 135 |
| 136 // Creates an image of size |size|. |
| 137 gfx::ImageSkia CreateImage(int width, int height) { |
| 138 SkBitmap bitmap; |
| 139 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 140 bitmap.allocPixels(); |
| 141 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 142 return image; |
| 143 } |
| 144 |
134 // Runs kAnimatingDesktopController's animation to completion. | 145 // Runs kAnimatingDesktopController's animation to completion. |
135 // TODO(bshe): Don't require tests to run animations; it's slow. | 146 // TODO(bshe): Don't require tests to run animations; it's slow. |
136 void RunDesktopControllerAnimation() { | 147 void RunDesktopControllerAnimation() { |
137 internal::DesktopBackgroundWidgetController* controller = | 148 internal::DesktopBackgroundWidgetController* controller = |
138 Shell::GetPrimaryRootWindowController()-> | 149 Shell::GetPrimaryRootWindowController()-> |
139 animating_wallpaper_controller()->GetController(false); | 150 animating_wallpaper_controller()->GetController(false); |
140 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 151 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
141 } | 152 } |
142 | 153 |
143 // Returns true if the color at the center of |image| is close to | 154 // Returns true if the color at the center of |image| is close to |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // The desktop controller should be the last created animating controller. | 430 // The desktop controller should be the last created animating controller. |
420 EXPECT_EQ(animating_controller, | 431 EXPECT_EQ(animating_controller, |
421 root_window_controller->wallpaper_controller()); | 432 root_window_controller->wallpaper_controller()); |
422 } | 433 } |
423 | 434 |
424 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { | 435 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { |
425 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | 436 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. |
426 if (!SupportsHostWindowResize()) | 437 if (!SupportsHostWindowResize()) |
427 return; | 438 return; |
428 | 439 |
429 test::DisplayManagerTestApi display_manager_test_api( | 440 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the |
430 Shell::GetInstance()->display_manager()); | 441 // display configuration changes. |
| 442 gfx::ImageSkia image = CreateImage(640, 480); |
| 443 wallpaper_delegate_->set_custom_wallpaper(image); |
| 444 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
431 | 445 |
432 // Small wallpaper images should be used for configurations less than or | 446 // Small wallpaper images should be used for configurations less than or |
433 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | 447 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if |
434 // multiple displays are connected. | 448 // multiple displays are connected. |
| 449 test::DisplayManagerTestApi display_manager_test_api( |
| 450 Shell::GetInstance()->display_manager()); |
435 display_manager_test_api.UpdateDisplay("800x600"); | 451 display_manager_test_api.UpdateDisplay("800x600"); |
436 RunAllPendingInMessageLoop(); | 452 RunAllPendingInMessageLoop(); |
437 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 453 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
438 controller_->GetAppropriateResolution()); | 454 controller_->GetAppropriateResolution()); |
439 EXPECT_EQ(0, | 455 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
440 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
441 | 456 |
442 display_manager_test_api.UpdateDisplay("800x600,800x600"); | 457 display_manager_test_api.UpdateDisplay("800x600,800x600"); |
443 RunAllPendingInMessageLoop(); | 458 RunAllPendingInMessageLoop(); |
444 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 459 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
445 controller_->GetAppropriateResolution()); | 460 controller_->GetAppropriateResolution()); |
446 EXPECT_EQ(0, | 461 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
447 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
448 | 462 |
449 display_manager_test_api.UpdateDisplay("1366x800"); | 463 display_manager_test_api.UpdateDisplay("1366x800"); |
450 RunAllPendingInMessageLoop(); | 464 RunAllPendingInMessageLoop(); |
451 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 465 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
452 controller_->GetAppropriateResolution()); | 466 controller_->GetAppropriateResolution()); |
453 EXPECT_EQ(1, | 467 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
454 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
455 | 468 |
456 // At larger sizes, large wallpapers should be used. | 469 // At larger sizes, large wallpapers should be used. |
457 display_manager_test_api.UpdateDisplay("1367x800"); | 470 display_manager_test_api.UpdateDisplay("1367x800"); |
458 RunAllPendingInMessageLoop(); | 471 RunAllPendingInMessageLoop(); |
459 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 472 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
460 controller_->GetAppropriateResolution()); | 473 controller_->GetAppropriateResolution()); |
461 EXPECT_EQ(1, | 474 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
462 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
463 | 475 |
464 display_manager_test_api.UpdateDisplay("1367x801"); | 476 display_manager_test_api.UpdateDisplay("1367x801"); |
465 RunAllPendingInMessageLoop(); | 477 RunAllPendingInMessageLoop(); |
466 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 478 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
467 controller_->GetAppropriateResolution()); | 479 controller_->GetAppropriateResolution()); |
468 EXPECT_EQ(1, | 480 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
469 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
470 | 481 |
471 display_manager_test_api.UpdateDisplay("2560x1700"); | 482 display_manager_test_api.UpdateDisplay("2560x1700"); |
472 RunAllPendingInMessageLoop(); | 483 RunAllPendingInMessageLoop(); |
473 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 484 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
474 controller_->GetAppropriateResolution()); | 485 controller_->GetAppropriateResolution()); |
475 EXPECT_EQ(1, | 486 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
476 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
477 | 487 |
478 // Rotated smaller screen may use larger image. | 488 // Rotated smaller screen may use larger image. |
479 display_manager_test_api.UpdateDisplay("800x600/r"); | 489 display_manager_test_api.UpdateDisplay("800x600/r"); |
480 RunAllPendingInMessageLoop(); | 490 RunAllPendingInMessageLoop(); |
481 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 491 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
482 controller_->GetAppropriateResolution()); | 492 controller_->GetAppropriateResolution()); |
483 EXPECT_EQ(1, | 493 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
484 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
485 | 494 |
486 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); | 495 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); |
487 RunAllPendingInMessageLoop(); | 496 RunAllPendingInMessageLoop(); |
488 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 497 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
489 controller_->GetAppropriateResolution()); | 498 controller_->GetAppropriateResolution()); |
490 EXPECT_EQ(1, | 499 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
491 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
492 display_manager_test_api.UpdateDisplay("1366x800/r"); | 500 display_manager_test_api.UpdateDisplay("1366x800/r"); |
493 RunAllPendingInMessageLoop(); | 501 RunAllPendingInMessageLoop(); |
494 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 502 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
495 controller_->GetAppropriateResolution()); | 503 controller_->GetAppropriateResolution()); |
496 EXPECT_EQ(1, | 504 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
497 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
498 | 505 |
499 // Max display size didn't chagne. | 506 // Max display size didn't chagne. |
500 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); | 507 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); |
501 RunAllPendingInMessageLoop(); | 508 RunAllPendingInMessageLoop(); |
502 EXPECT_EQ(0, | 509 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
503 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
504 | |
505 } | 510 } |
506 | 511 |
507 // Test that DesktopBackgroundController loads the appropriate wallpaper | 512 // Test that DesktopBackgroundController loads the appropriate wallpaper |
508 // images as specified via command-line flags in various situations. | 513 // images as specified via command-line flags in various situations. |
509 // Splitting these into separate tests avoids needing to run animations. | 514 // Splitting these into separate tests avoids needing to run animations. |
510 // TODO(derat): Combine these into a single test -- see | 515 // TODO(derat): Combine these into a single test -- see |
511 // RunDesktopControllerAnimation()'s TODO. | 516 // RunDesktopControllerAnimation()'s TODO. |
512 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { | 517 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { |
513 if (!SupportsMultipleDisplays()) | 518 if (!SupportsMultipleDisplays()) |
514 return; | 519 return; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 TestObserver observer(controller_); | 587 TestObserver observer(controller_); |
583 test::DisplayManagerTestApi display_manager_test_api( | 588 test::DisplayManagerTestApi display_manager_test_api( |
584 Shell::GetInstance()->display_manager()); | 589 Shell::GetInstance()->display_manager()); |
585 display_manager_test_api.UpdateDisplay("1600x1200"); | 590 display_manager_test_api.UpdateDisplay("1600x1200"); |
586 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); | 591 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); |
587 observer.WaitForWallpaperDataChanged(); | 592 observer.WaitForWallpaperDataChanged(); |
588 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | 593 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
589 kLargeGuestWallpaperColor)); | 594 kLargeGuestWallpaperColor)); |
590 } | 595 } |
591 | 596 |
| 597 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
| 598 if (!SupportsMultipleDisplays()) |
| 599 return; |
| 600 |
| 601 test::DisplayManagerTestApi display_manager_test_api( |
| 602 Shell::GetInstance()->display_manager()); |
| 603 display_manager_test_api.UpdateDisplay("320x200"); |
| 604 |
| 605 gfx::ImageSkia image = CreateImage(640, 480); |
| 606 |
| 607 // Set the image as custom wallpaper, wait for the resize to finish, and check |
| 608 // that the resized image is the expected size. |
| 609 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
| 610 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 611 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 612 content::RunAllPendingInMessageLoop(); |
| 613 gfx::ImageSkia resized_image = controller_->GetWallpaper(); |
| 614 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); |
| 615 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); |
| 616 |
| 617 // Load the original wallpaper again and check that we're still using the |
| 618 // previously-resized image instead of doing another resize |
| 619 // (http://crbug.com/321402). |
| 620 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
| 621 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 622 content::RunAllPendingInMessageLoop(); |
| 623 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 624 } |
| 625 |
592 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { | 626 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { |
593 // Device scale factor shouldn't affect the native size. | 627 // Device scale factor shouldn't affect the native size. |
594 UpdateDisplay("1000x300*2"); | 628 UpdateDisplay("1000x300*2"); |
595 EXPECT_EQ( | 629 EXPECT_EQ( |
596 "1000x300", | 630 "1000x300", |
597 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 631 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
598 | 632 |
599 // Rotated display should return the rotated size. | 633 // Rotated display should return the rotated size. |
600 UpdateDisplay("1000x300*2/r"); | 634 UpdateDisplay("1000x300*2/r"); |
601 EXPECT_EQ( | 635 EXPECT_EQ( |
(...skipping 22 matching lines...) Expand all Loading... |
624 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 658 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
625 | 659 |
626 // Maximum width and height belongs to different displays. | 660 // Maximum width and height belongs to different displays. |
627 UpdateDisplay("400x300,100x500"); | 661 UpdateDisplay("400x300,100x500"); |
628 EXPECT_EQ( | 662 EXPECT_EQ( |
629 "400x500", | 663 "400x500", |
630 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 664 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
631 } | 665 } |
632 | 666 |
633 } // namespace ash | 667 } // namespace ash |
OLD | NEW |