| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { | 145 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 146 EnableNewAvatarMenuOnly(); | 146 EnableNewAvatarMenuOnly(); |
| 147 StartProfileChooserController(); | 147 StartProfileChooserController(); |
| 148 | 148 |
| 149 NSArray* subviews = [[[controller() window] contentView] subviews]; | 149 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 150 EXPECT_EQ(1U, [subviews count]); | 150 EXPECT_EQ(1U, [subviews count]); |
| 151 subviews = [[subviews objectAtIndex:0] subviews]; | 151 subviews = [[subviews objectAtIndex:0] subviews]; |
| 152 | 152 |
| 153 // Three profiles means we should have one active card and a | 153 // Three profiles means we should have one active card and a |
| 154 // fast user switcher which has two "other" profiles and 2 separators. In | 154 // fast user switcher which has two "other" profiles and 2 separators. |
| 155 // this flow we also have the tutorial view. | 155 EXPECT_EQ(5U, [subviews count]); |
| 156 EXPECT_EQ(6U, [subviews count]); | |
| 157 | 156 |
| 158 // There should be two "other profiles" items. The items are drawn from the | 157 // There should be two "other profiles" items. The items are drawn from the |
| 159 // bottom up, so in the opposite order of those in the AvatarMenu. | 158 // bottom up, so in the opposite order of those in the AvatarMenu. |
| 160 int profileIndex = 1; | 159 int profileIndex = 1; |
| 161 for (int i = 3; i >= 0; i -= 2) { | 160 for (int i = 3; i >= 0; i -= 2) { |
| 162 // Each profile button has a separator. | 161 // Each profile button has a separator. |
| 163 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); | 162 EXPECT_TRUE([[subviews objectAtIndex:i] isKindOfClass:[NSBox class]]); |
| 164 | 163 |
| 165 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); | 164 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
| 166 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, | 165 EXPECT_EQ(menu()->GetItemAt(profileIndex).name, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 185 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); | 184 EXPECT_TRUE([activeProfileName isKindOfClass:[NSButton class]]); |
| 186 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 185 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 187 [static_cast<NSButton*>(activeProfileName) title])); | 186 [static_cast<NSButton*>(activeProfileName) title])); |
| 188 | 187 |
| 189 // Profile links. This is a local profile, so there should be a signin button. | 188 // Profile links. This is a local profile, so there should be a signin button. |
| 190 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 189 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 191 EXPECT_EQ(1U, [linksSubviews count]); | 190 EXPECT_EQ(1U, [linksSubviews count]); |
| 192 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 191 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 193 EXPECT_EQ(@selector(showTabbedSigninPage:), [link action]); | 192 EXPECT_EQ(@selector(showTabbedSigninPage:), [link action]); |
| 194 EXPECT_EQ(controller(), [link target]); | 193 EXPECT_EQ(controller(), [link target]); |
| 195 | |
| 196 // There is a tutorial view card at the top. | |
| 197 EXPECT_TRUE([[subviews objectAtIndex:5] isKindOfClass:[NSView class]]); | |
| 198 } | 194 } |
| 199 | 195 |
| 200 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 196 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
| 201 switches::EnableNewProfileManagementForTesting( | 197 switches::EnableNewProfileManagementForTesting( |
| 202 CommandLine::ForCurrentProcess()); | 198 CommandLine::ForCurrentProcess()); |
| 203 EnableFastUserSwitching(); | 199 EnableFastUserSwitching(); |
| 204 StartProfileChooserController(); | 200 StartProfileChooserController(); |
| 205 | 201 |
| 206 NSArray* subviews = [[[controller() window] contentView] subviews]; | 202 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 207 EXPECT_EQ(1U, [subviews count]); | 203 EXPECT_EQ(1U, [subviews count]); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 TestingProfile::TestingFactories()); | 254 TestingProfile::TestingFactories()); |
| 259 StartProfileChooserController(); | 255 StartProfileChooserController(); |
| 260 | 256 |
| 261 NSArray* subviews = [[[controller() window] contentView] subviews]; | 257 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 262 EXPECT_EQ(1U, [subviews count]); | 258 EXPECT_EQ(1U, [subviews count]); |
| 263 subviews = [[subviews objectAtIndex:0] subviews]; | 259 subviews = [[subviews objectAtIndex:0] subviews]; |
| 264 NSString* sortedNames[] = { @"Another Test", | 260 NSString* sortedNames[] = { @"Another Test", |
| 265 @"New Profile", | 261 @"New Profile", |
| 266 @"Test 1", | 262 @"Test 1", |
| 267 @"Test 2" }; | 263 @"Test 2" }; |
| 268 // There are four "other" profiles, each with a button and a separator, an | 264 // There are four "other" profiles, each with a button and a separator, and an |
| 269 // active profile card, and a tutorial card. | 265 // active profile card. |
| 270 EXPECT_EQ(10U, [subviews count]); | 266 EXPECT_EQ(9U, [subviews count]); |
| 271 // There should be four "other profiles" items, sorted alphabetically. | 267 // There should be four "other profiles" items, sorted alphabetically. |
| 272 // The "other profiles" start at index 0, and each have a separator. We | 268 // The "other profiles" start at index 0, and each have a separator. We |
| 273 // need to iterate through the profiles in the order displayed in the bubble, | 269 // need to iterate through the profiles in the order displayed in the bubble, |
| 274 // which is opposite from the drawn order. | 270 // which is opposite from the drawn order. |
| 275 int sortedNameIndex = 0; | 271 int sortedNameIndex = 0; |
| 276 for (int i = 7; i >= 0; i -= 2) { | 272 for (int i = 7; i >= 0; i -= 2) { |
| 277 // The item at index i is the separator. | 273 // The item at index i is the separator. |
| 278 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); | 274 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
| 279 EXPECT_TRUE( | 275 EXPECT_TRUE( |
| 280 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 276 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 308 |
| 313 // There should be one "sign in" link. | 309 // There should be one "sign in" link. |
| 314 EXPECT_EQ(1U, [activeCardLinks count]); | 310 EXPECT_EQ(1U, [activeCardLinks count]); |
| 315 NSButton* signinLink = | 311 NSButton* signinLink = |
| 316 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 312 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
| 317 EXPECT_EQ(@selector(showTabbedSigninPage:), [signinLink action]); | 313 EXPECT_EQ(@selector(showTabbedSigninPage:), [signinLink action]); |
| 318 EXPECT_EQ(controller(), [signinLink target]); | 314 EXPECT_EQ(controller(), [signinLink target]); |
| 319 } | 315 } |
| 320 | 316 |
| 321 TEST_F(ProfileChooserControllerTest, | 317 TEST_F(ProfileChooserControllerTest, |
| 322 SignedInProfileActiveCardLinksWithNewManagement) { | 318 SignedInProfileActiveCardLinksWithAccountConsistency) { |
| 323 switches::EnableNewProfileManagementForTesting( | 319 switches::EnableAccountConsistencyForTesting( |
| 324 CommandLine::ForCurrentProcess()); | 320 CommandLine::ForCurrentProcess()); |
| 325 // Sign in the first profile. | 321 // Sign in the first profile. |
| 326 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 322 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 327 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 323 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 328 | 324 |
| 329 StartProfileChooserController(); | 325 StartProfileChooserController(); |
| 330 NSArray* subviews = [[[controller() window] contentView] subviews]; | 326 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 331 EXPECT_EQ(1U, [subviews count]); | 327 EXPECT_EQ(1U, [subviews count]); |
| 332 subviews = [[subviews objectAtIndex:0] subviews]; | 328 subviews = [[subviews objectAtIndex:0] subviews]; |
| 333 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 329 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 358 // There is one link, without a target and with the user's email. | 354 // There is one link, without a target and with the user's email. |
| 359 EXPECT_EQ(1U, [activeCardLinks count]); | 355 EXPECT_EQ(1U, [activeCardLinks count]); |
| 360 NSButton* emailLink = | 356 NSButton* emailLink = |
| 361 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 357 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
| 362 EXPECT_EQ(nil, [emailLink action]); | 358 EXPECT_EQ(nil, [emailLink action]); |
| 363 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailLink title])); | 359 EXPECT_EQ(kEmail, base::SysNSStringToUTF8([emailLink title])); |
| 364 EXPECT_EQ(controller(), [emailLink target]); | 360 EXPECT_EQ(controller(), [emailLink target]); |
| 365 } | 361 } |
| 366 | 362 |
| 367 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { | 363 TEST_F(ProfileChooserControllerTest, AccountManagementLayout) { |
| 368 switches::EnableNewProfileManagementForTesting( | 364 switches::EnableAccountConsistencyForTesting( |
| 369 CommandLine::ForCurrentProcess()); | 365 CommandLine::ForCurrentProcess()); |
| 370 // Sign in the first profile. | 366 // Sign in the first profile. |
| 371 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 367 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 372 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 368 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 373 | 369 |
| 374 // Set up the signin manager and the OAuth2Tokens. | 370 // Set up the signin manager and the OAuth2Tokens. |
| 375 Profile* profile = browser()->profile(); | 371 Profile* profile = browser()->profile(); |
| 376 SigninManagerFactory::GetForProfile(profile)-> | 372 SigninManagerFactory::GetForProfile(profile)-> |
| 377 SetAuthenticatedUsername(kEmail); | 373 SetAuthenticatedUsername(kEmail); |
| 378 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> | 374 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 456 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 461 [static_cast<NSButton*>(activeProfileName) title])); | 457 [static_cast<NSButton*>(activeProfileName) title])); |
| 462 | 458 |
| 463 // Profile links. This is a local profile, so there should be a signin button. | 459 // Profile links. This is a local profile, so there should be a signin button. |
| 464 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 460 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 465 EXPECT_EQ(1U, [linksSubviews count]); | 461 EXPECT_EQ(1U, [linksSubviews count]); |
| 466 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 462 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 467 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 463 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
| 468 EXPECT_EQ(controller(), [link target]); | 464 EXPECT_EQ(controller(), [link target]); |
| 469 } | 465 } |
| OLD | NEW |