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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/prefs/pref_service_syncable.h" | 12 #include "chrome/browser/prefs/pref_service_syncable.h" |
13 #include "chrome/browser/profiles/avatar_menu.h" | 13 #include "chrome/browser/profiles/avatar_menu.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 15 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
18 #include "chrome/browser/signin/signin_header_helper.h" | 18 #include "chrome/browser/signin/signin_header_helper.h" |
19 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 21 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 23 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
24 #include "components/signin/core/browser/signin_manager.h" | 24 #include "components/signin/core/browser/signin_manager.h" |
25 #include "components/signin/core/common/profile_management_switches.h" | |
26 | 25 |
27 const std::string kEmail = "user@gmail.com"; | 26 const std::string kEmail = "user@gmail.com"; |
28 const std::string kSecondaryEmail = "user2@gmail.com"; | 27 const std::string kSecondaryEmail = "user2@gmail.com"; |
29 const std::string kLoginToken = "oauth2_login_token"; | 28 const std::string kLoginToken = "oauth2_login_token"; |
30 | 29 |
31 class ProfileChooserControllerTest : public CocoaProfileTest { | 30 class ProfileChooserControllerTest : public CocoaProfileTest { |
32 public: | 31 public: |
33 ProfileChooserControllerTest() { | 32 ProfileChooserControllerTest() { |
34 } | 33 } |
35 | 34 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 NSRect frame = [test_window() frame]; | 67 NSRect frame = [test_window() frame]; |
69 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 68 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
70 controller_.reset([[ProfileChooserController alloc] | 69 controller_.reset([[ProfileChooserController alloc] |
71 initWithBrowser:browser() | 70 initWithBrowser:browser() |
72 anchoredAt:point | 71 anchoredAt:point |
73 withMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | 72 withMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
74 withServiceType:signin::GAIA_SERVICE_TYPE_NONE]); | 73 withServiceType:signin::GAIA_SERVICE_TYPE_NONE]); |
75 [controller_ showWindow:nil]; | 74 [controller_ showWindow:nil]; |
76 } | 75 } |
77 | 76 |
| 77 void EnableNewProfileManagement() { |
| 78 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 79 switches::kNewProfileManagement); |
| 80 } |
| 81 |
78 void EnableNewAvatarMenuOnly() { | 82 void EnableNewAvatarMenuOnly() { |
79 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNewAvatarMenu); | 83 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNewAvatarMenu); |
80 } | 84 } |
81 | 85 |
82 void EnableFastUserSwitching() { | 86 void EnableFastUserSwitching() { |
83 CommandLine::ForCurrentProcess()->AppendSwitch( | 87 CommandLine::ForCurrentProcess()->AppendSwitch( |
84 switches::kFastUserSwitching); | 88 switches::kFastUserSwitching); |
85 } | 89 } |
86 | 90 |
87 ProfileChooserController* controller() { return controller_; } | 91 ProfileChooserController* controller() { return controller_; } |
88 AvatarMenu* menu() { return menu_; } | 92 AvatarMenu* menu() { return menu_; } |
89 | 93 |
90 private: | 94 private: |
91 base::scoped_nsobject<ProfileChooserController> controller_; | 95 base::scoped_nsobject<ProfileChooserController> controller_; |
92 | 96 |
93 // Weak; owned by |controller_|. | 97 // Weak; owned by |controller_|. |
94 AvatarMenu* menu_; | 98 AvatarMenu* menu_; |
95 | 99 |
96 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 100 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
97 }; | 101 }; |
98 | 102 |
99 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewManagement) { | 103 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewManagement) { |
100 switches::EnableNewProfileManagementForTesting( | 104 EnableNewProfileManagement(); |
101 CommandLine::ForCurrentProcess()); | |
102 StartProfileChooserController(); | 105 StartProfileChooserController(); |
103 | 106 |
104 NSArray* subviews = [[[controller() window] contentView] subviews]; | 107 NSArray* subviews = [[[controller() window] contentView] subviews]; |
105 EXPECT_EQ(1U, [subviews count]); | 108 EXPECT_EQ(1U, [subviews count]); |
106 subviews = [[subviews objectAtIndex:0] subviews]; | 109 subviews = [[subviews objectAtIndex:0] subviews]; |
107 | 110 |
108 // Three profiles means we should have one active card, one separator and | 111 // Three profiles means we should have one active card, one separator and |
109 // one option buttons view. | 112 // one option buttons view. |
110 EXPECT_EQ(3U, [subviews count]); | 113 EXPECT_EQ(3U, [subviews count]); |
111 | 114 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 EXPECT_EQ(1U, [linksSubviews count]); | 194 EXPECT_EQ(1U, [linksSubviews count]); |
192 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 195 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
193 EXPECT_EQ(@selector(showTabbedSigninPage:), [link action]); | 196 EXPECT_EQ(@selector(showTabbedSigninPage:), [link action]); |
194 EXPECT_EQ(controller(), [link target]); | 197 EXPECT_EQ(controller(), [link target]); |
195 | 198 |
196 // There is a tutorial view card at the top. | 199 // There is a tutorial view card at the top. |
197 EXPECT_TRUE([[subviews objectAtIndex:5] isKindOfClass:[NSView class]]); | 200 EXPECT_TRUE([[subviews objectAtIndex:5] isKindOfClass:[NSView class]]); |
198 } | 201 } |
199 | 202 |
200 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 203 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
201 switches::EnableNewProfileManagementForTesting( | 204 EnableNewProfileManagement(); |
202 CommandLine::ForCurrentProcess()); | |
203 EnableFastUserSwitching(); | 205 EnableFastUserSwitching(); |
204 StartProfileChooserController(); | 206 StartProfileChooserController(); |
205 | 207 |
206 NSArray* subviews = [[[controller() window] contentView] subviews]; | 208 NSArray* subviews = [[[controller() window] contentView] subviews]; |
207 EXPECT_EQ(1U, [subviews count]); | 209 EXPECT_EQ(1U, [subviews count]); |
208 subviews = [[subviews objectAtIndex:0] subviews]; | 210 subviews = [[subviews objectAtIndex:0] subviews]; |
209 | 211 |
210 // Three profiles means we should have one active card, two "other" profiles, | 212 // Three profiles means we should have one active card, two "other" profiles, |
211 // each with a separator, and one option buttons view. | 213 // each with a separator, and one option buttons view. |
212 EXPECT_EQ(7U, [subviews count]); | 214 EXPECT_EQ(7U, [subviews count]); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 int sortedNameIndex = 0; | 277 int sortedNameIndex = 0; |
276 for (int i = 7; i >= 0; i -= 2) { | 278 for (int i = 7; i >= 0; i -= 2) { |
277 // The item at index i is the separator. | 279 // The item at index i is the separator. |
278 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); | 280 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
279 EXPECT_TRUE( | 281 EXPECT_TRUE( |
280 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 282 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
281 } | 283 } |
282 } | 284 } |
283 | 285 |
284 TEST_F(ProfileChooserControllerTest, | 286 TEST_F(ProfileChooserControllerTest, |
285 LocalProfileActiveCardLinksWithNewManagement) { | 287 LocalProfileActiveCardLinksWithNewManagement) { |
286 switches::EnableNewProfileManagementForTesting( | 288 EnableNewProfileManagement(); |
287 CommandLine::ForCurrentProcess()); | |
288 StartProfileChooserController(); | 289 StartProfileChooserController(); |
289 NSArray* subviews = [[[controller() window] contentView] subviews]; | 290 NSArray* subviews = [[[controller() window] contentView] subviews]; |
290 EXPECT_EQ(1U, [subviews count]); | 291 EXPECT_EQ(1U, [subviews count]); |
291 subviews = [[subviews objectAtIndex:0] subviews]; | 292 subviews = [[subviews objectAtIndex:0] subviews]; |
292 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 293 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
293 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 294 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
294 | 295 |
295 // There should be one "sign in" link. | 296 // There should be one "sign in" link. |
296 EXPECT_EQ(1U, [activeCardLinks count]); | 297 EXPECT_EQ(1U, [activeCardLinks count]); |
297 NSButton* signinLink = | 298 NSButton* signinLink = |
(...skipping 14 matching lines...) Expand all Loading... |
312 | 313 |
313 // There should be one "sign in" link. | 314 // There should be one "sign in" link. |
314 EXPECT_EQ(1U, [activeCardLinks count]); | 315 EXPECT_EQ(1U, [activeCardLinks count]); |
315 NSButton* signinLink = | 316 NSButton* signinLink = |
316 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 317 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
317 EXPECT_EQ(@selector(showTabbedSigninPage:), [signinLink action]); | 318 EXPECT_EQ(@selector(showTabbedSigninPage:), [signinLink action]); |
318 EXPECT_EQ(controller(), [signinLink target]); | 319 EXPECT_EQ(controller(), [signinLink target]); |
319 } | 320 } |
320 | 321 |
321 TEST_F(ProfileChooserControllerTest, | 322 TEST_F(ProfileChooserControllerTest, |
322 SignedInProfileActiveCardLinksWithNewManagement) { | 323 SignedInProfileActiveCardLinksWithNewManagement) { |
323 switches::EnableNewProfileManagementForTesting( | 324 EnableNewProfileManagement(); |
324 CommandLine::ForCurrentProcess()); | |
325 // Sign in the first profile. | 325 // Sign in the first profile. |
326 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 326 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
327 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 327 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
328 | 328 |
329 StartProfileChooserController(); | 329 StartProfileChooserController(); |
330 NSArray* subviews = [[[controller() window] contentView] subviews]; | 330 NSArray* subviews = [[[controller() window] contentView] subviews]; |
331 EXPECT_EQ(1U, [subviews count]); | 331 EXPECT_EQ(1U, [subviews count]); |
332 subviews = [[subviews objectAtIndex:0] subviews]; | 332 subviews = [[subviews objectAtIndex:0] subviews]; |
333 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 333 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
334 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 334 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
(...skipping 23 matching lines...) Expand all Loading... |
358 // There is one link, without a target and with the user's email. | 358 // There is one link, without a target and with the user's email. |
359 EXPECT_EQ(1U, [activeCardLinks count]); | 359 EXPECT_EQ(1U, [activeCardLinks count]); |
360 NSButton* emailLink = | 360 NSButton* emailLink = |
361 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 361 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
362 EXPECT_EQ(nil, [emailLink action]); | 362 EXPECT_EQ(nil, [emailLink action]); |
363 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailLink title])); | 363 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailLink title])); |
364 EXPECT_EQ(controller(), [emailLink target]); | 364 EXPECT_EQ(controller(), [emailLink target]); |
365 } | 365 } |
366 | 366 |
367 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { | 367 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { |
368 switches::EnableNewProfileManagementForTesting( | 368 EnableNewProfileManagement(); |
369 CommandLine::ForCurrentProcess()); | |
370 // Sign in the first profile. | 369 // Sign in the first profile. |
371 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 370 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
372 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 371 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
373 | 372 |
374 // Set up the signin manager and the OAuth2Tokens. | 373 // Set up the signin manager and the OAuth2Tokens. |
375 Profile* profile = browser()->profile(); | 374 Profile* profile = browser()->profile(); |
376 SigninManagerFactory::GetForProfile(profile)-> | 375 SigninManagerFactory::GetForProfile(profile)-> |
377 SetAuthenticatedUsername(kEmail); | 376 SetAuthenticatedUsername(kEmail); |
378 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 377 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
379 UpdateCredentials(kEmail, kLoginToken); | 378 UpdateCredentials(kEmail, kLoginToken); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 454 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
456 [static_cast<NSButton*>(activeProfileName) title])); | 455 [static_cast<NSButton*>(activeProfileName) title])); |
457 | 456 |
458 // Profile links. This is a local profile, so there should be a signin button. | 457 // Profile links. This is a local profile, so there should be a signin button. |
459 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 458 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
460 EXPECT_EQ(1U, [linksSubviews count]); | 459 EXPECT_EQ(1U, [linksSubviews count]); |
461 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 460 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
462 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 461 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
463 EXPECT_EQ(controller(), [link target]); | 462 EXPECT_EQ(controller(), [link target]); |
464 } | 463 } |
OLD | NEW |