| 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 NSRect frame = [test_window() frame]; | 68 NSRect frame = [test_window() frame]; |
| 69 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 69 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
| 70 controller_.reset([[ProfileChooserController alloc] | 70 controller_.reset([[ProfileChooserController alloc] |
| 71 initWithBrowser:browser() | 71 initWithBrowser:browser() |
| 72 anchoredAt:point | 72 anchoredAt:point |
| 73 withMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | 73 withMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
| 74 withServiceType:signin::GAIA_SERVICE_TYPE_NONE]); | 74 withServiceType:signin::GAIA_SERVICE_TYPE_NONE]); |
| 75 [controller_ showWindow:nil]; | 75 [controller_ showWindow:nil]; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void EnableNewAvatarMenuOnly() { | |
| 79 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNewAvatarMenu); | |
| 80 } | |
| 81 | |
| 82 void EnableFastUserSwitching() { | 78 void EnableFastUserSwitching() { |
| 83 CommandLine::ForCurrentProcess()->AppendSwitch( | 79 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 84 switches::kFastUserSwitching); | 80 switches::kFastUserSwitching); |
| 85 } | 81 } |
| 86 | 82 |
| 87 ProfileChooserController* controller() { return controller_; } | 83 ProfileChooserController* controller() { return controller_; } |
| 88 AvatarMenu* menu() { return menu_; } | 84 AvatarMenu* menu() { return menu_; } |
| 89 | 85 |
| 90 private: | 86 private: |
| 91 base::scoped_nsobject<ProfileChooserController> controller_; | 87 base::scoped_nsobject<ProfileChooserController> controller_; |
| 92 | 88 |
| 93 // Weak; owned by |controller_|. | 89 // Weak; owned by |controller_|. |
| 94 AvatarMenu* menu_; | 90 AvatarMenu* menu_; |
| 95 | 91 |
| 96 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); | 92 DISALLOW_COPY_AND_ASSIGN(ProfileChooserControllerTest); |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { | 95 TEST_F(ProfileChooserControllerTest, InitialLayoutWithNewMenu) { |
| 100 EnableNewAvatarMenuOnly(); | 96 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 101 StartProfileChooserController(); | 97 StartProfileChooserController(); |
| 102 | 98 |
| 103 NSArray* subviews = [[[controller() window] contentView] subviews]; | 99 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 104 ASSERT_EQ(1U, [subviews count]); | 100 ASSERT_EQ(1U, [subviews count]); |
| 105 subviews = [[subviews objectAtIndex:0] subviews]; | 101 subviews = [[subviews objectAtIndex:0] subviews]; |
| 106 | 102 |
| 107 // Three profiles means we should have one active card, one separator and | 103 // Three profiles means we should have one active card, one separator and |
| 108 // one option buttons view. | 104 // one option buttons view. |
| 109 ASSERT_EQ(3U, [subviews count]); | 105 ASSERT_EQ(3U, [subviews count]); |
| 110 | 106 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 148 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 153 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 149 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
| 154 EXPECT_EQ(controller(), [link target]); | 150 EXPECT_EQ(controller(), [link target]); |
| 155 | 151 |
| 156 NSTextField* promo = static_cast<NSTextField*>( | 152 NSTextField* promo = static_cast<NSTextField*>( |
| 157 [linksSubviews objectAtIndex:1]); | 153 [linksSubviews objectAtIndex:1]); |
| 158 EXPECT_GT([[promo stringValue] length], 0U); | 154 EXPECT_GT([[promo stringValue] length], 0U); |
| 159 } | 155 } |
| 160 | 156 |
| 161 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 157 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
| 162 EnableNewAvatarMenuOnly(); | 158 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 163 EnableFastUserSwitching(); | 159 EnableFastUserSwitching(); |
| 164 StartProfileChooserController(); | 160 StartProfileChooserController(); |
| 165 | 161 |
| 166 NSArray* subviews = [[[controller() window] contentView] subviews]; | 162 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 167 ASSERT_EQ(1U, [subviews count]); | 163 ASSERT_EQ(1U, [subviews count]); |
| 168 subviews = [[subviews objectAtIndex:0] subviews]; | 164 subviews = [[subviews objectAtIndex:0] subviews]; |
| 169 | 165 |
| 170 // Three profiles means we should have one active card and a | 166 // Three profiles means we should have one active card and a |
| 171 // fast user switcher which has two "other" profiles and 2 separators, and | 167 // fast user switcher which has two "other" profiles and 2 separators, and |
| 172 // an option buttons view with its separator. | 168 // an option buttons view with its separator. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 207 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 212 [static_cast<NSButton*>(activeProfileName) title])); | 208 [static_cast<NSButton*>(activeProfileName) title])); |
| 213 | 209 |
| 214 // Profile links. This is a local profile, so there should be a signin button | 210 // Profile links. This is a local profile, so there should be a signin button |
| 215 // and a signin promo. These are also tested in InitialLayoutWithNewMenu. | 211 // and a signin promo. These are also tested in InitialLayoutWithNewMenu. |
| 216 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 212 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 217 EXPECT_EQ(2U, [linksSubviews count]); | 213 EXPECT_EQ(2U, [linksSubviews count]); |
| 218 } | 214 } |
| 219 | 215 |
| 220 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { | 216 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { |
| 221 EnableNewAvatarMenuOnly(); | 217 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 222 EnableFastUserSwitching(); | 218 EnableFastUserSwitching(); |
| 223 | 219 |
| 224 // Add two extra profiles, to make sure sorting is alphabetical and not | 220 // Add two extra profiles, to make sure sorting is alphabetical and not |
| 225 // by order of creation. | 221 // by order of creation. |
| 226 testing_profile_manager()-> | 222 testing_profile_manager()-> |
| 227 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), | 223 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), |
| 228 base::ASCIIToUTF16("New Profile"), 1, std::string(), | 224 base::ASCIIToUTF16("New Profile"), 1, std::string(), |
| 229 TestingProfile::TestingFactories()); | 225 TestingProfile::TestingFactories()); |
| 230 testing_profile_manager()-> | 226 testing_profile_manager()-> |
| 231 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), | 227 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 252 for (int i = 9; i >= 2; i -= 2) { | 248 for (int i = 9; i >= 2; i -= 2) { |
| 253 // The item at index i is the separator. | 249 // The item at index i is the separator. |
| 254 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); | 250 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); |
| 255 EXPECT_TRUE( | 251 EXPECT_TRUE( |
| 256 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); | 252 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); |
| 257 } | 253 } |
| 258 } | 254 } |
| 259 | 255 |
| 260 TEST_F(ProfileChooserControllerTest, | 256 TEST_F(ProfileChooserControllerTest, |
| 261 LocalProfileActiveCardLinksWithNewMenu) { | 257 LocalProfileActiveCardLinksWithNewMenu) { |
| 262 EnableNewAvatarMenuOnly(); | 258 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 263 StartProfileChooserController(); | 259 StartProfileChooserController(); |
| 264 NSArray* subviews = [[[controller() window] contentView] subviews]; | 260 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 265 ASSERT_EQ(1U, [subviews count]); | 261 ASSERT_EQ(1U, [subviews count]); |
| 266 subviews = [[subviews objectAtIndex:0] subviews]; | 262 subviews = [[subviews objectAtIndex:0] subviews]; |
| 267 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 263 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 268 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 264 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 269 | 265 |
| 270 ASSERT_EQ(2U, [activeCardLinks count]); | 266 ASSERT_EQ(2U, [activeCardLinks count]); |
| 271 | 267 |
| 272 // There should be a sign in button. | 268 // There should be a sign in button. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 298 // There is one link: manage accounts. | 294 // There is one link: manage accounts. |
| 299 ASSERT_EQ(1U, [activeCardLinks count]); | 295 ASSERT_EQ(1U, [activeCardLinks count]); |
| 300 NSButton* manageAccountsLink = | 296 NSButton* manageAccountsLink = |
| 301 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); | 297 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); |
| 302 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); | 298 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); |
| 303 EXPECT_EQ(controller(), [manageAccountsLink target]); | 299 EXPECT_EQ(controller(), [manageAccountsLink target]); |
| 304 } | 300 } |
| 305 | 301 |
| 306 TEST_F(ProfileChooserControllerTest, | 302 TEST_F(ProfileChooserControllerTest, |
| 307 SignedInProfileActiveCardLinksWithNewMenu) { | 303 SignedInProfileActiveCardLinksWithNewMenu) { |
| 308 EnableNewAvatarMenuOnly(); | 304 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 309 // Sign in the first profile. | 305 // Sign in the first profile. |
| 310 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); | 306 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); |
| 311 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); | 307 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); |
| 312 | 308 |
| 313 StartProfileChooserController(); | 309 StartProfileChooserController(); |
| 314 NSArray* subviews = [[[controller() window] contentView] subviews]; | 310 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 315 ASSERT_EQ(1U, [subviews count]); | 311 ASSERT_EQ(1U, [subviews count]); |
| 316 subviews = [[subviews objectAtIndex:0] subviews]; | 312 subviews = [[subviews objectAtIndex:0] subviews]; |
| 317 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; | 313 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; |
| 318 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; | 314 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( | 428 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( |
| 433 [static_cast<NSButton*>(activeProfileName) title])); | 429 [static_cast<NSButton*>(activeProfileName) title])); |
| 434 | 430 |
| 435 // Profile links. This is a local profile, so there should be a signin button. | 431 // Profile links. This is a local profile, so there should be a signin button. |
| 436 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; | 432 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; |
| 437 ASSERT_EQ(1U, [linksSubviews count]); | 433 ASSERT_EQ(1U, [linksSubviews count]); |
| 438 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); | 434 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); |
| 439 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); | 435 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); |
| 440 EXPECT_EQ(controller(), [link target]); | 436 EXPECT_EQ(controller(), [link target]); |
| 441 } | 437 } |
| OLD | NEW |