OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/profiles/profile_list_desktop.h" | 5 #include "chrome/browser/profiles/profile_list_desktop.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 scoped_ptr<AvatarMenu> avatar_menu_; | 79 scoped_ptr<AvatarMenu> avatar_menu_; |
80 | 80 |
81 DISALLOW_COPY_AND_ASSIGN(ProfileListDesktopTest); | 81 DISALLOW_COPY_AND_ASSIGN(ProfileListDesktopTest); |
82 }; | 82 }; |
83 | 83 |
84 TEST_F(ProfileListDesktopTest, InitialCreation) { | 84 TEST_F(ProfileListDesktopTest, InitialCreation) { |
85 string16 name1(ASCIIToUTF16("Test 1")); | 85 string16 name1(ASCIIToUTF16("Test 1")); |
86 string16 name2(ASCIIToUTF16("Test 2")); | 86 string16 name2(ASCIIToUTF16("Test 2")); |
87 | 87 |
88 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 88 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
89 name1, 0, std::string()); | 89 name1, 0, std::string(), |
| 90 TestingProfile::TestingFactories()); |
90 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 91 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
91 name2, 0, std::string()); | 92 name2, 0, std::string(), |
| 93 TestingProfile::TestingFactories()); |
92 | 94 |
93 AvatarMenu* model = GetAvatarMenu(); | 95 AvatarMenu* model = GetAvatarMenu(); |
94 EXPECT_EQ(0, change_count()); | 96 EXPECT_EQ(0, change_count()); |
95 | 97 |
96 ASSERT_EQ(2U, model->GetNumberOfItems()); | 98 ASSERT_EQ(2U, model->GetNumberOfItems()); |
97 | 99 |
98 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 100 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
99 EXPECT_EQ(0U, item1.menu_index); | 101 EXPECT_EQ(0U, item1.menu_index); |
100 EXPECT_EQ(name1, item1.name); | 102 EXPECT_EQ(name1, item1.name); |
101 | 103 |
102 const AvatarMenu::Item& item2 = model->GetItemAt(1); | 104 const AvatarMenu::Item& item2 = model->GetItemAt(1); |
103 EXPECT_EQ(1U, item2.menu_index); | 105 EXPECT_EQ(1U, item2.menu_index); |
104 EXPECT_EQ(name2, item2.name); | 106 EXPECT_EQ(name2, item2.name); |
105 } | 107 } |
106 | 108 |
107 TEST_F(ProfileListDesktopTest, ActiveItem) { | 109 TEST_F(ProfileListDesktopTest, ActiveItem) { |
108 string16 name1(ASCIIToUTF16("Test 1")); | 110 string16 name1(ASCIIToUTF16("Test 1")); |
109 string16 name2(ASCIIToUTF16("Test 2")); | 111 string16 name2(ASCIIToUTF16("Test 2")); |
110 | 112 |
111 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 113 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
112 name1, 0, std::string()); | 114 name1, 0, std::string(), |
| 115 TestingProfile::TestingFactories()); |
113 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 116 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
114 name2, 0, std::string()); | 117 name2, 0, std::string(), |
| 118 TestingProfile::TestingFactories()); |
115 | 119 |
116 AvatarMenu* model = GetAvatarMenu(); | 120 AvatarMenu* model = GetAvatarMenu(); |
117 ASSERT_EQ(2U, model->GetNumberOfItems()); | 121 ASSERT_EQ(2U, model->GetNumberOfItems()); |
118 // TODO(jeremy): Expand test to verify active profile index other than 0 | 122 // TODO(jeremy): Expand test to verify active profile index other than 0 |
119 // crbug.com/100871 | 123 // crbug.com/100871 |
120 ASSERT_EQ(0U, model->GetActiveProfileIndex()); | 124 ASSERT_EQ(0U, model->GetActiveProfileIndex()); |
121 } | 125 } |
122 | 126 |
123 TEST_F(ProfileListDesktopTest, ModifyingNameResortsCorrectly) { | 127 TEST_F(ProfileListDesktopTest, ModifyingNameResortsCorrectly) { |
124 string16 name1(ASCIIToUTF16("Alpha")); | 128 string16 name1(ASCIIToUTF16("Alpha")); |
125 string16 name2(ASCIIToUTF16("Beta")); | 129 string16 name2(ASCIIToUTF16("Beta")); |
126 string16 newname1(ASCIIToUTF16("Gamma")); | 130 string16 newname1(ASCIIToUTF16("Gamma")); |
127 | 131 |
128 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 132 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
129 name1, 0, std::string()); | 133 name1, 0, std::string(), |
| 134 TestingProfile::TestingFactories()); |
130 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 135 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
131 name2, 0, std::string()); | 136 name2, 0, std::string(), |
| 137 TestingProfile::TestingFactories()); |
132 | 138 |
133 AvatarMenu* model = GetAvatarMenu(); | 139 AvatarMenu* model = GetAvatarMenu(); |
134 EXPECT_EQ(0, change_count()); | 140 EXPECT_EQ(0, change_count()); |
135 | 141 |
136 ASSERT_EQ(2U, model->GetNumberOfItems()); | 142 ASSERT_EQ(2U, model->GetNumberOfItems()); |
137 | 143 |
138 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 144 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
139 EXPECT_EQ(0U, item1.menu_index); | 145 EXPECT_EQ(0U, item1.menu_index); |
140 EXPECT_EQ(name1, item1.name); | 146 EXPECT_EQ(name1, item1.name); |
141 | 147 |
(...skipping 12 matching lines...) Expand all Loading... |
154 const AvatarMenu::Item& item2next = model->GetItemAt(1); | 160 const AvatarMenu::Item& item2next = model->GetItemAt(1); |
155 EXPECT_EQ(1U, item2next.menu_index); | 161 EXPECT_EQ(1U, item2next.menu_index); |
156 EXPECT_EQ(newname1, item2next.name); | 162 EXPECT_EQ(newname1, item2next.name); |
157 } | 163 } |
158 | 164 |
159 TEST_F(ProfileListDesktopTest, ChangeOnNotify) { | 165 TEST_F(ProfileListDesktopTest, ChangeOnNotify) { |
160 string16 name1(ASCIIToUTF16("Test 1")); | 166 string16 name1(ASCIIToUTF16("Test 1")); |
161 string16 name2(ASCIIToUTF16("Test 2")); | 167 string16 name2(ASCIIToUTF16("Test 2")); |
162 | 168 |
163 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 169 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
164 name1, 0, std::string()); | 170 name1, 0, std::string(), |
| 171 TestingProfile::TestingFactories()); |
165 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 172 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
166 name2, 0, std::string()); | 173 name2, 0, std::string(), |
| 174 TestingProfile::TestingFactories()); |
167 | 175 |
168 AvatarMenu* model = GetAvatarMenu(); | 176 AvatarMenu* model = GetAvatarMenu(); |
169 EXPECT_EQ(0, change_count()); | 177 EXPECT_EQ(0, change_count()); |
170 EXPECT_EQ(2U, model->GetNumberOfItems()); | 178 EXPECT_EQ(2U, model->GetNumberOfItems()); |
171 | 179 |
172 string16 name3(ASCIIToUTF16("Test 3")); | 180 string16 name3(ASCIIToUTF16("Test 3")); |
173 manager()->CreateTestingProfile("p3", scoped_ptr<PrefServiceSyncable>(), | 181 manager()->CreateTestingProfile("p3", scoped_ptr<PrefServiceSyncable>(), |
174 name3, 0, std::string()); | 182 name3, 0, std::string(), |
| 183 TestingProfile::TestingFactories()); |
175 | 184 |
176 // Four changes happened via the call to CreateTestingProfile: adding the | 185 // Four changes happened via the call to CreateTestingProfile: adding the |
177 // profile to the cache, setting the user name, rebuilding the list of | 186 // profile to the cache, setting the user name, rebuilding the list of |
178 // profiles after the name change, and changing the avatar. | 187 // profiles after the name change, and changing the avatar. |
179 // On Windows, an extra change happens to set the shortcut name for the | 188 // On Windows, an extra change happens to set the shortcut name for the |
180 // profile. | 189 // profile. |
181 // TODO(michaelpg): Determine why five changes happen on ChromeOS and | 190 // TODO(michaelpg): Determine why five changes happen on ChromeOS and |
182 // investigate other platforms. | 191 // investigate other platforms. |
183 EXPECT_GE(change_count(), 4); | 192 EXPECT_GE(change_count(), 4); |
184 ASSERT_EQ(3U, model->GetNumberOfItems()); | 193 ASSERT_EQ(3U, model->GetNumberOfItems()); |
(...skipping 23 matching lines...) Expand all Loading... |
208 #if defined(OS_CHROMEOS) | 217 #if defined(OS_CHROMEOS) |
209 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 218 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
210 #else | 219 #else |
211 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); | 220 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); |
212 #endif | 221 #endif |
213 } | 222 } |
214 | 223 |
215 TEST_F(ProfileListDesktopTest, DontShowAvatarMenu) { | 224 TEST_F(ProfileListDesktopTest, DontShowAvatarMenu) { |
216 string16 name1(ASCIIToUTF16("Test 1")); | 225 string16 name1(ASCIIToUTF16("Test 1")); |
217 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 226 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
218 name1, 0, std::string()); | 227 name1, 0, std::string(), |
| 228 TestingProfile::TestingFactories()); |
219 | 229 |
220 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 230 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
221 | 231 |
222 // If multiprofile mode is enabled, there are no other cases when we wouldn't | 232 // If multiprofile mode is enabled, there are no other cases when we wouldn't |
223 // show the menu. | 233 // show the menu. |
224 if (profiles::IsMultipleProfilesEnabled()) | 234 if (profiles::IsMultipleProfilesEnabled()) |
225 return; | 235 return; |
226 | 236 |
227 string16 name2(ASCIIToUTF16("Test 2")); | 237 string16 name2(ASCIIToUTF16("Test 2")); |
228 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 238 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
229 name2, 0, std::string()); | 239 name2, 0, std::string(), |
| 240 TestingProfile::TestingFactories()); |
230 | 241 |
231 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 242 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
232 } | 243 } |
233 | 244 |
234 TEST_F(ProfileListDesktopTest, ShowAvatarMenu) { | 245 TEST_F(ProfileListDesktopTest, ShowAvatarMenu) { |
235 // If multiprofile mode is not enabled then the menu is never shown. | 246 // If multiprofile mode is not enabled then the menu is never shown. |
236 if (!profiles::IsMultipleProfilesEnabled()) | 247 if (!profiles::IsMultipleProfilesEnabled()) |
237 return; | 248 return; |
238 | 249 |
239 string16 name1(ASCIIToUTF16("Test 1")); | 250 string16 name1(ASCIIToUTF16("Test 1")); |
240 string16 name2(ASCIIToUTF16("Test 2")); | 251 string16 name2(ASCIIToUTF16("Test 2")); |
241 | 252 |
242 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 253 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
243 name1, 0, std::string()); | 254 name1, 0, std::string(), |
| 255 TestingProfile::TestingFactories()); |
244 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 256 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
245 name2, 0, std::string()); | 257 name2, 0, std::string(), |
| 258 TestingProfile::TestingFactories()); |
246 | 259 |
247 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
248 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); | 261 EXPECT_FALSE(AvatarMenu::ShouldShowAvatarMenu()); |
249 #else | 262 #else |
250 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); | 263 EXPECT_TRUE(AvatarMenu::ShouldShowAvatarMenu()); |
251 #endif | 264 #endif |
252 } | 265 } |
253 | 266 |
254 TEST_F(ProfileListDesktopTest, SyncState) { | 267 TEST_F(ProfileListDesktopTest, SyncState) { |
255 // If multiprofile mode is not enabled then the menu is never shown. | 268 // If multiprofile mode is not enabled then the menu is never shown. |
256 if (!profiles::IsMultipleProfilesEnabled()) | 269 if (!profiles::IsMultipleProfilesEnabled()) |
257 return; | 270 return; |
258 | 271 |
259 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 272 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
260 ASCIIToUTF16("Test 1"), 0, std::string()); | 273 ASCIIToUTF16("Test 1"), 0, std::string(), |
| 274 TestingProfile::TestingFactories()); |
261 | 275 |
262 // Add a managed user profile. | 276 // Add a managed user profile. |
263 ProfileInfoCache* cache = manager()->profile_info_cache(); | 277 ProfileInfoCache* cache = manager()->profile_info_cache(); |
264 manager()->profile_info_cache()->AddProfileToCache( | 278 manager()->profile_info_cache()->AddProfileToCache( |
265 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), | 279 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), |
266 string16(), 0, "TEST_ID"); | 280 string16(), 0, "TEST_ID"); |
267 | 281 |
268 AvatarMenu* model = GetAvatarMenu(); | 282 AvatarMenu* model = GetAvatarMenu(); |
269 model->RebuildMenu(); | 283 model->RebuildMenu(); |
270 EXPECT_EQ(2U, model->GetNumberOfItems()); | 284 EXPECT_EQ(2U, model->GetNumberOfItems()); |
271 | 285 |
272 // Now check that the sync_state of a managed user shows the managed user | 286 // Now check that the sync_state of a managed user shows the managed user |
273 // avatar label instead. | 287 // avatar label instead. |
274 base::string16 managed_user_label = | 288 base::string16 managed_user_label = |
275 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); | 289 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); |
276 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 290 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
277 EXPECT_NE(item1.sync_state, managed_user_label); | 291 EXPECT_NE(item1.sync_state, managed_user_label); |
278 | 292 |
279 const AvatarMenu::Item& item2 = model->GetItemAt(1); | 293 const AvatarMenu::Item& item2 = model->GetItemAt(1); |
280 EXPECT_EQ(item2.sync_state, managed_user_label); | 294 EXPECT_EQ(item2.sync_state, managed_user_label); |
281 } | 295 } |
282 | 296 |
283 } // namespace | 297 } // namespace |
OLD | NEW |