Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller_unittest.mm

Issue 431083003: Change new-avatar-menu to an enable-disable flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase - [Still Includes NewAvatarMenu by default] Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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();
101 StartProfileChooserController(); 96 StartProfileChooserController();
102 97
103 NSArray* subviews = [[[controller() window] contentView] subviews]; 98 NSArray* subviews = [[[controller() window] contentView] subviews];
104 ASSERT_EQ(1U, [subviews count]); 99 ASSERT_EQ(1U, [subviews count]);
105 subviews = [[subviews objectAtIndex:0] subviews]; 100 subviews = [[subviews objectAtIndex:0] subviews];
106 101
107 // Three profiles means we should have one active card, one separator and 102 // Three profiles means we should have one active card, one separator and
108 // one option buttons view. 103 // one option buttons view.
109 ASSERT_EQ(3U, [subviews count]); 104 ASSERT_EQ(3U, [subviews count]);
110 105
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); 147 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]);
153 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); 148 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]);
154 EXPECT_EQ(controller(), [link target]); 149 EXPECT_EQ(controller(), [link target]);
155 150
156 NSTextField* promo = static_cast<NSTextField*>( 151 NSTextField* promo = static_cast<NSTextField*>(
157 [linksSubviews objectAtIndex:1]); 152 [linksSubviews objectAtIndex:1]);
158 EXPECT_GT([[promo stringValue] length], 0U); 153 EXPECT_GT([[promo stringValue] length], 0U);
159 } 154 }
160 155
161 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { 156 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) {
162 EnableNewAvatarMenuOnly();
163 EnableFastUserSwitching(); 157 EnableFastUserSwitching();
164 StartProfileChooserController(); 158 StartProfileChooserController();
165 159
166 NSArray* subviews = [[[controller() window] contentView] subviews]; 160 NSArray* subviews = [[[controller() window] contentView] subviews];
167 ASSERT_EQ(1U, [subviews count]); 161 ASSERT_EQ(1U, [subviews count]);
168 subviews = [[subviews objectAtIndex:0] subviews]; 162 subviews = [[subviews objectAtIndex:0] subviews];
169 163
170 // Three profiles means we should have one active card and a 164 // Three profiles means we should have one active card and a
171 // fast user switcher which has two "other" profiles and 2 separators, and 165 // fast user switcher which has two "other" profiles and 2 separators, and
172 // an option buttons view with its separator. 166 // an option buttons view with its separator.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( 205 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
212 [static_cast<NSButton*>(activeProfileName) title])); 206 [static_cast<NSButton*>(activeProfileName) title]));
213 207
214 // Profile links. This is a local profile, so there should be a signin button 208 // 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. 209 // and a signin promo. These are also tested in InitialLayoutWithNewMenu.
216 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; 210 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
217 EXPECT_EQ(2U, [linksSubviews count]); 211 EXPECT_EQ(2U, [linksSubviews count]);
218 } 212 }
219 213
220 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) { 214 TEST_F(ProfileChooserControllerTest, OtherProfilesSortedAlphabetically) {
221 EnableNewAvatarMenuOnly();
222 EnableFastUserSwitching(); 215 EnableFastUserSwitching();
223 216
224 // Add two extra profiles, to make sure sorting is alphabetical and not 217 // Add two extra profiles, to make sure sorting is alphabetical and not
225 // by order of creation. 218 // by order of creation.
226 testing_profile_manager()-> 219 testing_profile_manager()->
227 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(), 220 CreateTestingProfile("test3", scoped_ptr<PrefServiceSyncable>(),
228 base::ASCIIToUTF16("New Profile"), 1, std::string(), 221 base::ASCIIToUTF16("New Profile"), 1, std::string(),
229 TestingProfile::TestingFactories()); 222 TestingProfile::TestingFactories());
230 testing_profile_manager()-> 223 testing_profile_manager()->
231 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(), 224 CreateTestingProfile("test4", scoped_ptr<PrefServiceSyncable>(),
(...skipping 20 matching lines...) Expand all
252 for (int i = 9; i >= 2; i -= 2) { 245 for (int i = 9; i >= 2; i -= 2) {
253 // The item at index i is the separator. 246 // The item at index i is the separator.
254 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]); 247 NSButton* button = static_cast<NSButton*>([subviews objectAtIndex:i-1]);
255 EXPECT_TRUE( 248 EXPECT_TRUE(
256 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]); 249 [[button title] isEqualToString:sortedNames[sortedNameIndex++]]);
257 } 250 }
258 } 251 }
259 252
260 TEST_F(ProfileChooserControllerTest, 253 TEST_F(ProfileChooserControllerTest,
261 LocalProfileActiveCardLinksWithNewMenu) { 254 LocalProfileActiveCardLinksWithNewMenu) {
262 EnableNewAvatarMenuOnly();
263 StartProfileChooserController(); 255 StartProfileChooserController();
264 NSArray* subviews = [[[controller() window] contentView] subviews]; 256 NSArray* subviews = [[[controller() window] contentView] subviews];
265 ASSERT_EQ(1U, [subviews count]); 257 ASSERT_EQ(1U, [subviews count]);
266 subviews = [[subviews objectAtIndex:0] subviews]; 258 subviews = [[subviews objectAtIndex:0] subviews];
267 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; 259 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
268 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; 260 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
269 261
270 ASSERT_EQ(2U, [activeCardLinks count]); 262 ASSERT_EQ(2U, [activeCardLinks count]);
271 263
272 // There should be a sign in button. 264 // There should be a sign in button.
(...skipping 25 matching lines...) Expand all
298 // There is one link: manage accounts. 290 // There is one link: manage accounts.
299 ASSERT_EQ(1U, [activeCardLinks count]); 291 ASSERT_EQ(1U, [activeCardLinks count]);
300 NSButton* manageAccountsLink = 292 NSButton* manageAccountsLink =
301 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]); 293 static_cast<NSButton*>([activeCardLinks objectAtIndex:0]);
302 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]); 294 EXPECT_EQ(@selector(showAccountManagement:), [manageAccountsLink action]);
303 EXPECT_EQ(controller(), [manageAccountsLink target]); 295 EXPECT_EQ(controller(), [manageAccountsLink target]);
304 } 296 }
305 297
306 TEST_F(ProfileChooserControllerTest, 298 TEST_F(ProfileChooserControllerTest,
307 SignedInProfileActiveCardLinksWithNewMenu) { 299 SignedInProfileActiveCardLinksWithNewMenu) {
308 EnableNewAvatarMenuOnly();
309 // Sign in the first profile. 300 // Sign in the first profile.
310 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache(); 301 ProfileInfoCache* cache = testing_profile_manager()->profile_info_cache();
311 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail)); 302 cache->SetUserNameOfProfileAtIndex(0, base::ASCIIToUTF16(kEmail));
312 303
313 StartProfileChooserController(); 304 StartProfileChooserController();
314 NSArray* subviews = [[[controller() window] contentView] subviews]; 305 NSArray* subviews = [[[controller() window] contentView] subviews];
315 ASSERT_EQ(1U, [subviews count]); 306 ASSERT_EQ(1U, [subviews count]);
316 subviews = [[subviews objectAtIndex:0] subviews]; 307 subviews = [[subviews objectAtIndex:0] subviews];
317 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews]; 308 NSArray* activeCardSubviews = [[subviews objectAtIndex:2] subviews];
318 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews]; 309 NSArray* activeCardLinks = [[activeCardSubviews objectAtIndex:0] subviews];
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16( 423 EXPECT_EQ(menu()->GetItemAt(0).name, base::SysNSStringToUTF16(
433 [static_cast<NSButton*>(activeProfileName) title])); 424 [static_cast<NSButton*>(activeProfileName) title]));
434 425
435 // Profile links. This is a local profile, so there should be a signin button. 426 // Profile links. This is a local profile, so there should be a signin button.
436 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews]; 427 NSArray* linksSubviews = [[activeCardSubviews objectAtIndex:0] subviews];
437 ASSERT_EQ(1U, [linksSubviews count]); 428 ASSERT_EQ(1U, [linksSubviews count]);
438 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]); 429 NSButton* link = static_cast<NSButton*>([linksSubviews objectAtIndex:0]);
439 EXPECT_EQ(@selector(hideAccountManagement:), [link action]); 430 EXPECT_EQ(@selector(hideAccountManagement:), [link action]);
440 EXPECT_EQ(controller(), [link target]); 431 EXPECT_EQ(controller(), [link target]);
441 } 432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698