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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/prefs/pref_service_syncable.h" | 14 #include "chrome/browser/prefs/pref_service_syncable.h" |
15 #include "chrome/browser/profiles/avatar_menu_observer.h" | 15 #include "chrome/browser/profiles/avatar_menu_observer.h" |
16 #include "chrome/browser/profiles/profile_info_cache.h" | 16 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 17 #include "chrome/browser/profiles/profile_attributes_storage.h" |
17 #include "chrome/browser/profiles/profiles_state.h" | 18 #include "chrome/browser/profiles/profiles_state.h" |
18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
19 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
20 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
21 #include "components/signin/core/common/profile_management_switches.h" | 22 #include "components/signin/core/common/profile_management_switches.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
25 | 26 |
26 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
(...skipping 29 matching lines...) Expand all Loading... |
56 #endif | 57 #endif |
57 } | 58 } |
58 | 59 |
59 AvatarMenu* GetAvatarMenu() { | 60 AvatarMenu* GetAvatarMenu() { |
60 // Reset the MockObserver. | 61 // Reset the MockObserver. |
61 mock_observer_.reset(new MockObserver()); | 62 mock_observer_.reset(new MockObserver()); |
62 EXPECT_EQ(0, change_count()); | 63 EXPECT_EQ(0, change_count()); |
63 | 64 |
64 // Reset the model. | 65 // Reset the model. |
65 avatar_menu_.reset(new AvatarMenu( | 66 avatar_menu_.reset(new AvatarMenu( |
66 manager()->profile_info_cache(), | 67 manager()->profile_attributes_storage(), |
67 mock_observer_.get(), | 68 mock_observer_.get(), |
68 NULL)); | 69 NULL)); |
69 avatar_menu_->RebuildMenu(); | 70 avatar_menu_->RebuildMenu(); |
70 EXPECT_EQ(0, change_count()); | 71 EXPECT_EQ(0, change_count()); |
71 return avatar_menu_.get(); | 72 return avatar_menu_.get(); |
72 } | 73 } |
73 | 74 |
74 TestingProfileManager* manager() { return &manager_; } | 75 TestingProfileManager* manager() { return &manager_; } |
75 | 76 |
76 void AddOmittedProfile(std::string name) { | 77 void AddOmittedProfile(std::string name) { |
77 ProfileInfoCache* cache = manager()->profile_info_cache(); | 78 ProfileAttributesStorage* storage = manager()->profile_attributes_storage(); |
78 cache->AddProfileToCache( | 79 storage->AddProfile( |
79 cache->GetUserDataDir().AppendASCII(name), ASCIIToUTF16(name), | 80 storage->GetUserDataDir().AppendASCII(name), ASCIIToUTF16(name), |
80 std::string(), base::string16(), 0, "TEST_ID"); | 81 std::string(), base::string16(), 0, "TEST_ID"); |
81 } | 82 } |
82 | 83 |
83 int change_count() const { return mock_observer_->change_count(); } | 84 int change_count() const { return mock_observer_->change_count(); } |
84 | 85 |
85 private: | 86 private: |
86 TestingProfileManager manager_; | 87 TestingProfileManager manager_; |
87 scoped_ptr<MockObserver> mock_observer_; | 88 scoped_ptr<MockObserver> mock_observer_; |
88 scoped_ptr<AvatarMenu> avatar_menu_; | 89 scoped_ptr<AvatarMenu> avatar_menu_; |
89 content::TestBrowserThreadBundle thread_bundle_; | 90 content::TestBrowserThreadBundle thread_bundle_; |
(...skipping 13 matching lines...) Expand all Loading... |
103 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 104 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
104 EXPECT_EQ(0U, item1.menu_index); | 105 EXPECT_EQ(0U, item1.menu_index); |
105 EXPECT_EQ(ASCIIToUTF16("Test 1"), item1.name); | 106 EXPECT_EQ(ASCIIToUTF16("Test 1"), item1.name); |
106 | 107 |
107 const AvatarMenu::Item& item2 = model->GetItemAt(1); | 108 const AvatarMenu::Item& item2 = model->GetItemAt(1); |
108 EXPECT_EQ(1U, item2.menu_index); | 109 EXPECT_EQ(1U, item2.menu_index); |
109 EXPECT_EQ(ASCIIToUTF16("Test 2"), item2.name); | 110 EXPECT_EQ(ASCIIToUTF16("Test 2"), item2.name); |
110 } | 111 } |
111 | 112 |
112 TEST_F(ProfileListDesktopTest, NoOmittedProfiles) { | 113 TEST_F(ProfileListDesktopTest, NoOmittedProfiles) { |
113 ProfileListDesktop profile_list(manager()->profile_info_cache()); | 114 ProfileListDesktop profile_list(manager()->profile_attributes_storage()); |
114 | 115 |
115 // Profiles are stored and listed alphabetically. | 116 // Profiles are stored and listed alphabetically. |
116 manager()->CreateTestingProfile("1 included"); | 117 manager()->CreateTestingProfile("1 included"); |
117 manager()->CreateTestingProfile("2 included"); | 118 manager()->CreateTestingProfile("2 included"); |
118 manager()->CreateTestingProfile("3 included"); | 119 manager()->CreateTestingProfile("3 included"); |
119 manager()->CreateTestingProfile("4 included"); | 120 manager()->CreateTestingProfile("4 included"); |
120 | 121 |
121 profile_list.RebuildMenu(); | 122 profile_list.RebuildMenu(); |
122 ASSERT_EQ(4u, profile_list.GetNumberOfItems()); | 123 ASSERT_EQ(4u, profile_list.GetNumberOfItems()); |
123 | 124 |
124 const AvatarMenu::Item& item1 = profile_list.GetItemAt(0); | 125 const AvatarMenu::Item& item1 = profile_list.GetItemAt(0); |
125 EXPECT_EQ(0u, item1.menu_index); | 126 EXPECT_EQ(0u, item1.menu_index); |
126 EXPECT_EQ(0u, item1.profile_index); | |
127 EXPECT_EQ(ASCIIToUTF16("1 included"), item1.name); | 127 EXPECT_EQ(ASCIIToUTF16("1 included"), item1.name); |
128 | 128 |
129 const AvatarMenu::Item& item2 = profile_list.GetItemAt(1); | 129 const AvatarMenu::Item& item2 = profile_list.GetItemAt(1); |
130 EXPECT_EQ(1u, item2.menu_index); | 130 EXPECT_EQ(1u, item2.menu_index); |
131 EXPECT_EQ(1u, item2.profile_index); | |
132 EXPECT_EQ(ASCIIToUTF16("2 included"), item2.name); | 131 EXPECT_EQ(ASCIIToUTF16("2 included"), item2.name); |
133 | 132 |
134 const AvatarMenu::Item& item3 = profile_list.GetItemAt(2); | 133 const AvatarMenu::Item& item3 = profile_list.GetItemAt(2); |
135 EXPECT_EQ(2u, item3.menu_index); | 134 EXPECT_EQ(2u, item3.menu_index); |
136 EXPECT_EQ(2u, item3.profile_index); | |
137 EXPECT_EQ(ASCIIToUTF16("3 included"), item3.name); | 135 EXPECT_EQ(ASCIIToUTF16("3 included"), item3.name); |
138 | 136 |
139 const AvatarMenu::Item& item4 = profile_list.GetItemAt(3); | 137 const AvatarMenu::Item& item4 = profile_list.GetItemAt(3); |
140 EXPECT_EQ(3u, item4.menu_index); | 138 EXPECT_EQ(3u, item4.menu_index); |
141 EXPECT_EQ(3u, item4.profile_index); | |
142 EXPECT_EQ(ASCIIToUTF16("4 included"), item4.name); | 139 EXPECT_EQ(ASCIIToUTF16("4 included"), item4.name); |
143 | 140 |
144 EXPECT_EQ(0u, profile_list.MenuIndexFromProfileIndex(0)); | 141 EXPECT_EQ(0u, profile_list.MenuIndexFromProfilePath(item1.profile_path)); |
145 EXPECT_EQ(1u, profile_list.MenuIndexFromProfileIndex(1)); | 142 EXPECT_EQ(1u, profile_list.MenuIndexFromProfilePath(item2.profile_path)); |
146 EXPECT_EQ(2u, profile_list.MenuIndexFromProfileIndex(2)); | 143 EXPECT_EQ(2u, profile_list.MenuIndexFromProfilePath(item3.profile_path)); |
147 EXPECT_EQ(3u, profile_list.MenuIndexFromProfileIndex(3)); | 144 EXPECT_EQ(3u, profile_list.MenuIndexFromProfilePath(item4.profile_path)); |
148 } | 145 } |
149 | 146 |
150 TEST_F(ProfileListDesktopTest, WithOmittedProfiles) { | 147 TEST_F(ProfileListDesktopTest, WithOmittedProfiles) { |
151 ProfileListDesktop profile_list(manager()->profile_info_cache()); | 148 ProfileListDesktop profile_list(manager()->profile_attributes_storage()); |
152 | 149 |
153 // Profiles are stored and listed alphabetically. | 150 // Profiles are stored and listed alphabetically. |
154 AddOmittedProfile("0 omitted"); | 151 AddOmittedProfile("0 omitted"); |
155 manager()->CreateTestingProfile("1 included"); | 152 manager()->CreateTestingProfile("1 included"); |
156 AddOmittedProfile("2 omitted"); | 153 AddOmittedProfile("2 omitted"); |
157 manager()->CreateTestingProfile("3 included"); | 154 manager()->CreateTestingProfile("3 included"); |
158 manager()->CreateTestingProfile("4 included"); | 155 manager()->CreateTestingProfile("4 included"); |
159 AddOmittedProfile("5 omitted"); | 156 AddOmittedProfile("5 omitted"); |
160 manager()->CreateTestingProfile("6 included"); | 157 manager()->CreateTestingProfile("6 included"); |
161 AddOmittedProfile("7 omitted"); | 158 AddOmittedProfile("7 omitted"); |
162 | 159 |
163 profile_list.RebuildMenu(); | 160 profile_list.RebuildMenu(); |
164 ASSERT_EQ(4u, profile_list.GetNumberOfItems()); | 161 ASSERT_EQ(4u, profile_list.GetNumberOfItems()); |
165 | 162 |
166 const AvatarMenu::Item& item1 = profile_list.GetItemAt(0); | 163 const AvatarMenu::Item& item1 = profile_list.GetItemAt(0); |
167 EXPECT_EQ(0u, item1.menu_index); | 164 EXPECT_EQ(0u, item1.menu_index); |
168 EXPECT_EQ(1u, item1.profile_index); | |
169 EXPECT_EQ(ASCIIToUTF16("1 included"), item1.name); | 165 EXPECT_EQ(ASCIIToUTF16("1 included"), item1.name); |
170 | 166 |
171 const AvatarMenu::Item& item2 = profile_list.GetItemAt(1); | 167 const AvatarMenu::Item& item2 = profile_list.GetItemAt(1); |
172 EXPECT_EQ(1u, item2.menu_index); | 168 EXPECT_EQ(1u, item2.menu_index); |
173 EXPECT_EQ(3u, item2.profile_index); | |
174 EXPECT_EQ(ASCIIToUTF16("3 included"), item2.name); | 169 EXPECT_EQ(ASCIIToUTF16("3 included"), item2.name); |
175 | 170 |
176 const AvatarMenu::Item& item3 = profile_list.GetItemAt(2); | 171 const AvatarMenu::Item& item3 = profile_list.GetItemAt(2); |
177 EXPECT_EQ(2u, item3.menu_index); | 172 EXPECT_EQ(2u, item3.menu_index); |
178 EXPECT_EQ(4u, item3.profile_index); | |
179 EXPECT_EQ(ASCIIToUTF16("4 included"), item3.name); | 173 EXPECT_EQ(ASCIIToUTF16("4 included"), item3.name); |
180 | 174 |
181 const AvatarMenu::Item& item4 = profile_list.GetItemAt(3); | 175 const AvatarMenu::Item& item4 = profile_list.GetItemAt(3); |
182 EXPECT_EQ(3u, item4.menu_index); | 176 EXPECT_EQ(3u, item4.menu_index); |
183 EXPECT_EQ(6u, item4.profile_index); | |
184 EXPECT_EQ(ASCIIToUTF16("6 included"), item4.name); | 177 EXPECT_EQ(ASCIIToUTF16("6 included"), item4.name); |
185 | 178 |
186 EXPECT_EQ(0u, profile_list.MenuIndexFromProfileIndex(1)); | 179 EXPECT_EQ(0u, profile_list.MenuIndexFromProfilePath(item1.profile_path)); |
187 EXPECT_EQ(1u, profile_list.MenuIndexFromProfileIndex(3)); | 180 EXPECT_EQ(1u, profile_list.MenuIndexFromProfilePath(item2.profile_path)); |
188 EXPECT_EQ(2u, profile_list.MenuIndexFromProfileIndex(4)); | 181 EXPECT_EQ(2u, profile_list.MenuIndexFromProfilePath(item3.profile_path)); |
189 EXPECT_EQ(3u, profile_list.MenuIndexFromProfileIndex(6)); | 182 EXPECT_EQ(3u, profile_list.MenuIndexFromProfilePath(item4.profile_path)); |
190 } | 183 } |
191 | 184 |
192 TEST_F(ProfileListDesktopTest, ActiveItem) { | 185 TEST_F(ProfileListDesktopTest, ActiveItem) { |
193 manager()->CreateTestingProfile("Test 1"); | 186 manager()->CreateTestingProfile("Test 1"); |
194 manager()->CreateTestingProfile("Test 2"); | 187 manager()->CreateTestingProfile("Test 2"); |
195 | 188 |
196 AvatarMenu* model = GetAvatarMenu(); | 189 AvatarMenu* model = GetAvatarMenu(); |
197 ASSERT_EQ(2U, model->GetNumberOfItems()); | 190 ASSERT_EQ(2U, model->GetNumberOfItems()); |
198 // TODO(jeremy): Expand test to verify active profile index other than 0 | 191 // TODO(jeremy): Expand test to verify active profile index other than 0 |
199 // crbug.com/100871 | 192 // crbug.com/100871 |
(...skipping 16 matching lines...) Expand all Loading... |
216 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 209 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
217 EXPECT_EQ(0U, item1.menu_index); | 210 EXPECT_EQ(0U, item1.menu_index); |
218 EXPECT_EQ(ASCIIToUTF16(name1), item1.name); | 211 EXPECT_EQ(ASCIIToUTF16(name1), item1.name); |
219 | 212 |
220 const AvatarMenu::Item& item2 = model->GetItemAt(1); | 213 const AvatarMenu::Item& item2 = model->GetItemAt(1); |
221 EXPECT_EQ(1U, item2.menu_index); | 214 EXPECT_EQ(1U, item2.menu_index); |
222 EXPECT_EQ(ASCIIToUTF16(name2), item2.name); | 215 EXPECT_EQ(ASCIIToUTF16(name2), item2.name); |
223 | 216 |
224 // Change name of the first profile, to trigger resorting of the profiles: | 217 // Change name of the first profile, to trigger resorting of the profiles: |
225 // now the first model should be named "beta", and the second be "gamma". | 218 // now the first model should be named "beta", and the second be "gamma". |
226 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, | 219 ProfileAttributesStorage* storage = manager()->profile_attributes_storage(); |
227 ASCIIToUTF16(newname1)); | 220 ProfileAttributesEntry* entry; |
| 221 ASSERT_TRUE( |
| 222 storage->GetProfileAttributesWithPath(item1.profile_path, &entry)); |
| 223 entry->SetName(ASCIIToUTF16(newname1)); |
| 224 |
228 const AvatarMenu::Item& item1next = model->GetItemAt(0); | 225 const AvatarMenu::Item& item1next = model->GetItemAt(0); |
229 EXPECT_EQ(1, change_count()); | 226 EXPECT_EQ(1, change_count()); |
230 EXPECT_EQ(0U, item1next.menu_index); | 227 EXPECT_EQ(0U, item1next.menu_index); |
231 EXPECT_EQ(ASCIIToUTF16(name2), item1next.name); | 228 EXPECT_EQ(ASCIIToUTF16(name2), item1next.name); |
232 | 229 |
233 const AvatarMenu::Item& item2next = model->GetItemAt(1); | 230 const AvatarMenu::Item& item2next = model->GetItemAt(1); |
234 EXPECT_EQ(1U, item2next.menu_index); | 231 EXPECT_EQ(1U, item2next.menu_index); |
235 EXPECT_EQ(ASCIIToUTF16(newname1), item2next.name); | 232 EXPECT_EQ(ASCIIToUTF16(newname1), item2next.name); |
236 } | 233 } |
237 | 234 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 326 } |
330 | 327 |
331 TEST_F(ProfileListDesktopTest, SyncState) { | 328 TEST_F(ProfileListDesktopTest, SyncState) { |
332 // If multiprofile mode is not enabled then the menu is never shown. | 329 // If multiprofile mode is not enabled then the menu is never shown. |
333 if (!profiles::IsMultipleProfilesEnabled()) | 330 if (!profiles::IsMultipleProfilesEnabled()) |
334 return; | 331 return; |
335 | 332 |
336 manager()->CreateTestingProfile("Test 1"); | 333 manager()->CreateTestingProfile("Test 1"); |
337 | 334 |
338 // Add a managed user profile. | 335 // Add a managed user profile. |
339 ProfileInfoCache* cache = manager()->profile_info_cache(); | 336 ProfileAttributesStorage* storage = manager()->profile_attributes_storage(); |
340 base::FilePath path = cache->GetUserDataDir().AppendASCII("p2"); | 337 base::FilePath path = storage->GetUserDataDir().AppendASCII("p2"); |
341 cache->AddProfileToCache(path, ASCIIToUTF16("Test 2"), std::string(), | 338 storage->AddProfile(path, ASCIIToUTF16("Test 2"), std::string(), |
342 base::string16(), 0, "TEST_ID"); | 339 base::string16(), 0, "TEST_ID"); |
343 cache->SetIsOmittedProfileAtIndex(cache->GetIndexOfProfileWithPath(path), | 340 ProfileAttributesEntry* entry; |
344 false); | 341 ASSERT_TRUE(storage->GetProfileAttributesWithPath(path, &entry)); |
| 342 entry->SetIsOmitted(false); |
345 | 343 |
346 AvatarMenu* model = GetAvatarMenu(); | 344 AvatarMenu* model = GetAvatarMenu(); |
347 model->RebuildMenu(); | 345 model->RebuildMenu(); |
348 EXPECT_EQ(2U, model->GetNumberOfItems()); | 346 EXPECT_EQ(2U, model->GetNumberOfItems()); |
349 | 347 |
350 // Now check that the username of a supervised user shows the supervised | 348 // Now check that the username of a supervised user shows the supervised |
351 // user avatar label instead. | 349 // user avatar label instead. |
352 base::string16 supervised_user_label = | 350 base::string16 supervised_user_label = |
353 l10n_util::GetStringUTF16(IDS_SUPERVISED_USER_AVATAR_LABEL); | 351 l10n_util::GetStringUTF16(IDS_SUPERVISED_USER_AVATAR_LABEL); |
354 const AvatarMenu::Item& item1 = model->GetItemAt(0); | 352 const AvatarMenu::Item& item1 = model->GetItemAt(0); |
355 EXPECT_NE(item1.username, supervised_user_label); | 353 EXPECT_NE(item1.username, supervised_user_label); |
356 | 354 |
357 const AvatarMenu::Item& item2 = model->GetItemAt(1); | 355 const AvatarMenu::Item& item2 = model->GetItemAt(1); |
358 EXPECT_EQ(item2.username, supervised_user_label); | 356 EXPECT_EQ(item2.username, supervised_user_label); |
359 } | 357 } |
360 | 358 |
361 } // namespace | 359 } // namespace |
OLD | NEW |