OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void StartProfileChooserController() { | 68 void StartProfileChooserController() { |
69 NSRect frame = [test_window() frame]; | 69 NSRect frame = [test_window() frame]; |
70 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 70 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
71 controller_.reset([[ProfileChooserController alloc] | 71 controller_.reset([[ProfileChooserController alloc] |
72 initWithBrowser:browser() | 72 initWithBrowser:browser() |
73 anchoredAt:point | 73 anchoredAt:point |
74 withMode:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]); | 74 withMode:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]); |
75 [controller_ showWindow:nil]; | 75 [controller_ showWindow:nil]; |
76 } | 76 } |
77 | 77 |
| 78 void EnableNewProfileManagement() { |
| 79 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 80 switches::kNewProfileManagement); |
| 81 } |
| 82 |
| 83 void EnableNewAvatarMenuOnly() { |
| 84 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNewAvatarMenu); |
| 85 } |
| 86 |
| 87 void EnableFastUserSwitching() { |
| 88 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 89 switches::kFastUserSwitching); |
| 90 } |
| 91 |
78 ProfileChooserController* controller() { return controller_; } | 92 ProfileChooserController* controller() { return controller_; } |
79 AvatarMenu* menu() { return menu_; } | 93 AvatarMenu* menu() { return menu_; } |
80 | 94 |
81 private: | 95 private: |
82 base::scoped_nsobject<ProfileChooserController> controller_; | 96 base::scoped_nsobject<ProfileChooserController> controller_; |
83 | 97 |
84 // Weak; owned by |controller_|. | 98 // Weak; owned by |controller_|. |
85 AvatarMenu* menu_; | 99 AvatarMenu* menu_; |
86 | 100 |
87 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 101 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
88 }; | 102 }; |
89 | 103 |
90 TEST_F(ProfileChooserControllerTest, InitialLayout) { | 104 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewManagement) { |
| 105 EnableNewProfileManagement(); |
91 StartProfileChooserController(); | 106 StartProfileChooserController(); |
| 107 |
92 NSArray* subviews = [[[controller() window] contentView] subviews]; | 108 NSArray* subviews = [[[controller() window] contentView] subviews]; |
93 | 109 |
94 // Three profiles means we should have one active card, one separator and | 110 // Three profiles means we should have one active card, one separator and |
95 // one option buttons view. | 111 // one option buttons view. |
96 EXPECT_EQ(3U, [subviews count]); | 112 EXPECT_EQ(3U, [subviews count]); |
97 | 113 |
98 // For a local profile, there should be one button in the option buttons view. | 114 // For a local profile, there should be one button in the option buttons view. |
99 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 115 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
100 EXPECT_EQ(1U, [buttonSubviews count]); | 116 EXPECT_EQ(1U, [buttonSubviews count]); |
101 NSButton* button = static_cast<NSButton*>([buttonSubviews objectAtIndex:0]); | 117 NSButton* button = static_cast<NSButton*>([buttonSubviews objectAtIndex:0]); |
102 EXPECT_EQ(@selector(showUserManager:), [button action]); | 118 EXPECT_EQ(@selector(showUserManager:), [button action]); |
103 EXPECT_EQ(controller(), [button target]); | 119 EXPECT_EQ(controller(), [button target]); |
104 | 120 |
105 // There should be a separator. | 121 // There should be a separator. |
106 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 122 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
107 | 123 |
108 // There should be the profile avatar, name and links container in the active | 124 // There should be the profile avatar, name and links container in the active |
109 // card view. The links displayed in the container are checked separately. | 125 // card view. The links displayed in the container are checked separately. |
110 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 126 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
111 EXPECT_EQ(3U, [activeCardSubviews count]); | 127 EXPECT_EQ(3U, [activeCardSubviews count]); |
112 | 128 |
113 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:0]; | 129 // Profile icon. |
| 130 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
114 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); | 131 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
115 | 132 |
116 // There are some links in between. The profile name is added last. | 133 // Profile name. |
117 CGFloat index = [activeCardSubviews count] - 1; | 134 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
118 NSView* activeProfileName = [activeCardSubviews objectAtIndex:index]; | |
119 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 135 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
120 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 136 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
121 [static_cast<NSButton*>(activeProfileName) title])); | 137 [static_cast<NSButton*>(activeProfileName) title])); |
| 138 |
| 139 // Profile links. This is a local profile, so there should be a signin button. |
| 140 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 141 EXPECT_EQ(1U, [linksSubviews count]); |
| 142 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 143 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 144 EXPECT_EQ(controller(), [link target]); |
| 145 } |
| 146 |
| 147 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 148 EnableNewAvatarMenuOnly(); |
| 149 StartProfileChooserController(); |
| 150 |
| 151 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 152 |
| 153 // Three profiles means we should have one active card and a |
| 154 // fast user switcher which has two "other" profiles and 2 separators. |
| 155 EXPECT_EQ(5U, [subviews count]); |
| 156 |
| 157 // There should be two "other profiles" items. The items are drawn from the |
| 158 // bottom up, so in the opposite order of those in the AvatarMenu. |
| 159 int profileIndex = 1; |
| 160 for (int i = 3; i >= 0; i -= 2) { |
| 161 // Each profile button has a separator. |
| 162 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); |
| 163 |
| 164 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
| 165 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, |
| 166 base::SysNSStringToUTF16([button title])); |
| 167 EXPECT_EQ(profileIndex, [button tag]); |
| 168 EXPECT_EQ(@selector(switchToProfile:), [button action]); |
| 169 EXPECT_EQ(controller(), [button target]); |
| 170 profileIndex++; |
| 171 } |
| 172 |
| 173 // There should be the profile avatar, name and links container in the active |
| 174 // card view. The links displayed in the container are checked separately. |
| 175 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
| 176 EXPECT_EQ(3U, [activeCardSubviews count]); |
| 177 |
| 178 // Profile icon. |
| 179 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
| 180 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
| 181 |
| 182 // Profile name. |
| 183 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
| 184 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 185 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 186 [static_cast<NSButton*>(activeProfileName) title])); |
| 187 |
| 188 // Profile links. This is a local profile, so there should be a signin button. |
| 189 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 190 EXPECT_EQ(1U, [linksSubviews count]); |
| 191 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 192 EXPECT_EQ(@selector(showTabbedSigninPage:), [link action]); |
| 193 EXPECT_EQ(controller(), [link target]); |
122 } | 194 } |
123 | 195 |
124 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 196 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
125 // The fast user switcher is only availbale behind a flag. | 197 EnableNewProfileManagement(); |
126 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kFastUserSwitching); | 198 EnableFastUserSwitching(); |
| 199 StartProfileChooserController(); |
127 | 200 |
128 StartProfileChooserController(); | |
129 NSArray* subviews = [[[controller() window] contentView] subviews]; | 201 NSArray* subviews = [[[controller() window] contentView] subviews]; |
130 | 202 |
131 // Three profiles means we should have one active card, two "other" profiles, | 203 // Three profiles means we should have one active card, two "other" profiles, |
132 // one separator and one option buttons view. | 204 // each with a separator, and one option buttons view. |
133 EXPECT_EQ(5U, [subviews count]); | 205 EXPECT_EQ(7U, [subviews count]); |
134 | 206 |
135 // For a local profile, there should be one button in the option buttons view. | 207 // For a local profile, there should be one button in the option buttons view. |
136 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; | 208 NSArray* buttonSubviews = [[subviews objectAtIndex:0] subviews]; |
137 EXPECT_EQ(1U, [buttonSubviews count]); | 209 EXPECT_EQ(1U, [buttonSubviews count]); |
138 NSButton* button = static_cast<NSButton*>([buttonSubviews objectAtIndex:0]); | 210 NSButton* button = static_cast<NSButton*>([buttonSubviews objectAtIndex:0]); |
139 EXPECT_EQ(@selector(showUserManager:), [button action]); | 211 EXPECT_EQ(@selector(showUserManager:), [button action]); |
140 EXPECT_EQ(controller(), [button target]); | 212 EXPECT_EQ(controller(), [button target]); |
141 | 213 |
142 // There should be a separator. | 214 // There should be a separator. |
143 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); | 215 EXPECT_TRUE([[subviews objectAtIndex:1] isKindOfClass:[NSBox class]]); |
144 | 216 |
145 // There should be two "other profiles" items. The items are drawn from the | 217 // There should be two "other profiles" items. The items are drawn from the |
146 // bottom up, so in the opposite order of those in the AvatarMenu. | 218 // bottom up, so in the opposite order of those in the AvatarMenu. |
147 int profileIndex = 1; | 219 int profileIndex = 1; |
148 for (NSUInteger i = 3; i >= 2; --i) { | 220 for (int i = 5; i >= 2; i -= 2) { |
149 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i]); | 221 // Each profile button has a separator. |
| 222 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); |
| 223 |
| 224 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
150 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, | 225 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, |
151 base::SysNSStringToUTF16([button title])); | 226 base::SysNSStringToUTF16([button title])); |
152 EXPECT_EQ(profileIndex, [button tag]); | 227 EXPECT_EQ(profileIndex, [button tag]); |
153 EXPECT_EQ(@selector(switchToProfile:), [button action]); | 228 EXPECT_EQ(@selector(switchToProfile:), [button action]); |
154 EXPECT_EQ(controller(), [button target]); | 229 EXPECT_EQ(controller(), [button target]); |
155 profileIndex++; | 230 profileIndex++; |
156 } | 231 } |
157 | 232 |
158 // There should be the profile avatar, name and links container in the active | 233 // There should be the profile avatar, name and links container in the active |
159 // card view. The links displayed in the container are checked separately. | 234 // card view. These have been checked separately. |
160 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; | 235 NSArray* activeCardSubviews = [[subviews objectAtIndex:6] subviews]; |
161 EXPECT_EQ(3U, [activeCardSubviews count]); | 236 EXPECT_EQ(3U, [activeCardSubviews count]); |
162 | |
163 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:0]; | |
164 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); | |
165 | |
166 // There are some links in between. The profile name is added last. | |
167 CGFloat index = [activeCardSubviews count] - 1; | |
168 NSView* activeProfileName = [activeCardSubviews objectAtIndex:index]; | |
169 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | |
170 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | |
171 [static_cast<NSButton*>(activeProfileName) title])); | |
172 } | 237 } |
173 | 238 |
174 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 239 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
175 // The fast user switcher is only availbale behind a flag. | 240 EnableNewAvatarMenuOnly(); |
176 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kFastUserSwitching); | |
177 | 241 |
178 // Add two extra profiles, to make sure sorting is alphabetical and not | 242 // Add two extra profiles, to make sure sorting is alphabetical and not |
179 // by order of creation. | 243 // by order of creation. |
180 testing_profile_manager()-> | 244 testing_profile_manager()-> |
181 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), | 245 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), |
182 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 246 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
183 TestingProfile::TestingFactories()); | 247 TestingProfile::TestingFactories()); |
184 testing_profile_manager()-> | 248 testing_profile_manager()-> |
185 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), | 249 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), |
186 base::ASCIIToUTF16("Another Test"), 1, std::string(), | 250 base::ASCIIToUTF16("Another Test"), 1, std::string(), |
187 TestingProfile::TestingFactories()); | 251 TestingProfile::TestingFactories()); |
188 StartProfileChooserController(); | 252 StartProfileChooserController(); |
189 | 253 |
190 NSArray* subviews = [[[controller() window] contentView] subviews]; | 254 NSArray* subviews = [[[controller() window] contentView] subviews]; |
191 NSString* sortedNames[] = { @"Another Test", | 255 NSString* sortedNames[] = { @"Another Test", |
192 @"New Profile", | 256 @"New Profile", |
193 @"Test 1", | 257 @"Test 1", |
194 @"Test 2" }; | 258 @"Test 2" }; |
195 // There should be three "other profiles" items, sorted alphabetically. | 259 EXPECT_EQ(9U, [subviews count]); |
196 // The "other profiles" start at index 2, after the option buttons and | 260 // There should be four "other profiles" items, sorted alphabetically. |
197 // a separator. We need to iterate through the profiles in the order | 261 // The "other profiles" start at index 0, and each have a separator. We |
198 // displayed in the bubble, which is opposite from the drawn order. | 262 // need to iterate through the profiles in the order displayed in the bubble, |
| 263 // which is opposite from the drawn order. |
199 int sortedNameIndex = 0; | 264 int sortedNameIndex = 0; |
200 for (NSUInteger i = 5; i >= 2; --i) { | 265 for (int i = 7; i >= 0; i -= 2) { |
201 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i]); | 266 // The item at index i is the separator. |
| 267 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
202 EXPECT_TRUE( | 268 EXPECT_TRUE( |
203 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 269 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
204 } | 270 } |
205 } | 271 } |
206 | 272 |
207 TEST_F(ProfileChooserControllerTest, LocalProfileActiveCardLinks) { | 273 TEST_F(ProfileChooserControllerTest, |
| 274 LocalProfileActiveCardLinksWithNewManagement) { |
| 275 EnableNewProfileManagement(); |
208 StartProfileChooserController(); | 276 StartProfileChooserController(); |
209 NSArray* subviews = [[[controller() window] contentView] subviews]; | 277 NSArray* subviews = [[[controller() window] contentView] subviews]; |
210 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 278 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
211 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:1] subviews]; | 279 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
212 | 280 |
213 // There should be one "sign in" link. | 281 // There should be one "sign in" link. |
214 EXPECT_EQ(1U, [activeCardLinks count]); | 282 EXPECT_EQ(1U, [activeCardLinks count]); |
215 NSButton* signinLink = | 283 NSButton* signinLink = |
216 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 284 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
217 EXPECT_EQ(@selector(showSigninPage:), [signinLink action]); | 285 EXPECT_EQ(@selector(showInlineSigninPage:), [signinLink action]); |
218 EXPECT_EQ(controller(), [signinLink target]); | 286 EXPECT_EQ(controller(), [signinLink target]); |
219 } | 287 } |
220 | 288 |
221 TEST_F(ProfileChooserControllerTest, SignedInProfileActiveCardLinks) { | 289 TEST_F(ProfileChooserControllerTest, |
| 290 LocalProfileActiveCardLinksWithNewMenu) { |
| 291 EnableNewAvatarMenuOnly(); |
| 292 StartProfileChooserController(); |
| 293 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 294 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
| 295 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 296 |
| 297 // There should be one "sign in" link. |
| 298 EXPECT_EQ(1U, [activeCardLinks count]); |
| 299 NSButton* signinLink = |
| 300 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
| 301 EXPECT_EQ(@selector(showTabbedSigninPage:), [signinLink action]); |
| 302 EXPECT_EQ(controller(), [signinLink target]); |
| 303 } |
| 304 |
| 305 TEST_F(ProfileChooserControllerTest, |
| 306 SignedInProfileActiveCardLinksWithNewManagement) { |
| 307 EnableNewProfileManagement(); |
222 // Sign in the first profile. | 308 // Sign in the first profile. |
223 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 309 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
224 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 310 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
225 | 311 |
226 StartProfileChooserController(); | 312 StartProfileChooserController(); |
227 NSArray* subviews = [[[controller() window] contentView] subviews]; | 313 NSArray* subviews = [[[controller() window] contentView] subviews]; |
228 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 314 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
229 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:1] subviews]; | 315 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
230 | 316 |
231 // There is one link: manage accounts. | 317 // There is one link: manage accounts. |
232 EXPECT_EQ(1U, [activeCardLinks count]); | 318 EXPECT_EQ(1U, [activeCardLinks count]); |
233 NSButton* manageAccountsLink = | 319 NSButton* manageAccountsLink = |
234 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 320 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
235 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 321 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
236 EXPECT_EQ(controller(), [manageAccountsLink target]); | 322 EXPECT_EQ(controller(), [manageAccountsLink target]); |
237 } | 323 } |
238 | 324 |
239 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { | 325 TEST_F(ProfileChooserControllerTest, |
| 326 SignedInProfileActiveCardLinksWithNewMenu) { |
| 327 EnableNewAvatarMenuOnly(); |
240 // Sign in the first profile. | 328 // Sign in the first profile. |
241 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 329 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
242 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 330 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 331 |
| 332 StartProfileChooserController(); |
| 333 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 334 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
| 335 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 336 |
| 337 // There is one link, without a target and with the user's email. |
| 338 EXPECT_EQ(1U, [activeCardLinks count]); |
| 339 NSButton* emailLink = |
| 340 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
| 341 EXPECT_EQ(nil, [emailLink action]); |
| 342 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailLink title])); |
| 343 EXPECT_EQ(controller(), [emailLink target]); |
| 344 } |
| 345 |
| 346 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { |
| 347 EnableNewProfileManagement(); |
| 348 // Sign in the first profile. |
| 349 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 350 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
243 | 351 |
244 // Set up the signin manager and the OAuth2Tokens. | 352 // Set up the signin manager and the OAuth2Tokens. |
245 Profile* profile = browser()->profile(); | 353 Profile* profile = browser()->profile(); |
246 SigninManagerFactory::GetForProfile(profile)-> | 354 SigninManagerFactory::GetForProfile(profile)-> |
247 SetAuthenticatedUsername(kEmail); | 355 SetAuthenticatedUsername(kEmail); |
248 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 356 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
249 UpdateCredentials(kEmail, kLoginToken); | 357 UpdateCredentials(kEmail, kLoginToken); |
250 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 358 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
251 UpdateCredentials(kSecondaryEmail, kLoginToken); | 359 UpdateCredentials(kSecondaryEmail, kLoginToken); |
252 | 360 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 EXPECT_EQ(controller(), [addAccountsButton target]); | 392 EXPECT_EQ(controller(), [addAccountsButton target]); |
285 | 393 |
286 // There should be two accounts in the account list container. | 394 // There should be two accounts in the account list container. |
287 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews]; | 395 NSArray* accountsListSubviews = [[accountsSubviews objectAtIndex:1] subviews]; |
288 EXPECT_EQ(2U, [accountsListSubviews count]); | 396 EXPECT_EQ(2U, [accountsListSubviews count]); |
289 | 397 |
290 NSButton* genericAccount = | 398 NSButton* genericAccount = |
291 static_cast<NSButton*>([accountsListSubviews objectAtIndex:0]); | 399 static_cast<NSButton*>([accountsListSubviews objectAtIndex:0]); |
292 EXPECT_EQ(@selector(showAccountRemovalView:), [genericAccount action]); | 400 EXPECT_EQ(@selector(showAccountRemovalView:), [genericAccount action]); |
293 EXPECT_EQ(controller(), [genericAccount target]); | 401 EXPECT_EQ(controller(), [genericAccount target]); |
| 402 EXPECT_NE(-1, [genericAccount tag]); |
294 | 403 |
295 // Primary accounts are always last. | 404 // Primary accounts are always last. |
296 NSButton* primaryAccount = | 405 NSButton* primaryAccount = |
297 static_cast<NSButton*>([accountsListSubviews objectAtIndex:1]); | 406 static_cast<NSButton*>([accountsListSubviews objectAtIndex:1]); |
298 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccount action]); | 407 EXPECT_EQ(@selector(showAccountRemovalView:), [primaryAccount action]); |
299 EXPECT_EQ(controller(), [primaryAccount target]); | 408 EXPECT_EQ(controller(), [primaryAccount target]); |
| 409 EXPECT_EQ(-1, [primaryAccount tag]); |
300 | 410 |
301 // There should be another separator. | 411 // There should be another separator. |
302 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); | 412 EXPECT_TRUE([[subviews objectAtIndex:3] isKindOfClass:[NSBox class]]); |
303 | 413 |
304 // There should be the profile avatar, name and no links container in the | 414 // There should be the profile avatar, name and a "hide accounts" link |
305 // active card view. | 415 // container in the active card view. |
306 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; | 416 NSArray* activeCardSubviews = [[subviews objectAtIndex:4] subviews]; |
307 EXPECT_EQ(2U, [activeCardSubviews count]); | 417 EXPECT_EQ(3U, [activeCardSubviews count]); |
308 | 418 |
309 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:0]; | 419 // Profile icon. |
| 420 NSView* activeProfileImage = [activeCardSubviews objectAtIndex:2]; |
310 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); | 421 EXPECT_TRUE([activeProfileImage isKindOfClass:[NSImageView class]]); |
311 | 422 |
| 423 // Profile name. |
312 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; | 424 NSView* activeProfileName = [activeCardSubviews objectAtIndex:1]; |
313 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 425 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
314 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 426 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
315 [static_cast<NSButton*>(activeProfileName) title])); | 427 [static_cast<NSButton*>(activeProfileName) title])); |
| 428 |
| 429 // Profile links. This is a local profile, so there should be a signin button. |
| 430 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 431 EXPECT_EQ(1U, [linksSubviews count]); |
| 432 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 433 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
| 434 EXPECT_EQ(controller(), [link target]); |
316 } | 435 } |
OLD | NEW |