OLD | NEW |
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/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/testing_pref_service.h" | 16 #include "base/prefs/testing_pref_service.h" |
17 #include "chrome/browser/chromeos/login/fake_user_manager.h" | 17 #include "chrome/browser/chromeos/login/fake_user_manager.h" |
18 #include "chrome/browser/chromeos/login/startup_utils.h" | 18 #include "chrome/browser/chromeos/login/startup_utils.h" |
19 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 19 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
20 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | 20 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 21 #include "chrome/browser/chromeos/settings/cros_settings.h" |
22 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 22 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 23 #include "chrome/browser/prefs/browser_prefs.h" |
23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/test/base/testing_browser_process.h" | 25 #include "chrome/test/base/testing_browser_process.h" |
25 #include "chromeos/chromeos_switches.h" | 26 #include "chromeos/chromeos_switches.h" |
26 #include "chromeos/settings/cros_settings_names.h" | 27 #include "chromeos/settings/cros_settings_names.h" |
27 #include "chromeos/settings/cros_settings_provider.h" | 28 #include "chromeos/settings/cros_settings_provider.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
30 | 31 |
31 using namespace ash; | 32 using namespace ash; |
32 | 33 |
33 const char kTestUser1[] = "test-user@example.com"; | 34 const char kTestUser1[] = "test-user@example.com"; |
34 const char kTestUser1Hash[] = "test-user@example.com-hash"; | 35 const char kTestUser1Hash[] = "test-user@example.com-hash"; |
35 | 36 |
36 namespace chromeos { | 37 namespace chromeos { |
37 | 38 |
38 class WallpaperManagerTest : public test::AshTestBase { | 39 class WallpaperManagerTest : public test::AshTestBase { |
39 public: | 40 public: |
40 WallpaperManagerTest() : command_line_(CommandLine::NO_PROGRAM) {} | 41 WallpaperManagerTest() : command_line_(CommandLine::NO_PROGRAM) {} |
41 | 42 |
42 virtual ~WallpaperManagerTest() {} | 43 virtual ~WallpaperManagerTest() {} |
43 | 44 |
44 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
45 test::AshTestBase::SetUp(); | 46 test::AshTestBase::SetUp(); |
46 | 47 |
47 // Register an in-memory local settings instance. | 48 // Register an in-memory local settings instance. |
48 local_state_.reset(new TestingPrefServiceSimple); | 49 local_state_.reset(new TestingPrefServiceSimple); |
49 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get()); | 50 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get()); |
50 UserManager::RegisterPrefs(local_state_->registry()); | 51 chrome::RegisterLocalState(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 | 52 |
56 StartupUtils::RegisterPrefs(local_state_->registry()); | |
57 StartupUtils::MarkDeviceRegistered(); | 53 StartupUtils::MarkDeviceRegistered(); |
58 | 54 |
59 ResetUserManager(); | 55 ResetUserManager(); |
60 } | 56 } |
61 | 57 |
62 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
63 // Unregister the in-memory local settings instance. | 59 // Unregister the in-memory local settings instance. |
64 TestingBrowserProcess::GetGlobal()->SetLocalState(0); | 60 TestingBrowserProcess::GetGlobal()->SetLocalState(0); |
65 | 61 |
66 // Shut down the DeviceSettingsService. | 62 // Shut down the DeviceSettingsService. |
(...skipping 12 matching lines...) Expand all Loading... |
79 | 75 |
80 void AppendGuestSwitch() { | 76 void AppendGuestSwitch() { |
81 command_line_.AppendSwitch(switches::kGuestSession); | 77 command_line_.AppendSwitch(switches::kGuestSession); |
82 WallpaperManager::Get()->set_command_line_for_testing(&command_line_); | 78 WallpaperManager::Get()->set_command_line_for_testing(&command_line_); |
83 } | 79 } |
84 | 80 |
85 void WaitAsyncWallpaperLoad() { | 81 void WaitAsyncWallpaperLoad() { |
86 base::MessageLoop::current()->RunUntilIdle(); | 82 base::MessageLoop::current()->RunUntilIdle(); |
87 } | 83 } |
88 | 84 |
| 85 const base::FilePath& GetWallpaperManagerGuestSmallFile() const { |
| 86 return WallpaperManager::Get()->guest_default_small_wallpaper_file_; |
| 87 } |
| 88 |
| 89 const base::FilePath& GetWallpaperManagerGuestLargeFile() const { |
| 90 return WallpaperManager::Get()->guest_default_large_wallpaper_file_; |
| 91 } |
| 92 |
89 protected: | 93 protected: |
90 CommandLine command_line_; | 94 CommandLine command_line_; |
91 | 95 |
92 scoped_ptr<TestingPrefServiceSimple> local_state_; | 96 scoped_ptr<TestingPrefServiceSimple> local_state_; |
93 | 97 |
94 ScopedTestDeviceSettingsService test_device_settings_service_; | 98 ScopedTestDeviceSettingsService test_device_settings_service_; |
95 ScopedTestCrosSettings test_cros_settings_; | 99 ScopedTestCrosSettings test_cros_settings_; |
96 | 100 |
97 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 101 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
98 | 102 |
(...skipping 22 matching lines...) Expand all Loading... |
121 scoped_ptr<WallpaperManager::TestApi> test_api; | 125 scoped_ptr<WallpaperManager::TestApi> test_api; |
122 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); | 126 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); |
123 // If last logged in user's wallpaper is used in function InitializeWallpaper, | 127 // If last logged in user's wallpaper is used in function InitializeWallpaper, |
124 // this test will crash. InitializeWallpaper should be a noop after | 128 // this test will crash. InitializeWallpaper should be a noop after |
125 // AppendGuestSwitch being called. | 129 // AppendGuestSwitch being called. |
126 WallpaperManager::Get()->InitializeWallpaper(); | 130 WallpaperManager::Get()->InitializeWallpaper(); |
127 EXPECT_TRUE(test_api->current_wallpaper_path().empty()); | 131 EXPECT_TRUE(test_api->current_wallpaper_path().empty()); |
128 UserManager::Get()->UserLoggedIn(UserManager::kGuestUserName, | 132 UserManager::Get()->UserLoggedIn(UserManager::kGuestUserName, |
129 UserManager::kGuestUserName, false); | 133 UserManager::kGuestUserName, false); |
130 WaitAsyncWallpaperLoad(); | 134 WaitAsyncWallpaperLoad(); |
131 EXPECT_FALSE(ash::Shell::GetInstance()->desktop_background_controller()-> | 135 const base::FilePath& guest_wallpaper_small = |
132 SetDefaultWallpaper(true)); | 136 GetWallpaperManagerGuestSmallFile(); |
| 137 const base::FilePath& guest_wallpaper_large = |
| 138 GetWallpaperManagerGuestLargeFile(); |
| 139 EXPECT_FALSE( |
| 140 ash::Shell::GetInstance() |
| 141 ->desktop_background_controller() |
| 142 ->SetDefaultWallpaper(guest_wallpaper_small, guest_wallpaper_large)); |
133 } | 143 } |
134 | 144 |
135 class WallpaperManagerCacheTest : public test::AshTestBase { | 145 class WallpaperManagerCacheTest : public test::AshTestBase { |
136 public: | 146 public: |
137 WallpaperManagerCacheTest() | 147 WallpaperManagerCacheTest() |
138 : fake_user_manager_(new FakeUserManager()), | 148 : fake_user_manager_(new FakeUserManager()), |
139 scoped_user_manager_(fake_user_manager_) { | 149 scoped_user_manager_(fake_user_manager_) { |
140 } | 150 } |
141 | 151 |
142 protected: | 152 protected: |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // Logged in users' wallpaper cache should be kept. | 203 // Logged in users' wallpaper cache should be kept. |
194 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); | 204 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); |
195 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper)); | 205 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper)); |
196 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); | 206 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); |
197 | 207 |
198 // Not logged in user's wallpaper cache should be cleared. | 208 // Not logged in user's wallpaper cache should be cleared. |
199 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper)); | 209 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper)); |
200 } | 210 } |
201 | 211 |
202 } // namespace chromeos | 212 } // namespace chromeos |
OLD | NEW |