Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: trunk/src/chrome/browser/profiles/avatar_menu_model_unittest.cc

Issue 17068004: Revert 207755 "Add device policies to control accessibility sett..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
8 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
9 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/prefs/pref_service_syncable.h"
12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h"
13 #include "chrome/browser/profiles/profile_info_cache.h" 11 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/test/base/testing_browser_process.h" 13 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile_manager.h" 14 #include "chrome/test/base/testing_profile_manager.h"
17 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
18 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
20 18
21 namespace { 19 namespace {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 TestingProfileManager* manager() { return &manager_; } 53 TestingProfileManager* manager() { return &manager_; }
56 54
57 private: 55 private:
58 TestingProfileManager manager_; 56 TestingProfileManager manager_;
59 }; 57 };
60 58
61 TEST_F(AvatarMenuModelTest, InitialCreation) { 59 TEST_F(AvatarMenuModelTest, InitialCreation) {
62 string16 name1(ASCIIToUTF16("Test 1")); 60 string16 name1(ASCIIToUTF16("Test 1"));
63 string16 name2(ASCIIToUTF16("Test 2")); 61 string16 name2(ASCIIToUTF16("Test 2"));
64 62
65 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 63 manager()->CreateTestingProfile("p1", name1, 0);
66 name1, 0); 64 manager()->CreateTestingProfile("p2", name2, 0);
67 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(),
68 name2, 0);
69 65
70 MockObserver observer; 66 MockObserver observer;
71 EXPECT_EQ(0, observer.change_count()); 67 EXPECT_EQ(0, observer.change_count());
72 68
73 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); 69 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
74 EXPECT_EQ(0, observer.change_count()); 70 EXPECT_EQ(0, observer.change_count());
75 71
76 ASSERT_EQ(2U, model.GetNumberOfItems()); 72 ASSERT_EQ(2U, model.GetNumberOfItems());
77 73
78 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); 74 const AvatarMenuModel::Item& item1 = model.GetItemAt(0);
79 EXPECT_EQ(0U, item1.model_index); 75 EXPECT_EQ(0U, item1.model_index);
80 EXPECT_EQ(name1, item1.name); 76 EXPECT_EQ(name1, item1.name);
81 77
82 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); 78 const AvatarMenuModel::Item& item2 = model.GetItemAt(1);
83 EXPECT_EQ(1U, item2.model_index); 79 EXPECT_EQ(1U, item2.model_index);
84 EXPECT_EQ(name2, item2.name); 80 EXPECT_EQ(name2, item2.name);
85 } 81 }
86 82
87 TEST_F(AvatarMenuModelTest, ActiveItem) { 83 TEST_F(AvatarMenuModelTest, ActiveItem) {
88 string16 name1(ASCIIToUTF16("Test 1")); 84 string16 name1(ASCIIToUTF16("Test 1"));
89 string16 name2(ASCIIToUTF16("Test 2")); 85 string16 name2(ASCIIToUTF16("Test 2"));
90 86
91 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 87 manager()->CreateTestingProfile("p1", name1, 0);
92 name1, 0); 88 manager()->CreateTestingProfile("p2", name2, 0);
93 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(),
94 name2, 0);
95 89
96 MockObserver observer; 90 MockObserver observer;
97 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); 91 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
98 ASSERT_EQ(2U, model.GetNumberOfItems()); 92 ASSERT_EQ(2U, model.GetNumberOfItems());
99 // TODO(jeremy): Expand test to verify active profile index other than 0 93 // TODO(jeremy): Expand test to verify active profile index other than 0
100 // crbug.com/100871 94 // crbug.com/100871
101 ASSERT_EQ(0U, model.GetActiveProfileIndex()); 95 ASSERT_EQ(0U, model.GetActiveProfileIndex());
102 } 96 }
103 97
104 TEST_F(AvatarMenuModelTest, ModifyingNameResortsCorrectly) { 98 TEST_F(AvatarMenuModelTest, ModifyingNameResortsCorrectly) {
105 string16 name1(ASCIIToUTF16("Alpha")); 99 string16 name1(ASCIIToUTF16("Alpha"));
106 string16 name2(ASCIIToUTF16("Beta")); 100 string16 name2(ASCIIToUTF16("Beta"));
107 string16 newname1(ASCIIToUTF16("Gamma")); 101 string16 newname1(ASCIIToUTF16("Gamma"));
108 102
109 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 103 manager()->CreateTestingProfile("p1", name1, 0);
110 name1, 0); 104 manager()->CreateTestingProfile("p2", name2, 0);
111 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(),
112 name2, 0);
113 105
114 MockObserver observer; 106 MockObserver observer;
115 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); 107 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
116 EXPECT_EQ(0, observer.change_count()); 108 EXPECT_EQ(0, observer.change_count());
117 109
118 ASSERT_EQ(2U, model.GetNumberOfItems()); 110 ASSERT_EQ(2U, model.GetNumberOfItems());
119 111
120 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); 112 const AvatarMenuModel::Item& item1 = model.GetItemAt(0);
121 EXPECT_EQ(0U, item1.model_index); 113 EXPECT_EQ(0U, item1.model_index);
122 EXPECT_EQ(name1, item1.name); 114 EXPECT_EQ(name1, item1.name);
(...skipping 12 matching lines...) Expand all
135 127
136 const AvatarMenuModel::Item& item2next = model.GetItemAt(1); 128 const AvatarMenuModel::Item& item2next = model.GetItemAt(1);
137 EXPECT_EQ(1U, item2next.model_index); 129 EXPECT_EQ(1U, item2next.model_index);
138 EXPECT_EQ(newname1, item2next.name); 130 EXPECT_EQ(newname1, item2next.name);
139 } 131 }
140 132
141 TEST_F(AvatarMenuModelTest, ChangeOnNotify) { 133 TEST_F(AvatarMenuModelTest, ChangeOnNotify) {
142 string16 name1(ASCIIToUTF16("Test 1")); 134 string16 name1(ASCIIToUTF16("Test 1"));
143 string16 name2(ASCIIToUTF16("Test 2")); 135 string16 name2(ASCIIToUTF16("Test 2"));
144 136
145 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 137 manager()->CreateTestingProfile("p1", name1, 0);
146 name1, 0); 138 manager()->CreateTestingProfile("p2", name2, 0);
147 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(),
148 name2, 0);
149 139
150 MockObserver observer; 140 MockObserver observer;
151 EXPECT_EQ(0, observer.change_count()); 141 EXPECT_EQ(0, observer.change_count());
152 142
153 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); 143 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
154 EXPECT_EQ(0, observer.change_count()); 144 EXPECT_EQ(0, observer.change_count());
155 EXPECT_EQ(2U, model.GetNumberOfItems()); 145 EXPECT_EQ(2U, model.GetNumberOfItems());
156 146
157 string16 name3(ASCIIToUTF16("Test 3")); 147 string16 name3(ASCIIToUTF16("Test 3"));
158 manager()->CreateTestingProfile("p3", scoped_ptr<PrefServiceSyncable>(), 148 manager()->CreateTestingProfile("p3", name3, 0);
159 name3, 0);
160 149
161 // Four changes happened via the call to CreateTestingProfile: adding the 150 // Four changes happened via the call to CreateTestingProfile: adding the
162 // profile to the cache, setting the user name, rebuilding the list of 151 // profile to the cache, setting the user name, rebuilding the list of
163 // profiles after the name change, and changing the avatar. 152 // profiles after the name change, and changing the avatar.
164 // On Windows, an extra change happens to set the shortcut name for the 153 // On Windows, an extra change happens to set the shortcut name for the
165 // profile. 154 // profile.
166 EXPECT_GE(observer.change_count(), 4); 155 EXPECT_GE(observer.change_count(), 4);
167 ASSERT_EQ(3U, model.GetNumberOfItems()); 156 ASSERT_EQ(3U, model.GetNumberOfItems());
168 157
169 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); 158 const AvatarMenuModel::Item& item1 = model.GetItemAt(0);
(...skipping 20 matching lines...) Expand all
190 179
191 #if defined(OS_CHROMEOS) 180 #if defined(OS_CHROMEOS)
192 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); 181 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu());
193 #else 182 #else
194 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); 183 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu());
195 #endif 184 #endif
196 } 185 }
197 186
198 TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) { 187 TEST_F(AvatarMenuModelTest, DontShowAvatarMenu) {
199 string16 name1(ASCIIToUTF16("Test 1")); 188 string16 name1(ASCIIToUTF16("Test 1"));
200 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 189 manager()->CreateTestingProfile("p1", name1, 0);
201 name1, 0);
202 190
203 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); 191 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu());
204 192
205 // If multiprofile mode is enabled, there are no other cases when we wouldn't 193 // If multiprofile mode is enabled, there are no other cases when we wouldn't
206 // show the menu. 194 // show the menu.
207 if (ProfileManager::IsMultipleProfilesEnabled()) 195 if (ProfileManager::IsMultipleProfilesEnabled())
208 return; 196 return;
209 197
210 string16 name2(ASCIIToUTF16("Test 2")); 198 string16 name2(ASCIIToUTF16("Test 2"));
211 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(), 199 manager()->CreateTestingProfile("p2", name2, 0);
212 name2, 0);
213 200
214 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); 201 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu());
215 } 202 }
216 203
217 TEST_F(AvatarMenuModelTest, ShowAvatarMenu) { 204 TEST_F(AvatarMenuModelTest, ShowAvatarMenu) {
218 // If multiprofile mode is not enabled then the menu is never shown. 205 // If multiprofile mode is not enabled then the menu is never shown.
219 if (!ProfileManager::IsMultipleProfilesEnabled()) 206 if (!ProfileManager::IsMultipleProfilesEnabled())
220 return; 207 return;
221 208
222 string16 name1(ASCIIToUTF16("Test 1")); 209 string16 name1(ASCIIToUTF16("Test 1"));
223 string16 name2(ASCIIToUTF16("Test 2")); 210 string16 name2(ASCIIToUTF16("Test 2"));
224 211
225 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 212 manager()->CreateTestingProfile("p1", name1, 0);
226 name1, 0); 213 manager()->CreateTestingProfile("p2", name2, 0);
227 manager()->CreateTestingProfile("p2", scoped_ptr<PrefServiceSyncable>(),
228 name2, 0);
229 214
230 #if defined(OS_CHROMEOS) 215 #if defined(OS_CHROMEOS)
231 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu()); 216 EXPECT_FALSE(AvatarMenuModel::ShouldShowAvatarMenu());
232 #else 217 #else
233 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu()); 218 EXPECT_TRUE(AvatarMenuModel::ShouldShowAvatarMenu());
234 #endif 219 #endif
235 } 220 }
236 221
237 TEST_F(AvatarMenuModelTest, SyncState) { 222 TEST_F(AvatarMenuModelTest, SyncState) {
238 // If multiprofile mode is not enabled then the menu is never shown. 223 // If multiprofile mode is not enabled then the menu is never shown.
239 if (!ProfileManager::IsMultipleProfilesEnabled()) 224 if (!ProfileManager::IsMultipleProfilesEnabled())
240 return; 225 return;
241 226
242 manager()->CreateTestingProfile("p1", scoped_ptr<PrefServiceSyncable>(), 227 manager()->CreateTestingProfile("p1", ASCIIToUTF16("Test 1"), 0);
243 ASCIIToUTF16("Test 1"), 0);
244 228
245 // Add a managed user profile. 229 // Add a managed user profile.
246 ProfileInfoCache* cache = manager()->profile_info_cache(); 230 ProfileInfoCache* cache = manager()->profile_info_cache();
247 manager()->profile_info_cache()->AddProfileToCache( 231 manager()->profile_info_cache()->AddProfileToCache(
248 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"), 232 cache->GetUserDataDir().AppendASCII("p2"), ASCIIToUTF16("Test 2"),
249 string16(), 0, true); 233 string16(), 0, true);
250 MockObserver observer; 234 MockObserver observer;
251 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser()); 235 AvatarMenuModel model(manager()->profile_info_cache(), &observer, browser());
252 EXPECT_EQ(2U, model.GetNumberOfItems()); 236 EXPECT_EQ(2U, model.GetNumberOfItems());
253 237
254 // Now check that the sync_state of a managed user shows the managed user 238 // Now check that the sync_state of a managed user shows the managed user
255 // avatar label instead. 239 // avatar label instead.
256 base::string16 managed_user_label = 240 base::string16 managed_user_label =
257 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL); 241 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL);
258 const AvatarMenuModel::Item& item1 = model.GetItemAt(0); 242 const AvatarMenuModel::Item& item1 = model.GetItemAt(0);
259 EXPECT_NE(item1.sync_state, managed_user_label); 243 EXPECT_NE(item1.sync_state, managed_user_label);
260 244
261 const AvatarMenuModel::Item& item2 = model.GetItemAt(1); 245 const AvatarMenuModel::Item& item2 = model.GetItemAt(1);
262 EXPECT_EQ(item2.sync_state, managed_user_label); 246 EXPECT_EQ(item2.sync_state, managed_user_label);
263 } 247 }
264 248
265 } // namespace 249 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698