OLD | NEW |
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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 9 #include "ash/desktop_background/desktop_background_controller_observer.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "chrome/browser/chromeos/login/login_manager_test.h" | 20 #include "chrome/browser/chromeos/login/login_manager_test.h" |
21 #include "chrome/browser/chromeos/login/startup_utils.h" | 21 #include "chrome/browser/chromeos/login/startup_utils.h" |
22 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 22 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
23 #include "chrome/browser/chromeos/login/users/user.h" | |
24 #include "chrome/browser/chromeos/login/users/user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/user_manager.h" |
25 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 24 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
26 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" | 25 #include "chrome/browser/chromeos/policy/cloud_external_data_manager_base_test_u
til.h" |
27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 26 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
28 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
29 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
30 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
32 #include "chromeos/chromeos_paths.h" | 31 #include "chromeos/chromeos_paths.h" |
33 #include "chromeos/chromeos_switches.h" | 32 #include "chromeos/chromeos_switches.h" |
34 #include "chromeos/dbus/cryptohome_client.h" | 33 #include "chromeos/dbus/cryptohome_client.h" |
35 #include "chromeos/dbus/dbus_thread_manager.h" | 34 #include "chromeos/dbus/dbus_thread_manager.h" |
36 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 35 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
37 #include "chromeos/dbus/fake_session_manager_client.h" | 36 #include "chromeos/dbus/fake_session_manager_client.h" |
38 #include "chromeos/dbus/session_manager_client.h" | 37 #include "chromeos/dbus/session_manager_client.h" |
39 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 38 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
40 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 39 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
41 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 40 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
42 #include "components/policy/core/common/cloud/policy_builder.h" | 41 #include "components/policy/core/common/cloud/policy_builder.h" |
| 42 #include "components/user_manager/user.h" |
43 #include "content/public/test/browser_test_utils.h" | 43 #include "content/public/test/browser_test_utils.h" |
44 #include "crypto/rsa_private_key.h" | 44 #include "crypto/rsa_private_key.h" |
45 #include "net/test/embedded_test_server/embedded_test_server.h" | 45 #include "net/test/embedded_test_server/embedded_test_server.h" |
46 #include "policy/proto/cloud_policy.pb.h" | 46 #include "policy/proto/cloud_policy.pb.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "third_party/skia/include/core/SkBitmap.h" | 48 #include "third_party/skia/include/core/SkBitmap.h" |
49 #include "third_party/skia/include/core/SkColor.h" | 49 #include "third_party/skia/include/core/SkColor.h" |
50 #include "ui/gfx/image/image_skia.h" | 50 #include "ui/gfx/image/image_skia.h" |
51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
52 | 52 |
53 namespace chromeos { | 53 namespace chromeos { |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 const char kTestUsers[2][19] = { "test-0@example.com", "test-1@example.com" }; | 57 const char kTestUsers[2][19] = { "test-0@example.com", "test-1@example.com" }; |
58 | 58 |
59 const char kRedImageFileName[] = "chromeos/wallpapers/red.jpg"; | 59 const char kRedImageFileName[] = "chromeos/wallpapers/red.jpg"; |
60 const char kGreenImageFileName[] = "chromeos/wallpapers/green.jpg"; | 60 const char kGreenImageFileName[] = "chromeos/wallpapers/green.jpg"; |
61 const char kBlueImageFileName[] = "chromeos/wallpapers/blue.jpg"; | 61 const char kBlueImageFileName[] = "chromeos/wallpapers/blue.jpg"; |
62 | 62 |
63 const SkColor kRedImageColor = SkColorSetARGB(255, 199, 6, 7); | 63 const SkColor kRedImageColor = SkColorSetARGB(255, 199, 6, 7); |
64 const SkColor kGreenImageColor = SkColorSetARGB(255, 38, 196, 15); | 64 const SkColor kGreenImageColor = SkColorSetARGB(255, 38, 196, 15); |
65 | 65 |
66 policy::CloudPolicyStore* GetStoreForUser(const User* user) { | 66 policy::CloudPolicyStore* GetStoreForUser(const user_manager::User* user) { |
67 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); | 67 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); |
68 if (!profile) { | 68 if (!profile) { |
69 ADD_FAILURE(); | 69 ADD_FAILURE(); |
70 return NULL; | 70 return NULL; |
71 } | 71 } |
72 policy::UserCloudPolicyManagerChromeOS* policy_manager = | 72 policy::UserCloudPolicyManagerChromeOS* policy_manager = |
73 policy::UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | 73 policy::UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); |
74 if (!policy_manager) { | 74 if (!policy_manager) { |
75 ADD_FAILURE(); | 75 ADD_FAILURE(); |
76 return NULL; | 76 return NULL; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 policy::UserPolicyBuilder* builder = | 238 policy::UserPolicyBuilder* builder = |
239 user_policy_builders_[user_number].get(); | 239 user_policy_builders_[user_number].get(); |
240 if (filename != "") { | 240 if (filename != "") { |
241 builder->payload(). | 241 builder->payload(). |
242 mutable_wallpaperimage()->set_value(ConstructPolicy(filename)); | 242 mutable_wallpaperimage()->set_value(ConstructPolicy(filename)); |
243 } else { | 243 } else { |
244 builder->payload().Clear(); | 244 builder->payload().Clear(); |
245 } | 245 } |
246 builder->Build(); | 246 builder->Build(); |
247 fake_session_manager_client_->set_user_policy(user_id, builder->GetBlob()); | 247 fake_session_manager_client_->set_user_policy(user_id, builder->GetBlob()); |
248 const User* user = UserManager::Get()->FindUser(user_id); | 248 const user_manager::User* user = UserManager::Get()->FindUser(user_id); |
249 ASSERT_TRUE(user); | 249 ASSERT_TRUE(user); |
250 policy::CloudPolicyStore* store = GetStoreForUser(user); | 250 policy::CloudPolicyStore* store = GetStoreForUser(user); |
251 ASSERT_TRUE(store); | 251 ASSERT_TRUE(store); |
252 store->Load(); | 252 store->Load(); |
253 ASSERT_EQ(policy::CloudPolicyStore::STATUS_OK, store->status()); | 253 ASSERT_EQ(policy::CloudPolicyStore::STATUS_OK, store->status()); |
254 ASSERT_EQ(policy::CloudPolicyValidatorBase::VALIDATION_OK, | 254 ASSERT_EQ(policy::CloudPolicyValidatorBase::VALIDATION_OK, |
255 store->validation_status()); | 255 store->validation_status()); |
256 } | 256 } |
257 | 257 |
258 // Obtain WallpaperInfo for |user_number| from WallpaperManager. | 258 // Obtain WallpaperInfo for |user_number| from WallpaperManager. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 const SkColor original_background_color = GetAverageBackgroundColor(); | 293 const SkColor original_background_color = GetAverageBackgroundColor(); |
294 | 294 |
295 // Second user: Set wallpaper policy to blue image. This should not result in | 295 // Second user: Set wallpaper policy to blue image. This should not result in |
296 // a wallpaper change, which is checked at the very end of this test. | 296 // a wallpaper change, which is checked at the very end of this test. |
297 InjectPolicy(1, kBlueImageFileName); | 297 InjectPolicy(1, kBlueImageFileName); |
298 | 298 |
299 // First user: Set wallpaper policy to red image and verify average color. | 299 // First user: Set wallpaper policy to red image and verify average color. |
300 InjectPolicy(0, kRedImageFileName); | 300 InjectPolicy(0, kRedImageFileName); |
301 RunUntilWallpaperChangeCount(2); | 301 RunUntilWallpaperChangeCount(2); |
302 GetUserWallpaperInfo(0, &info); | 302 GetUserWallpaperInfo(0, &info); |
303 ASSERT_EQ(User::POLICY, info.type); | 303 ASSERT_EQ(user_manager::User::POLICY, info.type); |
304 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 304 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
305 | 305 |
306 // First user: Set wallpaper policy to green image and verify average color. | 306 // First user: Set wallpaper policy to green image and verify average color. |
307 InjectPolicy(0, kGreenImageFileName); | 307 InjectPolicy(0, kGreenImageFileName); |
308 RunUntilWallpaperChangeCount(3); | 308 RunUntilWallpaperChangeCount(3); |
309 GetUserWallpaperInfo(0, &info); | 309 GetUserWallpaperInfo(0, &info); |
310 ASSERT_EQ(User::POLICY, info.type); | 310 ASSERT_EQ(user_manager::User::POLICY, info.type); |
311 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); | 311 ASSERT_EQ(kGreenImageColor, GetAverageBackgroundColor()); |
312 | 312 |
313 // First user: Clear wallpaper policy and verify that the default wallpaper is | 313 // First user: Clear wallpaper policy and verify that the default wallpaper is |
314 // set again. | 314 // set again. |
315 InjectPolicy(0, ""); | 315 InjectPolicy(0, ""); |
316 RunUntilWallpaperChangeCount(4); | 316 RunUntilWallpaperChangeCount(4); |
317 GetUserWallpaperInfo(0, &info); | 317 GetUserWallpaperInfo(0, &info); |
318 ASSERT_EQ(User::DEFAULT, info.type); | 318 ASSERT_EQ(user_manager::User::DEFAULT, info.type); |
319 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); | 319 ASSERT_EQ(original_background_color, GetAverageBackgroundColor()); |
320 | 320 |
321 // Check wallpaper change count to ensure that setting the second user's | 321 // Check wallpaper change count to ensure that setting the second user's |
322 // wallpaper didn't have any effect. | 322 // wallpaper didn't have any effect. |
323 ASSERT_EQ(4, wallpaper_change_count_); | 323 ASSERT_EQ(4, wallpaper_change_count_); |
324 } | 324 } |
325 | 325 |
326 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, | 326 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, |
327 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) { | 327 DISABLED_PRE_PRE_PRE_WallpaperOnLoginScreen) { |
328 RegisterUser(kTestUsers[0]); | 328 RegisterUser(kTestUsers[0]); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { | 399 IN_PROC_BROWSER_TEST_F(WallpaperManagerPolicyTest, PersistOverLogout) { |
400 LoginUser(kTestUsers[0]); | 400 LoginUser(kTestUsers[0]); |
401 | 401 |
402 // Wait until wallpaper has been loaded. | 402 // Wait until wallpaper has been loaded. |
403 RunUntilWallpaperChangeCount(1); | 403 RunUntilWallpaperChangeCount(1); |
404 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); | 404 ASSERT_EQ(kRedImageColor, GetAverageBackgroundColor()); |
405 } | 405 } |
406 | 406 |
407 } // namespace chromeos | 407 } // namespace chromeos |
OLD | NEW |