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 29 matching lines...) Expand all Loading... | |
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 } | 80 } |
Nikita (slow)
2014/08/19 11:09:48
nit: drop {}
dzhioev (left Google)
2014/08/20 20:21:36
Done.
| |
87 | 81 |
88 // Create a profile for the user. | 82 // Create a profile for the user. |
89 manager()->CreateTestingProfile( | 83 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 } | 84 } |
95 | 85 |
96 AvatarMenu* GetAvatarMenu() { | 86 AvatarMenu* GetAvatarMenu() { |
97 // Reset the MockObserver. | 87 // Reset the MockObserver. |
98 mock_observer_.reset(new MockObserver()); | 88 mock_observer_.reset(new MockObserver()); |
99 EXPECT_EQ(0, change_count()); | 89 EXPECT_EQ(0, change_count()); |
100 | 90 |
101 // Reset the menu. | 91 // Reset the menu. |
102 avatar_menu_.reset(new AvatarMenu( | 92 avatar_menu_.reset(new AvatarMenu( |
103 manager()->profile_info_cache(), | 93 manager()->profile_info_cache(), |
104 mock_observer_.get(), | 94 mock_observer_.get(), |
105 NULL)); | 95 NULL)); |
106 avatar_menu_->RebuildMenu(); | 96 avatar_menu_->RebuildMenu(); |
107 EXPECT_EQ(0, change_count()); | 97 EXPECT_EQ(0, change_count()); |
108 return avatar_menu_.get(); | 98 return avatar_menu_.get(); |
109 } | 99 } |
110 | 100 |
111 void ActiveUserChanged(ProfileHelper* profile_helper, | 101 void ActiveUserChanged(const base::string16& name) { |
112 const std::string& hash) { | 102 std::string email_string = base::UTF16ToASCII(name) + "@example.com"; |
113 profile_helper->ActiveUserHashChanged(hash); | 103 GetFakeUserManager()->SwitchActiveUser(email_string); |
114 } | 104 } |
115 | 105 |
116 TestingProfileManager* manager() { return &manager_; } | 106 TestingProfileManager* manager() { return &manager_; } |
117 | 107 |
118 int change_count() const { return mock_observer_->change_count(); } | 108 int change_count() const { return mock_observer_->change_count(); } |
119 | 109 |
120 private: | 110 private: |
121 TestingProfileManager manager_; | 111 TestingProfileManager manager_; |
122 scoped_ptr<MockObserver> mock_observer_; | 112 scoped_ptr<MockObserver> mock_observer_; |
123 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 113 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); | 203 EXPECT_FALSE(menu->ShouldShowAddNewProfileLink()); |
214 } | 204 } |
215 | 205 |
216 TEST_F(ProfileListChromeOSTest, ActiveItem) { | 206 TEST_F(ProfileListChromeOSTest, ActiveItem) { |
217 base::string16 name1(ASCIIToUTF16("p1.com")); | 207 base::string16 name1(ASCIIToUTF16("p1.com")); |
218 base::string16 name2(ASCIIToUTF16("p2.com")); | 208 base::string16 name2(ASCIIToUTF16("p2.com")); |
219 | 209 |
220 AddProfile(name1, true); | 210 AddProfile(name1, true); |
221 AddProfile(name2, true); | 211 AddProfile(name2, true); |
222 | 212 |
223 // Initialize ProfileHelper, it will be accessed from GetActiveProfileIndex. | 213 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 | 214 |
228 AvatarMenu* menu = GetAvatarMenu(); | 215 AvatarMenu* menu = GetAvatarMenu(); |
229 | 216 |
230 ASSERT_EQ(2U, menu->GetNumberOfItems()); | 217 ASSERT_EQ(2U, menu->GetNumberOfItems()); |
231 // TODO(jeremy): Expand test to verify active profile index other than 0 | 218 // TODO(jeremy): Expand test to verify active profile index other than 0 |
232 // crbug.com/100871 | 219 // crbug.com/100871 |
233 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); | 220 ASSERT_EQ(0U, menu->GetActiveProfileIndex()); |
234 } | 221 } |
235 | 222 |
236 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { | 223 TEST_F(ProfileListChromeOSTest, ModifyingNameResortsCorrectly) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 | 298 |
312 // Should only show avatar menu with multiple users. | 299 // Should only show avatar menu with multiple users. |
313 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 300 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
314 | 301 |
315 AddProfile(name2, false); | 302 AddProfile(name2, false); |
316 | 303 |
317 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 304 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
318 } | 305 } |
319 | 306 |
320 } // namespace chromeos | 307 } // namespace chromeos |
OLD | NEW |