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

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

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

Powered by Google App Engine
This is Rietveld 408576698