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

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

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

Powered by Google App Engine
This is Rietveld 408576698