OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 // UserManager::Observer overrides: | 67 // UserManager::Observer overrides: |
68 virtual void LocalStateChanged(UserManager* user_manager) OVERRIDE { | 68 virtual void LocalStateChanged(UserManager* user_manager) OVERRIDE { |
69 MessageLoopForUI::current()->Quit(); | 69 MessageLoopForUI::current()->Quit(); |
70 } | 70 } |
71 | 71 |
72 // Adds given user to Local State, if not there. | 72 // Adds given user to Local State, if not there. |
73 void AddUser(const std::string& username) { | 73 void AddUser(const std::string& username) { |
74 ListPrefUpdate users_pref(local_state_, "LoggedInUsers"); | 74 ListPrefUpdate users_pref(local_state_, "LoggedInUsers"); |
75 users_pref->AppendIfNotPresent(base::Value::CreateStringValue(username)); | 75 users_pref->AppendIfNotPresent(new base::StringValue(username)); |
76 } | 76 } |
77 | 77 |
78 // Logs in |username|. | 78 // Logs in |username|. |
79 void LogIn(const std::string& username) { | 79 void LogIn(const std::string& username) { |
80 UserManager::Get()->UserLoggedIn(username, false); | 80 UserManager::Get()->UserLoggedIn(username, false); |
81 } | 81 } |
82 | 82 |
83 // Subscribes for image change notification. | 83 // Subscribes for image change notification. |
84 void ExpectImageChange() { | 84 void ExpectImageChange() { |
85 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 85 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
86 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
87 } | 87 } |
88 | 88 |
89 // Stores old (pre-migration) user image info. | 89 // Stores old (pre-migration) user image info. |
90 void SetOldUserImageInfo(const std::string& username, | 90 void SetOldUserImageInfo(const std::string& username, |
91 int image_index, | 91 int image_index, |
92 const FilePath& image_path) { | 92 const FilePath& image_path) { |
93 AddUser(username); | 93 AddUser(username); |
94 DictionaryPrefUpdate images_pref(local_state_, "UserImages"); | 94 DictionaryPrefUpdate images_pref(local_state_, "UserImages"); |
95 base::DictionaryValue* image_properties = new base::DictionaryValue(); | 95 base::DictionaryValue* image_properties = new base::DictionaryValue(); |
96 image_properties->Set( | 96 image_properties->Set( |
97 "index", base::Value::CreateIntegerValue(image_index)); | 97 "index", base::Value::CreateIntegerValue(image_index)); |
98 image_properties->Set( | 98 image_properties->Set( |
99 "path" , base::Value::CreateStringValue(image_path.value())); | 99 "path" , new base::StringValue(image_path.value())); |
100 images_pref->SetWithoutPathExpansion(username, image_properties); | 100 images_pref->SetWithoutPathExpansion(username, image_properties); |
101 } | 101 } |
102 | 102 |
103 // Verifies user image info in |images_pref| dictionary. | 103 // Verifies user image info in |images_pref| dictionary. |
104 void ExpectUserImageInfo(const base::DictionaryValue* images_pref, | 104 void ExpectUserImageInfo(const base::DictionaryValue* images_pref, |
105 const std::string& username, | 105 const std::string& username, |
106 int image_index, | 106 int image_index, |
107 const FilePath& image_path) { | 107 const FilePath& image_path) { |
108 ASSERT_TRUE(images_pref); | 108 ASSERT_TRUE(images_pref); |
109 const base::DictionaryValue* image_properties = NULL; | 109 const base::DictionaryValue* image_properties = NULL; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 const User* user = UserManager::Get()->FindUser(kTestUser1); | 253 const User* user = UserManager::Get()->FindUser(kTestUser1); |
254 ASSERT_TRUE(user); | 254 ASSERT_TRUE(user); |
255 EXPECT_TRUE(user->image_is_safe_format()); | 255 EXPECT_TRUE(user->image_is_safe_format()); |
256 // Check image dimensions. Images can't be compared since JPEG is lossy. | 256 // Check image dimensions. Images can't be compared since JPEG is lossy. |
257 const gfx::ImageSkia& saved_image = GetDefaultImage(kFirstDefaultImageIndex); | 257 const gfx::ImageSkia& saved_image = GetDefaultImage(kFirstDefaultImageIndex); |
258 EXPECT_EQ(saved_image.width(), user->image().width()); | 258 EXPECT_EQ(saved_image.width(), user->image().width()); |
259 EXPECT_EQ(saved_image.height(), user->image().height()); | 259 EXPECT_EQ(saved_image.height(), user->image().height()); |
260 } | 260 } |
261 | 261 |
262 } // namespace chromeos | 262 } // namespace chromeos |
OLD | NEW |