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 <string> | 5 #include <string> |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Initialize the UserManager singleton to a fresh FakeUserManager instance. | 71 // Initialize the UserManager singleton to a fresh FakeUserManager instance. |
72 user_manager_enabler_.reset( | 72 user_manager_enabler_.reset( |
73 new ScopedUserManagerEnabler(new FakeUserManager)); | 73 new ScopedUserManagerEnabler(new FakeUserManager)); |
74 } | 74 } |
75 | 75 |
76 FakeUserManager* GetFakeUserManager() { | 76 FakeUserManager* GetFakeUserManager() { |
77 return static_cast<FakeUserManager*>(UserManager::Get()); | 77 return static_cast<FakeUserManager*>(UserManager::Get()); |
78 } | 78 } |
79 | 79 |
80 void AddProfile(base::string16 name, bool log_in) { | 80 void AddProfile(base::string16 name, bool log_in) { |
81 std::string email_string = UTF16ToASCII(name) + "@example.com"; | 81 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
82 | 82 |
83 // Add a user to the fake user manager. | 83 // Add a user to the fake user manager. |
84 GetFakeUserManager()->AddUser(email_string); | 84 GetFakeUserManager()->AddUser(email_string); |
85 if (log_in) { | 85 if (log_in) { |
86 GetFakeUserManager()->UserLoggedIn( | 86 GetFakeUserManager()->UserLoggedIn( |
87 email_string, | 87 email_string, |
88 email_string + kUserIdHashSuffix, | 88 email_string + kUserIdHashSuffix, |
89 false); | 89 false); |
90 } | 90 } |
91 | 91 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 base::string16 managed_name(ASCIIToUTF16("p2@example.com")); | 174 base::string16 managed_name(ASCIIToUTF16("p2@example.com")); |
175 | 175 |
176 AddProfile(name1, true); | 176 AddProfile(name1, true); |
177 | 177 |
178 // Add a managed user profile. | 178 // Add a managed user profile. |
179 ProfileInfoCache* cache = manager()->profile_info_cache(); | 179 ProfileInfoCache* cache = manager()->profile_info_cache(); |
180 manager()->profile_info_cache()->AddProfileToCache( | 180 manager()->profile_info_cache()->AddProfileToCache( |
181 cache->GetUserDataDir().AppendASCII("p2"), managed_name, | 181 cache->GetUserDataDir().AppendASCII("p2"), managed_name, |
182 base::string16(), 0, "TEST_ID"); | 182 base::string16(), 0, "TEST_ID"); |
183 | 183 |
184 GetFakeUserManager()->AddUser(UTF16ToASCII(managed_name)); | 184 GetFakeUserManager()->AddUser(base::UTF16ToASCII(managed_name)); |
185 | 185 |
186 AvatarMenu* menu = GetAvatarMenu(); | 186 AvatarMenu* menu = GetAvatarMenu(); |
187 ASSERT_EQ(1U, menu->GetNumberOfItems()); | 187 ASSERT_EQ(1U, menu->GetNumberOfItems()); |
188 | 188 |
189 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 189 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
190 EXPECT_EQ(0U, item1.menu_index); | 190 EXPECT_EQ(0U, item1.menu_index); |
191 EXPECT_EQ(name1, item1.name); | 191 EXPECT_EQ(name1, item1.name); |
192 } | 192 } |
193 | 193 |
194 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { | 194 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { |
(...skipping 23 matching lines...) Expand all Loading... |
218 } | 218 } |
219 | 219 |
220 TEST_F(ProfileListChromeOSTest, ActiveItem) { | 220 TEST_F(ProfileListChromeOSTest, ActiveItem) { |
221 base::string16 name1(ASCIIToUTF16("p1.com")); | 221 base::string16 name1(ASCIIToUTF16("p1.com")); |
222 base::string16 name2(ASCIIToUTF16("p2.com")); | 222 base::string16 name2(ASCIIToUTF16("p2.com")); |
223 | 223 |
224 AddProfile(name1, true); | 224 AddProfile(name1, true); |
225 AddProfile(name2, true); | 225 AddProfile(name2, true); |
226 | 226 |
227 // Initialize ProfileHelper, it will be accessed from GetActiveProfileIndex. | 227 // Initialize ProfileHelper, it will be accessed from GetActiveProfileIndex. |
228 std::string email_string = UTF16ToASCII(name1) + "@example.com"; | 228 std::string email_string = base::UTF16ToASCII(name1) + "@example.com"; |
229 std::string hash = email_string + kUserIdHashSuffix; | 229 std::string hash = email_string + kUserIdHashSuffix; |
230 ActiveUserChanged( | 230 ActiveUserChanged( |
231 g_browser_process->platform_part()->profile_helper(), hash); | 231 g_browser_process->platform_part()->profile_helper(), hash); |
232 | 232 |
233 AvatarMenu* menu = GetAvatarMenu(); | 233 AvatarMenu* menu = GetAvatarMenu(); |
234 | 234 |
235 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 235 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
236 // TODO(jeremy): Expand test to verify active profile index other than 0 | 236 // TODO(jeremy): Expand test to verify active profile index other than 0 |
237 // crbug.com/100871 | 237 // crbug.com/100871 |
238 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); | 238 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); |
(...skipping 15 matching lines...) Expand all Loading... |
254 EXPECT_EQ(0U, item1.menu_index); | 254 EXPECT_EQ(0U, item1.menu_index); |
255 EXPECT_EQ(name1, item1.name); | 255 EXPECT_EQ(name1, item1.name); |
256 | 256 |
257 const AvatarMenu::Item& item2 = menu->GetItemAt(1); | 257 const AvatarMenu::Item& item2 = menu->GetItemAt(1); |
258 EXPECT_EQ(1U, item2.menu_index); | 258 EXPECT_EQ(1U, item2.menu_index); |
259 EXPECT_EQ(name2, item2.name); | 259 EXPECT_EQ(name2, item2.name); |
260 | 260 |
261 // Change name of the first profile, to trigger resorting of the profiles: | 261 // Change name of the first profile, to trigger resorting of the profiles: |
262 // now the first menu item should be named "beta", and the second be "gamma". | 262 // now the first menu item should be named "beta", and the second be "gamma". |
263 GetFakeUserManager()->SaveUserDisplayName( | 263 GetFakeUserManager()->SaveUserDisplayName( |
264 UTF16ToASCII(name1) + "@example.com", newname1); | 264 base::UTF16ToASCII(name1) + "@example.com", newname1); |
265 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); | 265 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); |
266 | 266 |
267 const AvatarMenu::Item& item1next = menu->GetItemAt(0); | 267 const AvatarMenu::Item& item1next = menu->GetItemAt(0); |
268 EXPECT_GT(change_count(), 1); | 268 EXPECT_GT(change_count(), 1); |
269 EXPECT_EQ(0U, item1next.menu_index); | 269 EXPECT_EQ(0U, item1next.menu_index); |
270 EXPECT_EQ(name2, item1next.name); | 270 EXPECT_EQ(name2, item1next.name); |
271 | 271 |
272 const AvatarMenu::Item& item2next = menu->GetItemAt(1); | 272 const AvatarMenu::Item& item2next = menu->GetItemAt(1); |
273 EXPECT_EQ(1U, item2next.menu_index); | 273 EXPECT_EQ(1U, item2next.menu_index); |
274 EXPECT_EQ(newname1, item2next.name); | 274 EXPECT_EQ(newname1, item2next.name); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 316 |
317 // Should only show avatar menu with multiple users. | 317 // Should only show avatar menu with multiple users. |
318 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 318 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
319 | 319 |
320 AddProfile(name2, false); | 320 AddProfile(name2, false); |
321 | 321 |
322 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 322 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
323 } | 323 } |
324 | 324 |
325 } // namespace chromeos | 325 } // namespace chromeos |
OLD | NEW |