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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 scoped_ptr<MockObserver> mock_observer_; | 126 scoped_ptr<MockObserver> mock_observer_; |
127 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 127 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
128 scoped_ptr<AvatarMenu> avatar_menu_; | 128 scoped_ptr<AvatarMenu> avatar_menu_; |
129 ChromeShellDelegate chrome_shell_delegate_; | 129 ChromeShellDelegate chrome_shell_delegate_; |
130 scoped_ptr<base::FieldTrialList> field_trial_list_; | 130 scoped_ptr<base::FieldTrialList> field_trial_list_; |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(ProfileListChromeOSTest); | 132 DISALLOW_COPY_AND_ASSIGN(ProfileListChromeOSTest); |
133 }; | 133 }; |
134 | 134 |
135 TEST_F(ProfileListChromeOSTest, InitialCreation) { | 135 TEST_F(ProfileListChromeOSTest, InitialCreation) { |
136 string16 name1(ASCIIToUTF16("p1")); | 136 base::string16 name1(ASCIIToUTF16("p1")); |
137 | 137 |
138 AddProfile(name1, true); | 138 AddProfile(name1, true); |
139 | 139 |
140 AvatarMenu* menu = GetAvatarMenu(); | 140 AvatarMenu* menu = GetAvatarMenu(); |
141 | 141 |
142 ASSERT_EQ(1U, menu->GetNumberOfItems()); | 142 ASSERT_EQ(1U, menu->GetNumberOfItems()); |
143 | 143 |
144 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 144 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
145 EXPECT_EQ(0U, item1.menu_index); | 145 EXPECT_EQ(0U, item1.menu_index); |
146 EXPECT_EQ(name1, item1.name); | 146 EXPECT_EQ(name1, item1.name); |
147 } | 147 } |
148 | 148 |
149 TEST_F(ProfileListChromeOSTest, ShowLoggedInUsers) { | 149 TEST_F(ProfileListChromeOSTest, ShowLoggedInUsers) { |
150 string16 name1(ASCIIToUTF16("p1")); | 150 base::string16 name1(ASCIIToUTF16("p1")); |
151 string16 name2(ASCIIToUTF16("p2")); | 151 base::string16 name2(ASCIIToUTF16("p2")); |
152 string16 name3(ASCIIToUTF16("p3")); | 152 base::string16 name3(ASCIIToUTF16("p3")); |
153 string16 name4(ASCIIToUTF16("p4")); | 153 base::string16 name4(ASCIIToUTF16("p4")); |
154 | 154 |
155 AddProfile(name1, true); | 155 AddProfile(name1, true); |
156 AddProfile(name2, false); | 156 AddProfile(name2, false); |
157 AddProfile(name3, true); | 157 AddProfile(name3, true); |
158 AddProfile(name4, false); | 158 AddProfile(name4, false); |
159 | 159 |
160 AvatarMenu* menu = GetAvatarMenu(); | 160 AvatarMenu* menu = GetAvatarMenu(); |
161 | 161 |
162 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 162 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
163 | 163 |
164 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 164 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
165 EXPECT_EQ(0U, item1.menu_index); | 165 EXPECT_EQ(0U, item1.menu_index); |
166 EXPECT_EQ(name1, item1.name); | 166 EXPECT_EQ(name1, item1.name); |
167 | 167 |
168 const AvatarMenu::Item& item3 = menu->GetItemAt(1); | 168 const AvatarMenu::Item& item3 = menu->GetItemAt(1); |
169 EXPECT_EQ(1U, item3.menu_index); | 169 EXPECT_EQ(1U, item3.menu_index); |
170 EXPECT_EQ(name3, item3.name); | 170 EXPECT_EQ(name3, item3.name); |
171 } | 171 } |
172 | 172 |
173 TEST_F(ProfileListChromeOSTest, DontShowManagedUsers) { | 173 TEST_F(ProfileListChromeOSTest, DontShowManagedUsers) { |
174 string16 name1(ASCIIToUTF16("p1")); | 174 base::string16 name1(ASCIIToUTF16("p1")); |
175 string16 managed_name(ASCIIToUTF16("p2@example.com")); | 175 base::string16 managed_name(ASCIIToUTF16("p2@example.com")); |
176 | 176 |
177 AddProfile(name1, true); | 177 AddProfile(name1, true); |
178 | 178 |
179 // Add a managed user profile. | 179 // Add a managed user profile. |
180 ProfileInfoCache* cache = manager()->profile_info_cache(); | 180 ProfileInfoCache* cache = manager()->profile_info_cache(); |
181 manager()->profile_info_cache()->AddProfileToCache( | 181 manager()->profile_info_cache()->AddProfileToCache( |
182 cache->GetUserDataDir().AppendASCII("p2"), managed_name, | 182 cache->GetUserDataDir().AppendASCII("p2"), managed_name, |
183 string16(), 0, "TEST_ID"); | 183 base::string16(), 0, "TEST_ID"); |
184 | 184 |
185 GetFakeUserManager()->AddUser(UTF16ToASCII(managed_name)); | 185 GetFakeUserManager()->AddUser(UTF16ToASCII(managed_name)); |
186 | 186 |
187 AvatarMenu* menu = GetAvatarMenu(); | 187 AvatarMenu* menu = GetAvatarMenu(); |
188 ASSERT_EQ(1U, menu->GetNumberOfItems()); | 188 ASSERT_EQ(1U, menu->GetNumberOfItems()); |
189 | 189 |
190 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 190 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
191 EXPECT_EQ(0U, item1.menu_index); | 191 EXPECT_EQ(0U, item1.menu_index); |
192 EXPECT_EQ(name1, item1.name); | 192 EXPECT_EQ(name1, item1.name); |
193 } | 193 } |
194 | 194 |
195 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { | 195 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { |
196 string16 name1(ASCIIToUTF16("p1.com")); | 196 base::string16 name1(ASCIIToUTF16("p1.com")); |
197 string16 name2(ASCIIToUTF16("p2.com")); | 197 base::string16 name2(ASCIIToUTF16("p2.com")); |
198 | 198 |
199 AddProfile(name1, true); | 199 AddProfile(name1, true); |
200 AddProfile(name2, false); | 200 AddProfile(name2, false); |
201 | 201 |
202 AvatarMenu* menu = GetAvatarMenu(); | 202 AvatarMenu* menu = GetAvatarMenu(); |
203 | 203 |
204 ASSERT_EQ(1U, menu->GetNumberOfItems()); | 204 ASSERT_EQ(1U, menu->GetNumberOfItems()); |
205 EXPECT_TRUE(menu->ShouldShowAddNewProfileLink()); | 205 EXPECT_TRUE(menu->ShouldShowAddNewProfileLink()); |
206 } | 206 } |
207 | 207 |
208 TEST_F(ProfileListChromeOSTest, DontShowAddProfileLink) { | 208 TEST_F(ProfileListChromeOSTest, DontShowAddProfileLink) { |
209 string16 name1(ASCIIToUTF16("p1.com")); | 209 base::string16 name1(ASCIIToUTF16("p1.com")); |
210 string16 name2(ASCIIToUTF16("p2.com")); | 210 base::string16 name2(ASCIIToUTF16("p2.com")); |
211 | 211 |
212 AddProfile(name1, true); | 212 AddProfile(name1, true); |
213 AddProfile(name2, true); | 213 AddProfile(name2, true); |
214 | 214 |
215 AvatarMenu* menu = GetAvatarMenu(); | 215 AvatarMenu* menu = GetAvatarMenu(); |
216 | 216 |
217 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 217 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
218 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); | 218 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); |
219 } | 219 } |
220 | 220 |
221 TEST_F(ProfileListChromeOSTest, ActiveItem) { | 221 TEST_F(ProfileListChromeOSTest, ActiveItem) { |
222 string16 name1(ASCIIToUTF16("p1.com")); | 222 base::string16 name1(ASCIIToUTF16("p1.com")); |
223 string16 name2(ASCIIToUTF16("p2.com")); | 223 base::string16 name2(ASCIIToUTF16("p2.com")); |
224 | 224 |
225 AddProfile(name1, true); | 225 AddProfile(name1, true); |
226 AddProfile(name2, true); | 226 AddProfile(name2, true); |
227 | 227 |
228 AvatarMenu* menu = GetAvatarMenu(); | 228 AvatarMenu* menu = GetAvatarMenu(); |
229 | 229 |
230 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 230 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
231 // TODO(jeremy): Expand test to verify active profile index other than 0 | 231 // TODO(jeremy): Expand test to verify active profile index other than 0 |
232 // crbug.com/100871 | 232 // crbug.com/100871 |
233 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); | 233 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); |
234 } | 234 } |
235 | 235 |
236 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { | 236 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { |
237 string16 name1(ASCIIToUTF16("Alpha")); | 237 base::string16 name1(ASCIIToUTF16("Alpha")); |
238 string16 name2(ASCIIToUTF16("Beta")); | 238 base::string16 name2(ASCIIToUTF16("Beta")); |
239 string16 newname1(ASCIIToUTF16("Gamma")); | 239 base::string16 newname1(ASCIIToUTF16("Gamma")); |
240 | 240 |
241 AddProfile(name1, true); | 241 AddProfile(name1, true); |
242 AddProfile(name2, true); | 242 AddProfile(name2, true); |
243 | 243 |
244 AvatarMenu* menu = GetAvatarMenu(); | 244 AvatarMenu* menu = GetAvatarMenu(); |
245 | 245 |
246 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 246 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
247 | 247 |
248 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 248 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
249 EXPECT_EQ(0U, item1.menu_index); | 249 EXPECT_EQ(0U, item1.menu_index); |
(...skipping 13 matching lines...) Expand all Loading... |
263 EXPECT_GT(change_count(), 1); | 263 EXPECT_GT(change_count(), 1); |
264 EXPECT_EQ(0U, item1next.menu_index); | 264 EXPECT_EQ(0U, item1next.menu_index); |
265 EXPECT_EQ(name2, item1next.name); | 265 EXPECT_EQ(name2, item1next.name); |
266 | 266 |
267 const AvatarMenu::Item& item2next = menu->GetItemAt(1); | 267 const AvatarMenu::Item& item2next = menu->GetItemAt(1); |
268 EXPECT_EQ(1U, item2next.menu_index); | 268 EXPECT_EQ(1U, item2next.menu_index); |
269 EXPECT_EQ(newname1, item2next.name); | 269 EXPECT_EQ(newname1, item2next.name); |
270 } | 270 } |
271 | 271 |
272 TEST_F(ProfileListChromeOSTest, ChangeOnNotify) { | 272 TEST_F(ProfileListChromeOSTest, ChangeOnNotify) { |
273 string16 name1(ASCIIToUTF16("p1.com")); | 273 base::string16 name1(ASCIIToUTF16("p1.com")); |
274 string16 name2(ASCIIToUTF16("p2.com")); | 274 base::string16 name2(ASCIIToUTF16("p2.com")); |
275 | 275 |
276 AddProfile(name1, true); | 276 AddProfile(name1, true); |
277 AddProfile(name2, true); | 277 AddProfile(name2, true); |
278 | 278 |
279 AvatarMenu* menu = GetAvatarMenu(); | 279 AvatarMenu* menu = GetAvatarMenu(); |
280 EXPECT_EQ(2U, menu->GetNumberOfItems()); | 280 EXPECT_EQ(2U, menu->GetNumberOfItems()); |
281 | 281 |
282 string16 name3(ASCIIToUTF16("p3.com")); | 282 base::string16 name3(ASCIIToUTF16("p3.com")); |
283 AddProfile(name3, true); | 283 AddProfile(name3, true); |
284 | 284 |
285 // Four changes happened via the call to CreateTestingProfile: adding the | 285 // Four changes happened via the call to CreateTestingProfile: adding the |
286 // profile to the cache, setting the user name, rebuilding the list of | 286 // profile to the cache, setting the user name, rebuilding the list of |
287 // profiles after the name change, and changing the avatar. | 287 // profiles after the name change, and changing the avatar. |
288 // TODO(michaelpg): Determine why actual change number does not match comment. | 288 // TODO(michaelpg): Determine why actual change number does not match comment. |
289 EXPECT_GE(change_count(), 4); | 289 EXPECT_GE(change_count(), 4); |
290 ASSERT_EQ(3U, menu->GetNumberOfItems()); | 290 ASSERT_EQ(3U, menu->GetNumberOfItems()); |
291 | 291 |
292 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 292 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
293 EXPECT_EQ(0U, item1.menu_index); | 293 EXPECT_EQ(0U, item1.menu_index); |
294 EXPECT_EQ(name1, item1.name); | 294 EXPECT_EQ(name1, item1.name); |
295 | 295 |
296 const AvatarMenu::Item& item2 = menu->GetItemAt(1); | 296 const AvatarMenu::Item& item2 = menu->GetItemAt(1); |
297 EXPECT_EQ(1U, item2.menu_index); | 297 EXPECT_EQ(1U, item2.menu_index); |
298 EXPECT_EQ(name2, item2.name); | 298 EXPECT_EQ(name2, item2.name); |
299 | 299 |
300 const AvatarMenu::Item& item3 = menu->GetItemAt(2); | 300 const AvatarMenu::Item& item3 = menu->GetItemAt(2); |
301 EXPECT_EQ(2U, item3.menu_index); | 301 EXPECT_EQ(2U, item3.menu_index); |
302 EXPECT_EQ(name3, item3.name); | 302 EXPECT_EQ(name3, item3.name); |
303 } | 303 } |
304 | 304 |
305 TEST_F(ProfileListChromeOSTest, DontShowAvatarMenu) { | 305 TEST_F(ProfileListChromeOSTest, DontShowAvatarMenu) { |
306 // If in the new M-32 UX mode the icon gets shown, the menu will not. | 306 // If in the new M-32 UX mode the icon gets shown, the menu will not. |
307 string16 name1(ASCIIToUTF16("p1")); | 307 base::string16 name1(ASCIIToUTF16("p1")); |
308 string16 name2(ASCIIToUTF16("p2")); | 308 base::string16 name2(ASCIIToUTF16("p2")); |
309 | 309 |
310 AddProfile(name1, true); | 310 AddProfile(name1, true); |
311 | 311 |
312 // Should only show avatar menu with multiple users. | 312 // Should only show avatar menu with multiple users. |
313 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 313 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
314 | 314 |
315 AddProfile(name2, false); | 315 AddProfile(name2, false); |
316 | 316 |
317 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 317 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
318 } | 318 } |
319 | 319 |
320 TEST_F(ProfileListChromeOSTest, ShowAvatarMenuInM31) { | 320 TEST_F(ProfileListChromeOSTest, ShowAvatarMenuInM31) { |
321 // In M-31 mode, the menu will get shown. | 321 // In M-31 mode, the menu will get shown. |
322 CommandLine* cl = CommandLine::ForCurrentProcess(); | 322 CommandLine* cl = CommandLine::ForCurrentProcess(); |
323 cl->AppendSwitch(ash::switches::kAshEnableFullMultiProfileMode); | 323 cl->AppendSwitch(ash::switches::kAshEnableFullMultiProfileMode); |
324 | 324 |
325 string16 name1(ASCIIToUTF16("p1")); | 325 base::string16 name1(ASCIIToUTF16("p1")); |
326 string16 name2(ASCIIToUTF16("p2")); | 326 base::string16 name2(ASCIIToUTF16("p2")); |
327 | 327 |
328 AddProfile(name1, true); | 328 AddProfile(name1, true); |
329 | 329 |
330 // Should only show avatar menu with multiple users. | 330 // Should only show avatar menu with multiple users. |
331 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 331 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
332 | 332 |
333 AddProfile(name2, false); | 333 AddProfile(name2, false); |
334 | 334 |
335 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); | 335 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); |
336 } | 336 } |
337 | 337 |
338 } // namespace chromeos | 338 } // namespace chromeos |
OLD | NEW |