| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 12 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 13 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/browser/prefs/pref_service_syncable.h" | 15 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 16 #include "chrome/browser/profiles/avatar_menu.h" | 16 #include "chrome/browser/profiles/avatar_menu.h" |
| 17 #include "chrome/browser/profiles/avatar_menu_observer.h" | 17 #include "chrome/browser/profiles/avatar_menu_observer.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
| 19 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 19 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 51 ProfileListChromeOSTest() | 51 ProfileListChromeOSTest() |
| 52 : manager_(TestingBrowserProcess::GetGlobal()) { | 52 : manager_(TestingBrowserProcess::GetGlobal()) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 void SetUp() override { | 55 void SetUp() override { |
| 56 ASSERT_TRUE(manager_.SetUp()); | 56 ASSERT_TRUE(manager_.SetUp()); |
| 57 | 57 |
| 58 // AvatarMenu and multiple profiles works after user logged in. | 58 // AvatarMenu and multiple profiles works after user logged in. |
| 59 manager_.SetLoggedIn(true); | 59 manager_.SetLoggedIn(true); |
| 60 | 60 |
| 61 // Initialize the UserManager singleton to a fresh FakeUserManager instance. | 61 // Initialize the UserManager singleton to a fresh FakeChromeUserManager |
| 62 // instance. |
| 62 user_manager_enabler_.reset( | 63 user_manager_enabler_.reset( |
| 63 new ScopedUserManagerEnabler(new FakeUserManager)); | 64 new ScopedUserManagerEnabler(new FakeChromeUserManager)); |
| 64 } | 65 } |
| 65 | 66 |
| 66 FakeUserManager* GetFakeUserManager() { | 67 FakeChromeUserManager* GetFakeChromeUserManager() { |
| 67 return static_cast<FakeUserManager*>(user_manager::UserManager::Get()); | 68 return static_cast<FakeChromeUserManager*>( |
| 69 user_manager::UserManager::Get()); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void AddProfile(base::string16 name, bool log_in) { | 72 void AddProfile(base::string16 name, bool log_in) { |
| 71 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; | 73 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
| 72 | 74 |
| 73 // Add a user to the fake user manager. | 75 // Add a user to the fake user manager. |
| 74 GetFakeUserManager()->AddUser(email_string); | 76 GetFakeChromeUserManager()->AddUser(email_string); |
| 75 if (log_in) | 77 if (log_in) |
| 76 GetFakeUserManager()->LoginUser(email_string); | 78 GetFakeChromeUserManager()->LoginUser(email_string); |
| 77 | 79 |
| 78 // Create a profile for the user. | 80 // Create a profile for the user. |
| 79 manager()->CreateTestingProfile(email_string); | 81 manager()->CreateTestingProfile(email_string); |
| 80 } | 82 } |
| 81 | 83 |
| 82 AvatarMenu* GetAvatarMenu() { | 84 AvatarMenu* GetAvatarMenu() { |
| 83 // Reset the MockObserver. | 85 // Reset the MockObserver. |
| 84 mock_observer_.reset(new MockObserver()); | 86 mock_observer_.reset(new MockObserver()); |
| 85 EXPECT_EQ(0, change_count()); | 87 EXPECT_EQ(0, change_count()); |
| 86 | 88 |
| 87 // Reset the menu. | 89 // Reset the menu. |
| 88 avatar_menu_.reset(new AvatarMenu( | 90 avatar_menu_.reset(new AvatarMenu( |
| 89 manager()->profile_info_cache(), | 91 manager()->profile_info_cache(), |
| 90 mock_observer_.get(), | 92 mock_observer_.get(), |
| 91 NULL)); | 93 NULL)); |
| 92 avatar_menu_->RebuildMenu(); | 94 avatar_menu_->RebuildMenu(); |
| 93 EXPECT_EQ(0, change_count()); | 95 EXPECT_EQ(0, change_count()); |
| 94 return avatar_menu_.get(); | 96 return avatar_menu_.get(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void ActiveUserChanged(const base::string16& name) { | 99 void ActiveUserChanged(const base::string16& name) { |
| 98 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; | 100 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
| 99 GetFakeUserManager()->SwitchActiveUser(email_string); | 101 GetFakeChromeUserManager()->SwitchActiveUser(email_string); |
| 100 } | 102 } |
| 101 | 103 |
| 102 TestingProfileManager* manager() { return &manager_; } | 104 TestingProfileManager* manager() { return &manager_; } |
| 103 | 105 |
| 104 int change_count() const { return mock_observer_->change_count(); } | 106 int change_count() const { return mock_observer_->change_count(); } |
| 105 | 107 |
| 106 private: | 108 private: |
| 107 TestingProfileManager manager_; | 109 TestingProfileManager manager_; |
| 108 scoped_ptr<MockObserver> mock_observer_; | 110 scoped_ptr<MockObserver> mock_observer_; |
| 109 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 111 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 base::string16 supervised_name(ASCIIToUTF16("p2@example.com")); | 158 base::string16 supervised_name(ASCIIToUTF16("p2@example.com")); |
| 157 | 159 |
| 158 AddProfile(name1, true); | 160 AddProfile(name1, true); |
| 159 | 161 |
| 160 // Add a managed user profile. | 162 // Add a managed user profile. |
| 161 ProfileInfoCache* cache = manager()->profile_info_cache(); | 163 ProfileInfoCache* cache = manager()->profile_info_cache(); |
| 162 manager()->profile_info_cache()->AddProfileToCache( | 164 manager()->profile_info_cache()->AddProfileToCache( |
| 163 cache->GetUserDataDir().AppendASCII("p2"), supervised_name, | 165 cache->GetUserDataDir().AppendASCII("p2"), supervised_name, |
| 164 base::string16(), 0, "TEST_ID"); | 166 base::string16(), 0, "TEST_ID"); |
| 165 | 167 |
| 166 GetFakeUserManager()->AddUser(base::UTF16ToASCII(supervised_name)); | 168 GetFakeChromeUserManager()->AddUser(base::UTF16ToASCII(supervised_name)); |
| 167 | 169 |
| 168 AvatarMenu* menu = GetAvatarMenu(); | 170 AvatarMenu* menu = GetAvatarMenu(); |
| 169 ASSERT_EQ(1U, menu->GetNumberOfItems()); | 171 ASSERT_EQ(1U, menu->GetNumberOfItems()); |
| 170 | 172 |
| 171 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 173 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
| 172 EXPECT_EQ(0U, item1.menu_index); | 174 EXPECT_EQ(0U, item1.menu_index); |
| 173 EXPECT_EQ(name1, item1.name); | 175 EXPECT_EQ(name1, item1.name); |
| 174 } | 176 } |
| 175 | 177 |
| 176 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { | 178 TEST_F(ProfileListChromeOSTest, ShowAddProfileLink) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 const AvatarMenu::Item& item1 = menu->GetItemAt(0); | 233 const AvatarMenu::Item& item1 = menu->GetItemAt(0); |
| 232 EXPECT_EQ(0U, item1.menu_index); | 234 EXPECT_EQ(0U, item1.menu_index); |
| 233 EXPECT_EQ(name1, item1.name); | 235 EXPECT_EQ(name1, item1.name); |
| 234 | 236 |
| 235 const AvatarMenu::Item& item2 = menu->GetItemAt(1); | 237 const AvatarMenu::Item& item2 = menu->GetItemAt(1); |
| 236 EXPECT_EQ(1U, item2.menu_index); | 238 EXPECT_EQ(1U, item2.menu_index); |
| 237 EXPECT_EQ(name2, item2.name); | 239 EXPECT_EQ(name2, item2.name); |
| 238 | 240 |
| 239 // Change name of the first profile, to trigger resorting of the profiles: | 241 // Change name of the first profile, to trigger resorting of the profiles: |
| 240 // now the first menu item should be named "beta", and the second be "gamma". | 242 // now the first menu item should be named "beta", and the second be "gamma". |
| 241 GetFakeUserManager()->SaveUserDisplayName( | 243 GetFakeChromeUserManager()->SaveUserDisplayName( |
| 242 base::UTF16ToASCII(name1) + "@example.com", newname1); | 244 base::UTF16ToASCII(name1) + "@example.com", newname1); |
| 243 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); | 245 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); |
| 244 | 246 |
| 245 const AvatarMenu::Item& item1next = menu->GetItemAt(0); | 247 const AvatarMenu::Item& item1next = menu->GetItemAt(0); |
| 246 EXPECT_GT(change_count(), 1); | 248 EXPECT_GT(change_count(), 1); |
| 247 EXPECT_EQ(0U, item1next.menu_index); | 249 EXPECT_EQ(0U, item1next.menu_index); |
| 248 EXPECT_EQ(name2, item1next.name); | 250 EXPECT_EQ(name2, item1next.name); |
| 249 | 251 |
| 250 const AvatarMenu::Item& item2next = menu->GetItemAt(1); | 252 const AvatarMenu::Item& item2next = menu->GetItemAt(1); |
| 251 EXPECT_EQ(1U, item2next.menu_index); | 253 EXPECT_EQ(1U, item2next.menu_index); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 296 |
| 295 // Should only show avatar menu with multiple users. | 297 // Should only show avatar menu with multiple users. |
| 296 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 298 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
| 297 | 299 |
| 298 AddProfile(name2, false); | 300 AddProfile(name2, false); |
| 299 | 301 |
| 300 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 302 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
| 301 } | 303 } |
| 302 | 304 |
| 303 } // namespace chromeos | 305 } // namespace chromeos |
| OLD | NEW |