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 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 EXPECT_EQ(3U, menu_->GetNumberOfItems()); | 73 EXPECT_EQ(3U, menu_->GetNumberOfItems()); |
74 } | 74 } |
75 | 75 |
76 void TearDown() override { | 76 void TearDown() override { |
77 [controller() close]; | 77 [controller() close]; |
78 controller_.reset(); | 78 controller_.reset(); |
79 CocoaProfileTest::TearDown(); | 79 CocoaProfileTest::TearDown(); |
80 } | 80 } |
81 | 81 |
82 void StartProfileChooserController() { | 82 void StartProfileChooserController() { |
| 83 StartProfileChooserControllerWithTutorialMode(profiles::TUTORIAL_MODE_NONE); |
| 84 } |
| 85 |
| 86 void StartProfileChooserControllerWithTutorialMode( |
| 87 profiles::TutorialMode mode) { |
83 NSRect frame = [test_window() frame]; | 88 NSRect frame = [test_window() frame]; |
84 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); | 89 NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
85 controller_.reset([[ProfileChooserController alloc] | 90 controller_.reset([[ProfileChooserController alloc] |
86 initWithBrowser:browser() | 91 initWithBrowser:browser() |
87 anchoredAt:point | 92 anchoredAt:point |
88 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | 93 viewMode:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER |
89 tutorialMode:profiles::TUTORIAL_MODE_NONE | 94 tutorialMode:mode |
90 serviceType:signin::GAIA_SERVICE_TYPE_NONE]); | 95 serviceType:signin::GAIA_SERVICE_TYPE_NONE]); |
91 [controller_ showWindow:nil]; | 96 [controller_ showWindow:nil]; |
92 } | 97 } |
93 | 98 |
| 99 void AssertRightClickTutorialShown() { |
| 100 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 101 ASSERT_EQ(2U, [subviews count]); |
| 102 subviews = [[subviews objectAtIndex:0] subviews]; |
| 103 |
| 104 // There should be 4 views: the tutorial, the active profile card, a |
| 105 // separator and the options view. |
| 106 ASSERT_EQ(4U, [subviews count]); |
| 107 |
| 108 // The tutorial is the topmost view, so the last in the array. It should |
| 109 // contain 3 views: the title, the content text and the OK button. |
| 110 NSArray* tutorialSubviews = [[subviews objectAtIndex:3] subviews]; |
| 111 ASSERT_EQ(3U, [tutorialSubviews count]); |
| 112 |
| 113 NSTextField* tutorialTitle = base::mac::ObjCCastStrict<NSTextField>( |
| 114 [tutorialSubviews objectAtIndex:2]); |
| 115 EXPECT_GT([[tutorialTitle stringValue] length], 0U); |
| 116 |
| 117 NSTextField* tutorialContent = base::mac::ObjCCastStrict<NSTextField>( |
| 118 [tutorialSubviews objectAtIndex:1]); |
| 119 EXPECT_GT([[tutorialContent stringValue] length], 0U); |
| 120 |
| 121 NSButton* tutorialOKButton = base::mac::ObjCCastStrict<NSButton>( |
| 122 [tutorialSubviews objectAtIndex:0]); |
| 123 EXPECT_GT([[tutorialOKButton title] length], 0U); |
| 124 } |
| 125 |
94 void EnableFastUserSwitching() { | 126 void EnableFastUserSwitching() { |
95 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 127 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
96 switches::kFastUserSwitching); | 128 switches::kFastUserSwitching); |
97 } | 129 } |
98 | 130 |
99 ProfileChooserController* controller() { return controller_; } | 131 ProfileChooserController* controller() { return controller_; } |
100 AvatarMenu* menu() { return menu_; } | 132 AvatarMenu* menu() { return menu_; } |
101 | 133 |
102 private: | 134 private: |
103 base::scoped_nsobject<ProfileChooserController> controller_; | 135 base::scoped_nsobject<ProfileChooserController> controller_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 NSButton* link = base::mac::ObjCCast<NSButton>( | 200 NSButton* link = base::mac::ObjCCast<NSButton>( |
169 [linksSubviews objectAtIndex:0]); | 201 [linksSubviews objectAtIndex:0]); |
170 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); | 202 EXPECT_EQ(@selector(showInlineSigninPage:), [link action]); |
171 EXPECT_EQ(controller(), [link target]); | 203 EXPECT_EQ(controller(), [link target]); |
172 | 204 |
173 NSTextField* promo = base::mac::ObjCCast<NSTextField>( | 205 NSTextField* promo = base::mac::ObjCCast<NSTextField>( |
174 [linksSubviews objectAtIndex:1]); | 206 [linksSubviews objectAtIndex:1]); |
175 EXPECT_GT([[promo stringValue] length], 0U); | 207 EXPECT_GT([[promo stringValue] length], 0U); |
176 } | 208 } |
177 | 209 |
| 210 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterWelcome) { |
| 211 switches::EnableNewAvatarMenuForTesting( |
| 212 base::CommandLine::ForCurrentProcess()); |
| 213 // The welcome upgrade tutorial takes precedence so show it then dismiss it. |
| 214 // The right click tutorial should be shown right away. |
| 215 StartProfileChooserControllerWithTutorialMode( |
| 216 profiles::TUTORIAL_MODE_WELCOME_UPGRADE); |
| 217 |
| 218 [controller() dismissTutorial:nil]; |
| 219 AssertRightClickTutorialShown(); |
| 220 } |
| 221 |
| 222 TEST_F(ProfileChooserControllerTest, RightClickTutorialShownAfterReopen) { |
| 223 switches::EnableNewAvatarMenuForTesting( |
| 224 base::CommandLine::ForCurrentProcess()); |
| 225 // The welcome upgrade tutorial takes precedence so show it then close the |
| 226 // menu. Reopening the menu should show the tutorial. |
| 227 StartProfileChooserController(); |
| 228 |
| 229 [controller() close]; |
| 230 StartProfileChooserController(); |
| 231 AssertRightClickTutorialShown(); |
| 232 |
| 233 // The tutorial must be manually dismissed so it should still be shown after |
| 234 // closing and reopening the menu, |
| 235 [controller() close]; |
| 236 StartProfileChooserController(); |
| 237 AssertRightClickTutorialShown(); |
| 238 } |
| 239 |
| 240 TEST_F(ProfileChooserControllerTest, RightClickTutorialNotShownAfterDismiss) { |
| 241 switches::EnableNewAvatarMenuForTesting( |
| 242 base::CommandLine::ForCurrentProcess()); |
| 243 // The welcome upgrade tutorial takes precedence so show it then close the |
| 244 // menu. Reopening the menu should show the tutorial. |
| 245 StartProfileChooserController(); |
| 246 |
| 247 [controller() close]; |
| 248 StartProfileChooserControllerWithTutorialMode( |
| 249 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 250 AssertRightClickTutorialShown(); |
| 251 |
| 252 // Dismissing the tutorial should prevent it from being shown forever. |
| 253 [controller() dismissTutorial:nil]; |
| 254 NSArray* subviews = [[[controller() window] contentView] subviews]; |
| 255 ASSERT_EQ(2U, [subviews count]); |
| 256 subviews = [[subviews objectAtIndex:0] subviews]; |
| 257 |
| 258 // There should be 3 views since there's no tutorial |
| 259 ASSERT_EQ(3U, [subviews count]); |
| 260 |
| 261 // Closing and reopening the menu shouldn't show the tutorial. |
| 262 [controller() close]; |
| 263 StartProfileChooserControllerWithTutorialMode( |
| 264 profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING); |
| 265 subviews = [[[controller() window] contentView] subviews]; |
| 266 ASSERT_EQ(2U, [subviews count]); |
| 267 subviews = [[subviews objectAtIndex:0] subviews]; |
| 268 |
| 269 // There should be 3 views since there's no tutorial |
| 270 ASSERT_EQ(3U, [subviews count]); |
| 271 } |
| 272 |
178 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { | 273 TEST_F(ProfileChooserControllerTest, InitialLayoutWithFastUserSwitcher) { |
179 switches::EnableNewAvatarMenuForTesting( | 274 switches::EnableNewAvatarMenuForTesting( |
180 base::CommandLine::ForCurrentProcess()); | 275 base::CommandLine::ForCurrentProcess()); |
181 EnableFastUserSwitching(); | 276 EnableFastUserSwitching(); |
182 StartProfileChooserController(); | 277 StartProfileChooserController(); |
183 | 278 |
184 NSArray* subviews = [[[controller() window] contentView] subviews]; | 279 NSArray* subviews = [[[controller() window] contentView] subviews]; |
185 ASSERT_EQ(2U, [subviews count]); | 280 ASSERT_EQ(2U, [subviews count]); |
186 subviews = [[subviews objectAtIndex:0] subviews]; | 281 subviews = [[subviews objectAtIndex:0] subviews]; |
187 | 282 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 ASSERT_EQ(5U, [buttonSubviews count]); | 613 ASSERT_EQ(5U, [buttonSubviews count]); |
519 | 614 |
520 // There should be a lock button. | 615 // There should be a lock button. |
521 NSButton* lockButton = | 616 NSButton* lockButton = |
522 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); | 617 base::mac::ObjCCast<NSButton>([buttonSubviews objectAtIndex:0]); |
523 ASSERT_TRUE(lockButton); | 618 ASSERT_TRUE(lockButton); |
524 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); | 619 EXPECT_EQ(@selector(lockProfile:), [lockButton action]); |
525 EXPECT_EQ(controller(), [lockButton target]); | 620 EXPECT_EQ(controller(), [lockButton target]); |
526 EXPECT_TRUE([lockButton isEnabled]); | 621 EXPECT_TRUE([lockButton isEnabled]); |
527 } | 622 } |
OLD | NEW |