Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/chromeos/profiles/profile_list_chromeos_unittest.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Rebased. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 new ScopedUserManagerEnabler(new FakeChromeUserManager)); 65 new ScopedUserManagerEnabler(new FakeChromeUserManager));
66 } 66 }
67 67
68 FakeChromeUserManager* GetFakeChromeUserManager() { 68 FakeChromeUserManager* GetFakeChromeUserManager() {
69 return static_cast<FakeChromeUserManager*>( 69 return static_cast<FakeChromeUserManager*>(
70 user_manager::UserManager::Get()); 70 user_manager::UserManager::Get());
71 } 71 }
72 72
73 void AddProfile(base::string16 name, bool log_in) { 73 void AddProfile(base::string16 name, bool log_in) {
74 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; 74 std::string email_string = base::UTF16ToASCII(name) + "@example.com";
75 const AccountId account_id(AccountId::FromUserEmail(email_string));
75 76
76 // Add a user to the fake user manager. 77 // Add a user to the fake user manager.
77 GetFakeChromeUserManager()->AddUser(email_string); 78 GetFakeChromeUserManager()->AddUser(account_id);
78 if (log_in) 79 if (log_in)
79 GetFakeChromeUserManager()->LoginUser(email_string); 80 GetFakeChromeUserManager()->LoginUser(account_id);
80 81
81 // Create a profile for the user. 82 // Create a profile for the user.
82 manager()->CreateTestingProfile(email_string); 83 manager()->CreateTestingProfile(account_id.GetUserEmail());
83 } 84 }
84 85
85 AvatarMenu* GetAvatarMenu() { 86 AvatarMenu* GetAvatarMenu() {
86 // Reset the MockObserver. 87 // Reset the MockObserver.
87 mock_observer_.reset(new MockObserver()); 88 mock_observer_.reset(new MockObserver());
88 EXPECT_EQ(0, change_count()); 89 EXPECT_EQ(0, change_count());
89 90
90 // Reset the menu. 91 // Reset the menu.
91 avatar_menu_.reset(new AvatarMenu( 92 avatar_menu_.reset(new AvatarMenu(
92 manager()->profile_info_cache(), 93 manager()->profile_info_cache(),
93 mock_observer_.get(), 94 mock_observer_.get(),
94 NULL)); 95 NULL));
95 avatar_menu_->RebuildMenu(); 96 avatar_menu_->RebuildMenu();
96 EXPECT_EQ(0, change_count()); 97 EXPECT_EQ(0, change_count());
97 return avatar_menu_.get(); 98 return avatar_menu_.get();
98 } 99 }
99 100
100 void ActiveUserChanged(const base::string16& name) { 101 void ActiveUserChanged(const base::string16& name) {
101 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; 102 std::string email_string = base::UTF16ToASCII(name) + "@example.com";
102 GetFakeChromeUserManager()->SwitchActiveUser(email_string); 103 const AccountId account_id(AccountId::FromUserEmail(email_string));
104 GetFakeChromeUserManager()->SwitchActiveUser(account_id);
103 } 105 }
104 106
105 TestingProfileManager* manager() { return &manager_; } 107 TestingProfileManager* manager() { return &manager_; }
106 108
107 int change_count() const { return mock_observer_->change_count(); } 109 int change_count() const { return mock_observer_->change_count(); }
108 110
109 private: 111 private:
110 content::TestBrowserThreadBundle thread_bundle_; 112 content::TestBrowserThreadBundle thread_bundle_;
111 TestingProfileManager manager_; 113 TestingProfileManager manager_;
112 scoped_ptr<MockObserver> mock_observer_; 114 scoped_ptr<MockObserver> mock_observer_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 base::string16 supervised_name(ASCIIToUTF16("p2@example.com")); 162 base::string16 supervised_name(ASCIIToUTF16("p2@example.com"));
161 163
162 AddProfile(name1, true); 164 AddProfile(name1, true);
163 165
164 // Add a managed user profile. 166 // Add a managed user profile.
165 ProfileInfoCache* cache = manager()->profile_info_cache(); 167 ProfileInfoCache* cache = manager()->profile_info_cache();
166 manager()->profile_info_cache()->AddProfileToCache( 168 manager()->profile_info_cache()->AddProfileToCache(
167 cache->GetUserDataDir().AppendASCII("p2"), supervised_name, std::string(), 169 cache->GetUserDataDir().AppendASCII("p2"), supervised_name, std::string(),
168 base::string16(), 0, "TEST_ID"); 170 base::string16(), 0, "TEST_ID");
169 171
170 GetFakeChromeUserManager()->AddUser(base::UTF16ToASCII(supervised_name)); 172 GetFakeChromeUserManager()->AddUser(
173 AccountId::FromUserEmail(base::UTF16ToASCII(supervised_name)));
171 174
172 AvatarMenu* menu = GetAvatarMenu(); 175 AvatarMenu* menu = GetAvatarMenu();
173 ASSERT_EQ(1U, menu->GetNumberOfItems()); 176 ASSERT_EQ(1U, menu->GetNumberOfItems());
174 177
175 const AvatarMenu::Item& item1 = menu->GetItemAt(0); 178 const AvatarMenu::Item& item1 = menu->GetItemAt(0);
176 EXPECT_EQ(0U, item1.menu_index); 179 EXPECT_EQ(0U, item1.menu_index);
177 EXPECT_EQ(name1, item1.name); 180 EXPECT_EQ(name1, item1.name);
178 } 181 }
179 182
180 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { 183 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 EXPECT_EQ(0U, item1.menu_index); 239 EXPECT_EQ(0U, item1.menu_index);
237 EXPECT_EQ(name1, item1.name); 240 EXPECT_EQ(name1, item1.name);
238 241
239 const AvatarMenu::Item& item2 = menu->GetItemAt(1); 242 const AvatarMenu::Item& item2 = menu->GetItemAt(1);
240 EXPECT_EQ(1U, item2.menu_index); 243 EXPECT_EQ(1U, item2.menu_index);
241 EXPECT_EQ(name2, item2.name); 244 EXPECT_EQ(name2, item2.name);
242 245
243 // Change name of the first profile, to trigger resorting of the profiles: 246 // Change name of the first profile, to trigger resorting of the profiles:
244 // now the first menu item should be named "beta", and the second be "gamma". 247 // now the first menu item should be named "beta", and the second be "gamma".
245 GetFakeChromeUserManager()->SaveUserDisplayName( 248 GetFakeChromeUserManager()->SaveUserDisplayName(
246 base::UTF16ToASCII(name1) + "@example.com", newname1); 249 AccountId::FromUserEmail(base::UTF16ToASCII(name1) + "@example.com"),
250 newname1);
247 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); 251 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1);
248 EXPECT_EQ(1, change_count()); 252 EXPECT_EQ(1, change_count());
249 253
250 const AvatarMenu::Item& item1next = menu->GetItemAt(0); 254 const AvatarMenu::Item& item1next = menu->GetItemAt(0);
251 EXPECT_EQ(0U, item1next.menu_index); 255 EXPECT_EQ(0U, item1next.menu_index);
252 EXPECT_EQ(name2, item1next.name); 256 EXPECT_EQ(name2, item1next.name);
253 257
254 const AvatarMenu::Item& item2next = menu->GetItemAt(1); 258 const AvatarMenu::Item& item2next = menu->GetItemAt(1);
255 EXPECT_EQ(1U, item2next.menu_index); 259 EXPECT_EQ(1U, item2next.menu_index);
256 EXPECT_EQ(newname1, item2next.name); 260 EXPECT_EQ(newname1, item2next.name);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 302
299 // Should only show avatar menu with multiple users. 303 // Should only show avatar menu with multiple users.
300 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); 304 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu());
301 305
302 AddProfile(name2, false); 306 AddProfile(name2, false);
303 307
304 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); 308 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu());
305 } 309 }
306 310
307 } // namespace chromeos 311 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698