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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc

Issue 2619653002: ash: SessionControllerClient observes user image change (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/common/wallpaper/wallpaper_controller.h" 9 #include "ash/common/wallpaper/wallpaper_controller.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/ash_test_helper.h" 13 #include "ash/test/ash_test_helper.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u tils.h" 24 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u tils.h"
25 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
26 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/testing_browser_process.h" 27 #include "chrome/test/base/testing_browser_process.h"
28 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
29 #include "components/prefs/scoped_user_pref_update.h" 29 #include "components/prefs/scoped_user_pref_update.h"
30 #include "components/session_manager/core/session_manager.h"
30 #include "components/signin/core/account_id/account_id.h" 31 #include "components/signin/core/account_id/account_id.h"
31 #include "components/user_manager/user.h" 32 #include "components/user_manager/user.h"
32 #include "components/user_manager/user_manager.h" 33 #include "components/user_manager/user_manager.h"
33 #include "components/user_manager/user_names.h" 34 #include "components/user_manager/user_names.h"
34 #include "components/wallpaper/wallpaper_files_id.h" 35 #include "components/wallpaper/wallpaper_files_id.h"
35 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
36 #include "ui/aura/env.h" 37 #include "ui/aura/env.h"
37 #include "ui/display/manager/display_manager.h" 38 #include "ui/display/manager/display_manager.h"
38 #include "ui/display/test/display_manager_test_api.h" 39 #include "ui/display/test/display_manager_test_api.h"
39 #include "ui/gfx/geometry/point.h" 40 #include "ui/gfx/geometry/point.h"
40 #include "ui/gfx/geometry/rect.h" 41 #include "ui/gfx/geometry/rect.h"
41 #include "ui/gfx/image/image_skia.h" 42 #include "ui/gfx/image/image_skia.h"
42 43
44 using session_manager::SessionManager;
43 using wallpaper::WallpaperInfo; 45 using wallpaper::WallpaperInfo;
44 using wallpaper::WALLPAPER_LAYOUT_CENTER; 46 using wallpaper::WALLPAPER_LAYOUT_CENTER;
45 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 47 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
46 using wallpaper::WALLPAPER_LAYOUT_STRETCH; 48 using wallpaper::WALLPAPER_LAYOUT_STRETCH;
47 using wallpaper::WALLPAPER_LAYOUT_TILE; 49 using wallpaper::WALLPAPER_LAYOUT_TILE;
48 50
49 namespace chromeos { 51 namespace chromeos {
50 52
51 namespace { 53 namespace {
52 54
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, 109 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir,
108 wallpaper_files_id, id); 110 wallpaper_files_id, id);
109 if (!base::DirectoryExists(wallpaper_path.DirName())) 111 if (!base::DirectoryExists(wallpaper_path.DirName()))
110 base::CreateDirectory(wallpaper_path.DirName()); 112 base::CreateDirectory(wallpaper_path.DirName());
111 113
112 return wallpaper_path; 114 return wallpaper_path;
113 } 115 }
114 116
115 // Logs in |account_id|. 117 // Logs in |account_id|.
116 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { 118 void LogIn(const AccountId& account_id, const std::string& user_id_hash) {
117 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, 119 SessionManager::Get()->CreateSession(account_id, user_id_hash);
118 false);
119 // Adding a secondary display creates a shelf on that display, which 120 // Adding a secondary display creates a shelf on that display, which
120 // assumes a shelf on the primary display if the user was logged in. 121 // assumes a shelf on the primary display if the user was logged in.
121 ash::WmShell::Get()->CreateShelf(); 122 ash::WmShell::Get()->CreateShelf();
122 WaitAsyncWallpaperLoadStarted(); 123 WaitAsyncWallpaperLoadStarted();
123 } 124 }
124 125
125 // Logs in |account_id| and sets it as child account. 126 // Logs in |account_id| and sets it as child account.
126 void LogInAsChild(const AccountId& account_id, 127 void LogInAsChild(const AccountId& account_id,
127 const std::string& user_id_hash) { 128 const std::string& user_id_hash) {
128 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, 129 SessionManager::Get()->CreateSession(account_id, user_id_hash);
129 false);
130 user_manager::User* user = 130 user_manager::User* user =
131 user_manager::UserManager::Get()->FindUserAndModify(account_id); 131 user_manager::UserManager::Get()->FindUserAndModify(account_id);
132 user_manager::UserManager::Get()->ChangeUserChildStatus( 132 user_manager::UserManager::Get()->ChangeUserChildStatus(
133 user, true /* is_child */); 133 user, true /* is_child */);
134 // TODO(jamescook): For some reason creating the shelf here (which is what 134 // TODO(jamescook): For some reason creating the shelf here (which is what
135 // would happen in normal login) causes the child wallpaper tests to fail 135 // would happen in normal login) causes the child wallpaper tests to fail
136 // with the wallpaper having alpha. This looks like the wallpaper is mid- 136 // with the wallpaper having alpha. This looks like the wallpaper is mid-
137 // animation, but happens even if animations are disabled. Something is 137 // animation, but happens even if animations are disabled. Something is
138 // wrong with how these tests simulate login. 138 // wrong with how these tests simulate login.
139 } 139 }
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations); 447 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations);
448 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation); 448 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation);
449 command_line->AppendSwitchASCII(switches::kLoginUser, 449 command_line->AppendSwitchASCII(switches::kLoginUser,
450 test_account_id1_.GetUserEmail()); 450 test_account_id1_.GetUserEmail());
451 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 451 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
452 } 452 }
453 }; 453 };
454 454
455 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, 455 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
456 PRE_RestoreWallpaper) { 456 PRE_RestoreWallpaper) {
457 LogIn(test_account_id1_, kTestUser1Hash); 457 // No need to explicitly login for crash-n-restore.
458 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 458 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
459 } 459 }
460 460
461 // Test for crbug.com/270278. It simulates a browser crash and verifies if user 461 // Test for crbug.com/270278. It simulates a browser crash and verifies if user
462 // wallpaper is loaded. 462 // wallpaper is loaded.
463 // Fails on the MSAN bots. See http://crbug.com/444477 463 // Fails on the MSAN bots. See http://crbug.com/444477
464 #if defined(MEMORY_SANITIZER) 464 #if defined(MEMORY_SANITIZER)
465 #define MAYBE_RestoreWallpaper DISABLED_RestoreWallpaper 465 #define MAYBE_RestoreWallpaper DISABLED_RestoreWallpaper
466 #else 466 #else
467 #define MAYBE_RestoreWallpaper RestoreWallpaper 467 #define MAYBE_RestoreWallpaper RestoreWallpaper
468 #endif 468 #endif
469 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, 469 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
470 MAYBE_RestoreWallpaper) { 470 MAYBE_RestoreWallpaper) {
471 EXPECT_EQ(1, LoadedWallpapers()); 471 EXPECT_EQ(1, LoadedWallpapers());
472 } 472 }
473 473
474 class WallpaperManagerBrowserTestCacheUpdate 474 class WallpaperManagerBrowserTestCacheUpdate
475 : public WallpaperManagerBrowserTest { 475 : public WallpaperManagerBrowserTest {
476 public:
477 void SetUpCommandLine(base::CommandLine* command_line) override {
478 command_line->AppendSwitchASCII(switches::kLoginUser,
479 test_account_id1_.GetUserEmail());
480 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
481 }
482 protected: 476 protected:
483 // Creates a test image of size 1x1. 477 // Creates a test image of size 1x1.
484 gfx::ImageSkia CreateTestImage(SkColor color) { 478 gfx::ImageSkia CreateTestImage(SkColor color) {
485 return wallpaper_manager_test_utils::CreateTestImage(1, 1, color); 479 return wallpaper_manager_test_utils::CreateTestImage(1, 1, color);
486 } 480 }
487 }; 481 };
488 482
489 // Sets test_account_id1_'s wallpaper to a custom wallpaper. 483 // Sets test_account_id1_'s wallpaper to a custom wallpaper.
490 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, 484 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
491 PRE_VerifyWallpaperCache) { 485 PRE_VerifyWallpaperCache) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // multi-profile mode when user: 531 // multi-profile mode when user:
538 // 1. chooses an online wallpaper from wallpaper 532 // 1. chooses an online wallpaper from wallpaper
539 // picker (calls SetWallpaperFromImageSkia); 533 // picker (calls SetWallpaperFromImageSkia);
540 // 2. chooses a custom wallpaper from wallpaper 534 // 2. chooses a custom wallpaper from wallpaper
541 // picker (calls SetCustomWallpaper); 535 // picker (calls SetCustomWallpaper);
542 // 3. reverts to a default wallpaper. 536 // 3. reverts to a default wallpaper.
543 // Also, when user login at multi-profile mode, previous logged in users' 537 // Also, when user login at multi-profile mode, previous logged in users'
544 // wallpaper cache should not be deleted. 538 // wallpaper cache should not be deleted.
545 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, 539 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
546 VerifyWallpaperCache) { 540 VerifyWallpaperCache) {
541 LogIn(test_account_id1_, kTestUser1Hash);
542
547 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); 543 WallpaperManager* wallpaper_manager = WallpaperManager::Get();
548 544
549 // Force load initial wallpaper 545 // Force load initial wallpaper
550 // (simulate WallpaperController::UpdateDisplay()). 546 // (simulate WallpaperController::UpdateDisplay()).
551 wallpaper_manager->UpdateWallpaper(true); 547 wallpaper_manager->UpdateWallpaper(true);
552 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 548 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
553 std::unique_ptr<WallpaperManager::TestApi> test_api; 549 std::unique_ptr<WallpaperManager::TestApi> test_api;
554 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); 550 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager));
555 gfx::ImageSkia cached_wallpaper; 551 gfx::ImageSkia cached_wallpaper;
556 // Previous custom wallpaper should be cached after user login. 552 // Previous custom wallpaper should be cached after user login.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 755 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
760 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 756 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
761 controller_->GetWallpaper(), 757 controller_->GetWallpaper(),
762 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 758 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
763 } 759 }
764 760
765 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallGuestWallpaper) { 761 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallGuestWallpaper) {
766 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 762 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
767 return; 763 return;
768 CreateCmdlineWallpapers(); 764 CreateCmdlineWallpapers();
769 user_manager::UserManager::Get()->UserLoggedIn( 765 SessionManager::Get()->CreateSession(user_manager::GuestAccountId(),
770 user_manager::GuestAccountId(), user_manager::kGuestUserName, false); 766 user_manager::kGuestUserName);
771 UpdateDisplay("800x600"); 767 UpdateDisplay("800x600");
772 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 768 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
773 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 769 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
774 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 770 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
775 controller_->GetWallpaper(), 771 controller_->GetWallpaper(),
776 wallpaper_manager_test_utils::kSmallGuestWallpaperColor)); 772 wallpaper_manager_test_utils::kSmallGuestWallpaperColor));
777 } 773 }
778 774
779 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeGuestWallpaper) { 775 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeGuestWallpaper) {
780 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 776 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
781 return; 777 return;
782 778
783 CreateCmdlineWallpapers(); 779 CreateCmdlineWallpapers();
784 user_manager::UserManager::Get()->UserLoggedIn( 780 SessionManager::Get()->CreateSession(user_manager::GuestAccountId(),
785 user_manager::GuestAccountId(), user_manager::kGuestUserName, false); 781 user_manager::kGuestUserName);
786 UpdateDisplay("1600x1200"); 782 UpdateDisplay("1600x1200");
787 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 783 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
788 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 784 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
789 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 785 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
790 controller_->GetWallpaper(), 786 controller_->GetWallpaper(),
791 wallpaper_manager_test_utils::kLargeGuestWallpaperColor)); 787 wallpaper_manager_test_utils::kLargeGuestWallpaperColor));
792 } 788 }
793 789
794 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallChildWallpaper) { 790 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallChildWallpaper) {
795 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 791 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
(...skipping 20 matching lines...) Expand all
816 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 812 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
817 controller_->GetWallpaper(), 813 controller_->GetWallpaper(),
818 wallpaper_manager_test_utils::kLargeChildWallpaperColor)); 814 wallpaper_manager_test_utils::kLargeChildWallpaperColor));
819 } 815 }
820 816
821 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 817 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
822 SwitchBetweenDefaultAndCustom) { 818 SwitchBetweenDefaultAndCustom) {
823 // Start loading the default wallpaper. 819 // Start loading the default wallpaper.
824 UpdateDisplay("640x480"); 820 UpdateDisplay("640x480");
825 CreateCmdlineWallpapers(); 821 CreateCmdlineWallpapers();
826 user_manager::UserManager::Get()->UserLoggedIn(user_manager::StubAccountId(), 822 SessionManager::Get()->CreateSession(user_manager::StubAccountId(),
827 "test_hash", false); 823 "test_hash");
828 824
829 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 825 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
830 826
831 // Custom wallpaper should be applied immediately, canceling the default 827 // Custom wallpaper should be applied immediately, canceling the default
832 // wallpaper load task. 828 // wallpaper load task.
833 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( 829 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage(
834 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); 830 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor);
835 WallpaperManager::Get()->SetCustomWallpaper( 831 WallpaperManager::Get()->SetCustomWallpaper(
836 user_manager::StubAccountId(), 832 user_manager::StubAccountId(),
837 wallpaper::WallpaperFilesId::FromString("test_hash"), "test-nofile.jpeg", 833 wallpaper::WallpaperFilesId::FromString("test_hash"), "test-nofile.jpeg",
838 WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, image, true); 834 WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, image, true);
839 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 835 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
840 836
841 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 837 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
842 controller_->GetWallpaper(), 838 controller_->GetWallpaper(),
843 wallpaper_manager_test_utils::kCustomWallpaperColor)); 839 wallpaper_manager_test_utils::kCustomWallpaperColor));
844 840
845 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); 841 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
846 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 842 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
847 843
848 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 844 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
849 controller_->GetWallpaper(), 845 controller_->GetWallpaper(),
850 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 846 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
851 } 847 }
852 848
853 } // namespace chromeos 849 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698