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