| 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_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" |
| 23 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 using base::ASCIIToUTF16; | 26 using base::ASCIIToUTF16; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // As defined in /chromeos/dbus/cryptohome_client.cc. | |
| 31 static const char kUserIdHashSuffix[] = "-hash"; | |
| 32 | |
| 33 class MockObserver : public AvatarMenuObserver { | 30 class MockObserver : public AvatarMenuObserver { |
| 34 public: | 31 public: |
| 35 MockObserver() : count_(0) {} | 32 MockObserver() : count_(0) {} |
| 36 virtual ~MockObserver() {} | 33 virtual ~MockObserver() {} |
| 37 | 34 |
| 38 virtual void OnAvatarMenuChanged( | 35 virtual void OnAvatarMenuChanged( |
| 39 AvatarMenu* avatar_menu) OVERRIDE { | 36 AvatarMenu* avatar_menu) OVERRIDE { |
| 40 ++count_; | 37 ++count_; |
| 41 } | 38 } |
| 42 | 39 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 71 | 68 |
| 72 FakeUserManager* GetFakeUserManager() { | 69 FakeUserManager* GetFakeUserManager() { |
| 73 return static_cast<FakeUserManager*>(user_manager::UserManager::Get()); | 70 return static_cast<FakeUserManager*>(user_manager::UserManager::Get()); |
| 74 } | 71 } |
| 75 | 72 |
| 76 void AddProfile(base::string16 name, bool log_in) { | 73 void AddProfile(base::string16 name, bool log_in) { |
| 77 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; | 74 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
| 78 | 75 |
| 79 // Add a user to the fake user manager. | 76 // Add a user to the fake user manager. |
| 80 GetFakeUserManager()->AddUser(email_string); | 77 GetFakeUserManager()->AddUser(email_string); |
| 81 if (log_in) { | 78 if (log_in) |
| 82 GetFakeUserManager()->UserLoggedIn( | 79 GetFakeUserManager()->LoginUser(email_string); |
| 83 email_string, | |
| 84 email_string + kUserIdHashSuffix, | |
| 85 false); | |
| 86 } | |
| 87 | 80 |
| 88 // Create a profile for the user. | 81 // Create a profile for the user. |
| 89 manager()->CreateTestingProfile( | 82 manager()->CreateTestingProfile(email_string); |
| 90 chrome::kProfileDirPrefix + email_string + kUserIdHashSuffix, | |
| 91 scoped_ptr<PrefServiceSyncable>(), | |
| 92 ASCIIToUTF16(email_string), 0, std::string(), | |
| 93 TestingProfile::TestingFactories()); | |
| 94 } | 83 } |
| 95 | 84 |
| 96 AvatarMenu* GetAvatarMenu() { | 85 AvatarMenu* GetAvatarMenu() { |
| 97 // Reset the MockObserver. | 86 // Reset the MockObserver. |
| 98 mock_observer_.reset(new MockObserver()); | 87 mock_observer_.reset(new MockObserver()); |
| 99 EXPECT_EQ(0, change_count()); | 88 EXPECT_EQ(0, change_count()); |
| 100 | 89 |
| 101 // Reset the menu. | 90 // Reset the menu. |
| 102 avatar_menu_.reset(new AvatarMenu( | 91 avatar_menu_.reset(new AvatarMenu( |
| 103 manager()->profile_info_cache(), | 92 manager()->profile_info_cache(), |
| 104 mock_observer_.get(), | 93 mock_observer_.get(), |
| 105 NULL)); | 94 NULL)); |
| 106 avatar_menu_->RebuildMenu(); | 95 avatar_menu_->RebuildMenu(); |
| 107 EXPECT_EQ(0, change_count()); | 96 EXPECT_EQ(0, change_count()); |
| 108 return avatar_menu_.get(); | 97 return avatar_menu_.get(); |
| 109 } | 98 } |
| 110 | 99 |
| 111 void ActiveUserChanged(ProfileHelper* profile_helper, | 100 void ActiveUserChanged(const base::string16& name) { |
| 112 const std::string& hash) { | 101 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
| 113 profile_helper->ActiveUserHashChanged(hash); | 102 GetFakeUserManager()->SwitchActiveUser(email_string); |
| 114 } | 103 } |
| 115 | 104 |
| 116 TestingProfileManager* manager() { return &manager_; } | 105 TestingProfileManager* manager() { return &manager_; } |
| 117 | 106 |
| 118 int change_count() const { return mock_observer_->change_count(); } | 107 int change_count() const { return mock_observer_->change_count(); } |
| 119 | 108 |
| 120 private: | 109 private: |
| 121 TestingProfileManager manager_; | 110 TestingProfileManager manager_; |
| 122 scoped_ptr<MockObserver> mock_observer_; | 111 scoped_ptr<MockObserver> mock_observer_; |
| 123 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 112 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); | 202 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); |
| 214 } | 203 } |
| 215 | 204 |
| 216 TEST_F(ProfileListChromeOSTest, ActiveItem) { | 205 TEST_F(ProfileListChromeOSTest, ActiveItem) { |
| 217 base::string16 name1(ASCIIToUTF16("p1.com")); | 206 base::string16 name1(ASCIIToUTF16("p1.com")); |
| 218 base::string16 name2(ASCIIToUTF16("p2.com")); | 207 base::string16 name2(ASCIIToUTF16("p2.com")); |
| 219 | 208 |
| 220 AddProfile(name1, true); | 209 AddProfile(name1, true); |
| 221 AddProfile(name2, true); | 210 AddProfile(name2, true); |
| 222 | 211 |
| 223 // Initialize ProfileHelper, it will be accessed from GetActiveProfileIndex. | 212 ActiveUserChanged(name1); |
| 224 std::string email_string = base::UTF16ToASCII(name1) + "@example.com"; | |
| 225 std::string hash = email_string + kUserIdHashSuffix; | |
| 226 ActiveUserChanged(ProfileHelper::Get(), hash); | |
| 227 | 213 |
| 228 AvatarMenu* menu = GetAvatarMenu(); | 214 AvatarMenu* menu = GetAvatarMenu(); |
| 229 | 215 |
| 230 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 216 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
| 231 // TODO(jeremy): Expand test to verify active profile index other than 0 | 217 // TODO(jeremy): Expand test to verify active profile index other than 0 |
| 232 // crbug.com/100871 | 218 // crbug.com/100871 |
| 233 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); | 219 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); |
| 234 } | 220 } |
| 235 | 221 |
| 236 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { | 222 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 297 |
| 312 // Should only show avatar menu with multiple users. | 298 // Should only show avatar menu with multiple users. |
| 313 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 299 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
| 314 | 300 |
| 315 AddProfile(name2, false); | 301 AddProfile(name2, false); |
| 316 | 302 |
| 317 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 303 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
| 318 } | 304 } |
| 319 | 305 |
| 320 } // namespace chromeos | 306 } // namespace chromeos |
| OLD | NEW |