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