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

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager_unittest.cc

Issue 215293003: Move all wallpaper file loading and decoding from DesktopBackgroundController to WallpaperManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clang debug build. Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <cstdlib> 5 #include <cstdlib>
6 #include <cstring> 6 #include <cstring>
7 7
8 #include "ash/ash_resources/grit/ash_resources.h" 8 #include "ash/ash_resources/grit/ash_resources.h"
9 #include "ash/desktop_background/desktop_background_controller.h" 9 #include "ash/desktop_background/desktop_background_controller.h"
10 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/display_manager_test_api.h"
14 #include "ash/test/test_user_wallpaper_delegate.h"
12 #include "base/command_line.h" 15 #include "base/command_line.h"
13 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/files/file_path.h"
18 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
15 #include "base/prefs/pref_service.h" 20 #include "base/prefs/pref_service.h"
16 #include "base/prefs/testing_pref_service.h" 21 #include "base/prefs/testing_pref_service.h"
17 #include "chrome/browser/chromeos/login/fake_user_manager.h" 22 #include "chrome/browser/chromeos/login/fake_user_manager.h"
18 #include "chrome/browser/chromeos/login/startup_utils.h" 23 #include "chrome/browser/chromeos/login/startup_utils.h"
19 #include "chrome/browser/chromeos/login/user_manager_impl.h" 24 #include "chrome/browser/chromeos/login/user_manager_impl.h"
20 #include "chrome/browser/chromeos/login/wallpaper_manager.h" 25 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 26 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chrome/browser/chromeos/settings/device_settings_service.h" 27 #include "chrome/browser/chromeos/settings/device_settings_service.h"
28 #include "chrome/browser/prefs/browser_prefs.h"
23 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/testing_browser_process.h" 30 #include "chrome/test/base/testing_browser_process.h"
25 #include "chromeos/chromeos_switches.h" 31 #include "chromeos/chromeos_switches.h"
26 #include "chromeos/settings/cros_settings_names.h" 32 #include "chromeos/settings/cros_settings_names.h"
27 #include "chromeos/settings/cros_settings_provider.h" 33 #include "chromeos/settings/cros_settings_provider.h"
28 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
29 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/image/image.h"
30 37
31 using namespace ash; 38 using namespace ash;
32 39
33 const char kTestUser1[] = "test-user@example.com";
34 const char kTestUser1Hash[] = "test-user@example.com-hash";
35
36 namespace chromeos { 40 namespace chromeos {
37 41
38 class WallpaperManagerTest : public test::AshTestBase {
39 public:
40 WallpaperManagerTest() : command_line_(CommandLine::NO_PROGRAM) {}
41
42 virtual ~WallpaperManagerTest() {}
43
44 virtual void SetUp() OVERRIDE {
45 test::AshTestBase::SetUp();
46
47 // Register an in-memory local settings instance.
48 local_state_.reset(new TestingPrefServiceSimple);
49 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get());
50 UserManager::RegisterPrefs(local_state_->registry());
51 // Wallpaper manager and user image managers prefs will be accessed by the
52 // unit-test as well.
53 UserImageManager::RegisterPrefs(local_state_->registry());
54 WallpaperManager::RegisterPrefs(local_state_->registry());
55
56 StartupUtils::RegisterPrefs(local_state_->registry());
57 StartupUtils::MarkDeviceRegistered();
58
59 ResetUserManager();
60 }
61
62 virtual void TearDown() OVERRIDE {
63 // Unregister the in-memory local settings instance.
64 TestingBrowserProcess::GetGlobal()->SetLocalState(0);
65
66 // Shut down the DeviceSettingsService.
67 DeviceSettingsService::Get()->UnsetSessionManager();
68
69 test::AshTestBase::TearDown();
70 }
71
72 void ResetUserManager() {
73 // Reset the UserManager singleton.
74 user_manager_enabler_.reset();
75 // Initialize the UserManager singleton to a fresh UserManagerImpl instance.
76 user_manager_enabler_.reset(
77 new ScopedUserManagerEnabler(new UserManagerImpl));
78 }
79
80 void AppendGuestSwitch() {
81 command_line_.AppendSwitch(switches::kGuestSession);
82 WallpaperManager::Get()->set_command_line_for_testing(&command_line_);
83 }
84
85 void WaitAsyncWallpaperLoad() {
86 base::MessageLoop::current()->RunUntilIdle();
87 }
88
89 protected:
90 CommandLine command_line_;
91
92 scoped_ptr<TestingPrefServiceSimple> local_state_;
93
94 ScopedTestDeviceSettingsService test_device_settings_service_;
95 ScopedTestCrosSettings test_cros_settings_;
96
97 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
98
99 private:
100 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerTest);
101 };
102
103 // Test for crbug.com/260755. If this test fails, it is probably because the
104 // wallpaper of last logged in user is set as guest wallpaper.
105 TEST_F(WallpaperManagerTest, GuestUserUseGuestWallpaper) {
106 UserManager::Get()->UserLoggedIn(kTestUser1, kTestUser1Hash, false);
107
108 std::string relative_path =
109 base::FilePath(kTestUser1Hash).Append(FILE_PATH_LITERAL("DUMMY")).value();
110 // Saves wallpaper info to local state for user |kTestUser1|.
111 WallpaperInfo info = {
112 relative_path,
113 WALLPAPER_LAYOUT_CENTER_CROPPED,
114 User::CUSTOMIZED,
115 base::Time::Now().LocalMidnight()
116 };
117 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
118 ResetUserManager();
119
120 AppendGuestSwitch();
121 scoped_ptr<WallpaperManager::TestApi> test_api;
122 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get()));
123 // If last logged in user's wallpaper is used in function InitializeWallpaper,
124 // this test will crash. InitializeWallpaper should be a noop after
125 // AppendGuestSwitch being called.
126 WallpaperManager::Get()->InitializeWallpaper();
127 EXPECT_TRUE(test_api->current_wallpaper_path().empty());
128 UserManager::Get()->UserLoggedIn(UserManager::kGuestUserName,
129 UserManager::kGuestUserName, false);
130 WaitAsyncWallpaperLoad();
131 EXPECT_FALSE(ash::Shell::GetInstance()->desktop_background_controller()->
132 SetDefaultWallpaper(true));
133 }
134
135 class WallpaperManagerCacheTest : public test::AshTestBase { 42 class WallpaperManagerCacheTest : public test::AshTestBase {
136 public: 43 public:
137 WallpaperManagerCacheTest() 44 WallpaperManagerCacheTest()
138 : fake_user_manager_(new FakeUserManager()), 45 : fake_user_manager_(new FakeUserManager()),
139 scoped_user_manager_(fake_user_manager_) { 46 scoped_user_manager_(fake_user_manager_) {
140 } 47 }
141 48
142 protected: 49 protected:
143 virtual ~WallpaperManagerCacheTest() {} 50 virtual ~WallpaperManagerCacheTest() {}
144 51
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Logged in users' wallpaper cache should be kept. 100 // Logged in users' wallpaper cache should be kept.
194 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); 101 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper));
195 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper)); 102 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper));
196 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); 103 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper));
197 104
198 // Not logged in user's wallpaper cache should be cleared. 105 // Not logged in user's wallpaper cache should be cleared.
199 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper)); 106 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper));
200 } 107 }
201 108
202 } // namespace chromeos 109 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager_browsertest.cc ('k') | chrome/browser/ui/ash/user_wallpaper_delegate_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698