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/avatar_menu_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 name2, 0); | 68 name2, 0); |
69 | 69 |
70 MockObserver observer; | 70 MockObserver observer; |
71 EXPECT_EQ(0, observer.change_count()); | 71 EXPECT_EQ(0, observer.change_count()); |
72 | 72 |
73 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); | 73 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); |
74 EXPECT_EQ(0, observer.change_count()); | 74 EXPECT_EQ(0, observer.change_count()); |
75 | 75 |
76 ASSERT_EQ(2U, model.GetNumberOfItems()); | 76 ASSERT_EQ(2U, model.GetNumberOfItems()); |
77 | 77 |
78 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); | 78 const ui::AvatarMenuItemModel& item1 = model.GetItemAt(0); |
79 EXPECT_EQ(0U, item1.model_index); | 79 EXPECT_EQ(0U, item1.model_index); |
80 EXPECT_EQ(name1, item1.name); | 80 EXPECT_EQ(name1, item1.name); |
81 | 81 |
82 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 82 const ui::AvatarMenuItemModel& item2 = model.GetItemAt(1); |
83 EXPECT_EQ(1U, item2.model_index); | 83 EXPECT_EQ(1U, item2.model_index); |
84 EXPECT_EQ(name2, item2.name); | 84 EXPECT_EQ(name2, item2.name); |
85 } | 85 } |
86 | 86 |
87 TEST_F(AvatarMenuModelTest, ActiveItem) { | 87 TEST_F(AvatarMenuModelTest, ActiveItem) { |
88 string16 name1(ASCIIToUTF16("Test 1")); | 88 string16 name1(ASCIIToUTF16("Test 1")); |
89 string16 name2(ASCIIToUTF16("Test 2")); | 89 string16 name2(ASCIIToUTF16("Test 2")); |
90 | 90 |
91 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 91 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
92 name1, 0); | 92 name1, 0); |
(...skipping 17 matching lines...) Expand all Loading... |
110 name1, 0); | 110 name1, 0); |
111 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), | 111 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), |
112 name2, 0); | 112 name2, 0); |
113 | 113 |
114 MockObserver observer; | 114 MockObserver observer; |
115 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); | 115 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); |
116 EXPECT_EQ(0, observer.change_count()); | 116 EXPECT_EQ(0, observer.change_count()); |
117 | 117 |
118 ASSERT_EQ(2U, model.GetNumberOfItems()); | 118 ASSERT_EQ(2U, model.GetNumberOfItems()); |
119 | 119 |
120 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); | 120 const ui::AvatarMenuItemModel& item1 = model.GetItemAt(0); |
121 EXPECT_EQ(0U, item1.model_index); | 121 EXPECT_EQ(0U, item1.model_index); |
122 EXPECT_EQ(name1, item1.name); | 122 EXPECT_EQ(name1, item1.name); |
123 | 123 |
124 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 124 const ui::AvatarMenuItemModel& item2 = model.GetItemAt(1); |
125 EXPECT_EQ(1U, item2.model_index); | 125 EXPECT_EQ(1U, item2.model_index); |
126 EXPECT_EQ(name2, item2.name); | 126 EXPECT_EQ(name2, item2.name); |
127 | 127 |
128 // Change name of the first profile, to trigger resorting of the profiles: | 128 // Change name of the first profile, to trigger resorting of the profiles: |
129 // now the first model should be named "beta", and the second be "gamma". | 129 // now the first model should be named "beta", and the second be "gamma". |
130 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); | 130 manager()->profile_info_cache()->SetNameOfProfileAtIndex(0, newname1); |
131 const AvatarMenuModel::Item& item1next = model.GetItemAt(0); | 131 const ui::AvatarMenuItemModel& item1next = model.GetItemAt(0); |
132 EXPECT_GT(observer.change_count(), 1); | 132 EXPECT_GT(observer.change_count(), 1); |
133 EXPECT_EQ(0U, item1next.model_index); | 133 EXPECT_EQ(0U, item1next.model_index); |
134 EXPECT_EQ(name2, item1next.name); | 134 EXPECT_EQ(name2, item1next.name); |
135 | 135 |
136 const AvatarMenuModel::Item& item2next = model.GetItemAt(1); | 136 const ui::AvatarMenuItemModel& item2next = model.GetItemAt(1); |
137 EXPECT_EQ(1U, item2next.model_index); | 137 EXPECT_EQ(1U, item2next.model_index); |
138 EXPECT_EQ(newname1, item2next.name); | 138 EXPECT_EQ(newname1, item2next.name); |
139 } | 139 } |
140 | 140 |
141 TEST_F(AvatarMenuModelTest, ChangeOnNotify) { | 141 TEST_F(AvatarMenuModelTest, ChangeOnNotify) { |
142 string16 name1(ASCIIToUTF16("Test 1")); | 142 string16 name1(ASCIIToUTF16("Test 1")); |
143 string16 name2(ASCIIToUTF16("Test 2")); | 143 string16 name2(ASCIIToUTF16("Test 2")); |
144 | 144 |
145 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), | 145 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), |
146 name1, 0); | 146 name1, 0); |
(...skipping 12 matching lines...) Expand all Loading... |
159 name3, 0); | 159 name3, 0); |
160 | 160 |
161 // Four changes happened via the call to CreateTestingProfile: adding the | 161 // Four changes happened via the call to CreateTestingProfile: adding the |
162 // profile to the cache, setting the user name, rebuilding the list of | 162 // profile to the cache, setting the user name, rebuilding the list of |
163 // profiles after the name change, and changing the avatar. | 163 // profiles after the name change, and changing the avatar. |
164 // On Windows, an extra change happens to set the shortcut name for the | 164 // On Windows, an extra change happens to set the shortcut name for the |
165 // profile. | 165 // profile. |
166 EXPECT_GE(observer.change_count(), 4); | 166 EXPECT_GE(observer.change_count(), 4); |
167 ASSERT_EQ(3U, model.GetNumberOfItems()); | 167 ASSERT_EQ(3U, model.GetNumberOfItems()); |
168 | 168 |
169 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); | 169 const ui::AvatarMenuItemModel& item1 = model.GetItemAt(0); |
170 EXPECT_EQ(0U, item1.model_index); | 170 EXPECT_EQ(0U, item1.model_index); |
171 EXPECT_EQ(name1, item1.name); | 171 EXPECT_EQ(name1, item1.name); |
172 | 172 |
173 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 173 const ui::AvatarMenuItemModel& item2 = model.GetItemAt(1); |
174 EXPECT_EQ(1U, item2.model_index); | 174 EXPECT_EQ(1U, item2.model_index); |
175 EXPECT_EQ(name2, item2.name); | 175 EXPECT_EQ(name2, item2.name); |
176 | 176 |
177 const AvatarMenuModel::Item& item3 = model.GetItemAt(2); | 177 const ui::AvatarMenuItemModel& item3 = model.GetItemAt(2); |
178 EXPECT_EQ(2U, item3.model_index); | 178 EXPECT_EQ(2U, item3.model_index); |
179 EXPECT_EQ(name3, item3.name); | 179 EXPECT_EQ(name3, item3.name); |
180 } | 180 } |
181 | 181 |
182 TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { | 182 TEST_F(AvatarMenuModelTest, ShowAvatarMenuInTrial) { |
183 // If multiprofile mode is not enabled, the trial will not be enabled, so it | 183 // If multiprofile mode is not enabled, the trial will not be enabled, so it |
184 // isn't tested. | 184 // isn't tested. |
185 if (!profiles::IsMultipleProfilesEnabled()) | 185 if (!profiles::IsMultipleProfilesEnabled()) |
186 return; | 186 return; |
187 | 187 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), | 248 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), |
249 string16(), 0, true); | 249 string16(), 0, true); |
250 MockObserver observer; | 250 MockObserver observer; |
251 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); | 251 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); |
252 EXPECT_EQ(2U, model.GetNumberOfItems()); | 252 EXPECT_EQ(2U, model.GetNumberOfItems()); |
253 | 253 |
254 // Now check that the sync_state of a managed user shows the managed user | 254 // Now check that the sync_state of a managed user shows the managed user |
255 // avatar label instead. | 255 // avatar label instead. |
256 base::string16 managed_user_label = | 256 base::string16 managed_user_label = |
257 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); | 257 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); |
258 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); | 258 const ui::AvatarMenuItemModel& item1 = model.GetItemAt(0); |
259 EXPECT_NE(item1.sync_state, managed_user_label); | 259 EXPECT_NE(item1.sync_state, managed_user_label); |
260 | 260 |
261 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); | 261 const ui::AvatarMenuItemModel& item2 = model.GetItemAt(1); |
262 EXPECT_EQ(item2.sync_state, managed_user_label); | 262 EXPECT_EQ(item2.sync_state, managed_user_label); |
263 } | 263 } |
264 | 264 |
265 } // namespace | 265 } // namespace |
OLD | NEW |