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

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

Issue 208273005: If customization includes default wallpaper, download and apply it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DBC::IsUsingDefaultWallpaper(); Restart wallpaper fetch on device restart. Created 6 years, 9 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
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"
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"
20 #include "base/file_util.h" 19 #include "base/file_util.h"
21 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
22 #include "base/files/scoped_temp_dir.h" 21 #include "base/files/scoped_temp_dir.h"
23 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
24 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
27 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "third_party/skia/include/core/SkColor.h" 28 #include "third_party/skia/include/core/SkColor.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 base::TimeTicks step_time = controller.animator()->last_step_time(); 94 base::TimeTicks step_time = controller.animator()->last_step_time();
96 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 95 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
97 } 96 }
98 } 97 }
99 98
100 } // namespace 99 } // namespace
101 100
102 class DesktopBackgroundControllerTest : public test::AshTestBase { 101 class DesktopBackgroundControllerTest : public test::AshTestBase {
103 public: 102 public:
104 DesktopBackgroundControllerTest() 103 DesktopBackgroundControllerTest()
105 : command_line_(CommandLine::NO_PROGRAM), 104 : controller_(NULL) {
106 controller_(NULL) {
107 } 105 }
108 virtual ~DesktopBackgroundControllerTest() {} 106 virtual ~DesktopBackgroundControllerTest() {}
109 107
110 virtual void SetUp() OVERRIDE { 108 virtual void SetUp() OVERRIDE {
111 test::AshTestBase::SetUp(); 109 test::AshTestBase::SetUp();
112 // Ash shell initialization creates wallpaper. Reset it so we can manually 110 // Ash shell initialization creates wallpaper. Reset it so we can manually
113 // control wallpaper creation and animation in our tests. 111 // control wallpaper creation and animation in our tests.
114 internal::RootWindowController* root_window_controller = 112 internal::RootWindowController* root_window_controller =
115 Shell::GetPrimaryRootWindowController(); 113 Shell::GetPrimaryRootWindowController();
116 root_window_controller->SetWallpaperController(NULL); 114 root_window_controller->SetWallpaperController(NULL);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 return false; 221 return false;
224 } 222 }
225 223
226 return true; 224 return true;
227 } 225 }
228 226
229 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and 227 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and
230 // passes |controller_| a command line instructing it to use the images. 228 // passes |controller_| a command line instructing it to use the images.
231 // Only needs to be called (once) by tests that want to test loading of 229 // Only needs to be called (once) by tests that want to test loading of
232 // default wallpapers. 230 // default wallpapers.
233 void WriteWallpapersAndSetFlags() { 231 void WriteWallpapersAndSetFlags() {
Daniel Erat 2014/03/25 21:58:29 nit: rename this to something like WriteWallpapers
Alexander Alekseev 2014/03/27 00:28:37 Done.
234 wallpaper_dir_.reset(new base::ScopedTempDir); 232 wallpaper_dir_.reset(new base::ScopedTempDir);
235 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); 233 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir());
236 234
237 const base::FilePath kLargePath = 235 default_large_file_ =
238 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); 236 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg"));
239 ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, 237 ASSERT_TRUE(WriteJPEGFile(default_large_file_,
238 kWallpaperSize,
239 kWallpaperSize,
240 kLargeWallpaperColor)); 240 kLargeWallpaperColor));
241 command_line_.AppendSwitchPath( 241 default_small_file_ =
242 switches::kAshDefaultWallpaperLarge, kLargePath);
243
244 const base::FilePath kSmallPath =
245 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); 242 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg"));
246 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, 243 ASSERT_TRUE(WriteJPEGFile(default_small_file_,
244 kWallpaperSize,
245 kWallpaperSize,
247 kSmallWallpaperColor)); 246 kSmallWallpaperColor));
248 command_line_.AppendSwitchPath( 247 guest_default_large_file_ =
249 switches::kAshDefaultWallpaperSmall, kSmallPath);
250
251 const base::FilePath kLargeGuestPath =
252 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); 248 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg"));
253 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, 249 ASSERT_TRUE(WriteJPEGFile(guest_default_large_file_,
250 kWallpaperSize,
251 kWallpaperSize,
254 kLargeGuestWallpaperColor)); 252 kLargeGuestWallpaperColor));
255 command_line_.AppendSwitchPath( 253 guest_default_small_file_ =
256 switches::kAshGuestWallpaperLarge, kLargeGuestPath);
257
258 const base::FilePath kSmallGuestPath =
259 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); 254 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg"));
260 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, 255 ASSERT_TRUE(WriteJPEGFile(guest_default_small_file_,
256 kWallpaperSize,
257 kWallpaperSize,
261 kSmallGuestWallpaperColor)); 258 kSmallGuestWallpaperColor));
262 command_line_.AppendSwitchPath(
263 switches::kAshGuestWallpaperSmall, kSmallGuestPath);
264
265 controller_->set_command_line_for_testing(&command_line_);
266 } 259 }
267 260
268 // Custom command line passed to DesktopBackgroundController by
269 // WriteWallpapersAndSetFlags().
270 CommandLine command_line_;
271
272 // Directory created by WriteWallpapersAndSetFlags() to store default 261 // Directory created by WriteWallpapersAndSetFlags() to store default
273 // wallpaper images. 262 // wallpaper images.
274 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; 263 scoped_ptr<base::ScopedTempDir> wallpaper_dir_;
275 264
276 DesktopBackgroundController* controller_; // Not owned. 265 DesktopBackgroundController* controller_; // Not owned.
277 266
278 test::TestUserWallpaperDelegate* wallpaper_delegate_; 267 test::TestUserWallpaperDelegate* wallpaper_delegate_;
279 268
269 base::FilePath default_small_file_;
270 base::FilePath default_large_file_;
271
272 base::FilePath guest_default_small_file_;
273 base::FilePath guest_default_large_file_;
274
280 private: 275 private:
281 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); 276 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest);
282 }; 277 };
283 278
284 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { 279 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) {
285 DesktopBackgroundController* controller = 280 DesktopBackgroundController* controller =
286 Shell::GetInstance()->desktop_background_controller(); 281 Shell::GetInstance()->desktop_background_controller();
287 controller->CreateEmptyWallpaper(); 282 controller->CreateEmptyWallpaper();
288 283
289 // Wallpaper view/window exists in the desktop background container and 284 // Wallpaper view/window exists in the desktop background container and
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (!SupportsMultipleDisplays()) 519 if (!SupportsMultipleDisplays())
525 return; 520 return;
526 521
527 WriteWallpapersAndSetFlags(); 522 WriteWallpapersAndSetFlags();
528 TestObserver observer(controller_); 523 TestObserver observer(controller_);
529 524
530 // At 800x600, the small wallpaper should be loaded. 525 // At 800x600, the small wallpaper should be loaded.
531 test::DisplayManagerTestApi display_manager_test_api( 526 test::DisplayManagerTestApi display_manager_test_api(
532 Shell::GetInstance()->display_manager()); 527 Shell::GetInstance()->display_manager());
533 display_manager_test_api.UpdateDisplay("800x600"); 528 display_manager_test_api.UpdateDisplay("800x600");
534 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 529 ASSERT_TRUE(controller_->SetDefaultWallpaper(default_small_file_,
530 default_large_file_));
535 observer.WaitForWallpaperDataChanged(); 531 observer.WaitForWallpaperDataChanged();
536 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 532 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
537 kSmallWallpaperColor)); 533 kSmallWallpaperColor));
538 534
539 // Requesting the same wallpaper again should be a no-op. 535 // Requesting the same wallpaper again should be a no-op.
540 ASSERT_FALSE(controller_->SetDefaultWallpaper(false)); 536 ASSERT_FALSE(controller_->SetDefaultWallpaper(default_small_file_,
537 default_large_file_));
541 } 538 }
542 539
543 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) { 540 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) {
544 if (!SupportsMultipleDisplays()) 541 if (!SupportsMultipleDisplays())
545 return; 542 return;
546 543
547 WriteWallpapersAndSetFlags(); 544 WriteWallpapersAndSetFlags();
548 TestObserver observer(controller_); 545 TestObserver observer(controller_);
549 test::DisplayManagerTestApi display_manager_test_api( 546 test::DisplayManagerTestApi display_manager_test_api(
550 Shell::GetInstance()->display_manager()); 547 Shell::GetInstance()->display_manager());
551 display_manager_test_api.UpdateDisplay("1600x1200"); 548 display_manager_test_api.UpdateDisplay("1600x1200");
552 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 549 ASSERT_TRUE(controller_->SetDefaultWallpaper(default_small_file_,
550 default_large_file_));
553 observer.WaitForWallpaperDataChanged(); 551 observer.WaitForWallpaperDataChanged();
554 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 552 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
555 kLargeWallpaperColor)); 553 kLargeWallpaperColor));
556 } 554 }
557 555
558 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaperWhenRotated) { 556 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaperWhenRotated) {
559 if (!SupportsMultipleDisplays()) 557 if (!SupportsMultipleDisplays())
560 return; 558 return;
561 WriteWallpapersAndSetFlags(); 559 WriteWallpapersAndSetFlags();
562 TestObserver observer(controller_); 560 TestObserver observer(controller_);
563 test::DisplayManagerTestApi display_manager_test_api( 561 test::DisplayManagerTestApi display_manager_test_api(
564 Shell::GetInstance()->display_manager()); 562 Shell::GetInstance()->display_manager());
565 563
566 display_manager_test_api.UpdateDisplay("1200x800/r"); 564 display_manager_test_api.UpdateDisplay("1200x800/r");
567 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 565 ASSERT_TRUE(controller_->SetDefaultWallpaper(default_small_file_,
566 default_large_file_));
568 observer.WaitForWallpaperDataChanged(); 567 observer.WaitForWallpaperDataChanged();
569 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 568 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
570 kLargeWallpaperColor)); 569 kLargeWallpaperColor));
571 } 570 }
572 571
573 TEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) { 572 TEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) {
574 if (!SupportsMultipleDisplays()) 573 if (!SupportsMultipleDisplays())
575 return; 574 return;
576 575
577 WriteWallpapersAndSetFlags(); 576 WriteWallpapersAndSetFlags();
578 TestObserver observer(controller_); 577 TestObserver observer(controller_);
579 test::DisplayManagerTestApi display_manager_test_api( 578 test::DisplayManagerTestApi display_manager_test_api(
580 Shell::GetInstance()->display_manager()); 579 Shell::GetInstance()->display_manager());
581 display_manager_test_api.UpdateDisplay("800x600"); 580 display_manager_test_api.UpdateDisplay("800x600");
582 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 581 ASSERT_TRUE(controller_->SetDefaultWallpaper(guest_default_small_file_,
582 guest_default_large_file_));
583 observer.WaitForWallpaperDataChanged(); 583 observer.WaitForWallpaperDataChanged();
584 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 584 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
585 kSmallGuestWallpaperColor)); 585 kSmallGuestWallpaperColor));
586 } 586 }
587 587
588 TEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) { 588 TEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) {
589 if (!SupportsMultipleDisplays()) 589 if (!SupportsMultipleDisplays())
590 return; 590 return;
591 591
592 WriteWallpapersAndSetFlags(); 592 WriteWallpapersAndSetFlags();
593 TestObserver observer(controller_); 593 TestObserver observer(controller_);
594 test::DisplayManagerTestApi display_manager_test_api( 594 test::DisplayManagerTestApi display_manager_test_api(
595 Shell::GetInstance()->display_manager()); 595 Shell::GetInstance()->display_manager());
596 display_manager_test_api.UpdateDisplay("1600x1200"); 596 display_manager_test_api.UpdateDisplay("1600x1200");
597 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); 597 ASSERT_TRUE(controller_->SetDefaultWallpaper(guest_default_small_file_,
598 guest_default_large_file_));
598 observer.WaitForWallpaperDataChanged(); 599 observer.WaitForWallpaperDataChanged();
599 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 600 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
600 kLargeGuestWallpaperColor)); 601 kLargeGuestWallpaperColor));
601 } 602 }
602 603
603 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { 604 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) {
604 if (!SupportsMultipleDisplays()) 605 if (!SupportsMultipleDisplays())
605 return; 606 return;
606 607
607 test::DisplayManagerTestApi display_manager_test_api( 608 test::DisplayManagerTestApi display_manager_test_api(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 UpdateDisplay("400x300,100x500"); 668 UpdateDisplay("400x300,100x500");
668 EXPECT_EQ( 669 EXPECT_EQ(
669 "400x500", 670 "400x500",
670 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 671 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
671 } 672 }
672 673
673 TEST_F(DesktopBackgroundControllerTest, SwitchBetweenDefaultAndCustom) { 674 TEST_F(DesktopBackgroundControllerTest, SwitchBetweenDefaultAndCustom) {
674 // Start loading the default wallpaper. 675 // Start loading the default wallpaper.
675 UpdateDisplay("640x480"); 676 UpdateDisplay("640x480");
676 WriteWallpapersAndSetFlags(); 677 WriteWallpapersAndSetFlags();
677 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 678 ASSERT_TRUE(controller_->SetDefaultWallpaper(default_small_file_,
679 default_large_file_));
678 680
679 // Custom wallpaper should be applied immediately, canceling the default 681 // Custom wallpaper should be applied immediately, canceling the default
680 // wallpaper load task. 682 // wallpaper load task.
681 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); 683 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
682 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 684 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
683 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 685 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
684 kCustomWallpaperColor)); 686 kCustomWallpaperColor));
685 687
686 // A call to SetDefaultWallpaper() should return true now, indicating that a 688 // A call to SetDefaultWallpaper() should return true now, indicating that a
687 // new load task was started (since the previous one was interrupted by 689 // new load task was started (since the previous one was interrupted by
688 // SetCustomWallpaper()). See http://crbug.com/327443. 690 // SetCustomWallpaper()). See http://crbug.com/327443.
689 TestObserver observer(controller_); 691 TestObserver observer(controller_);
690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); 692 ASSERT_TRUE(controller_->SetDefaultWallpaper(default_small_file_,
693 default_large_file_));
691 observer.WaitForWallpaperDataChanged(); 694 observer.WaitForWallpaperDataChanged();
692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), 695 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
693 kSmallWallpaperColor)); 696 kSmallWallpaperColor));
694 } 697 }
695 698
696 } // namespace ash 699 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698