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

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

Issue 916523003: Bring up fast user switcher on right-click of the avatar menu on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove init in unit tests Created 5 years, 10 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h"
6
7 #import "base/mac/scoped_nsobject.h"
8 #import "ui/events/test/cocoa_test_event_utils.h"
9 #import "ui/gfx/test/ui_cocoa_test_helper.h"
10
11 @interface AvatarButton (ExposedForTesting)
12 - (void)performRightClick;
13 @end
14
15 @interface AvatarButtonTestObserver : NSObject
16 @property BOOL clicked;
17
18 - (void)buttonRightClicked;
19 @end
20
21 @implementation AvatarButtonTestObserver
22 @synthesize clicked = clicked_;
23
24 - (void)buttonRightClicked {
25 self.clicked = YES;
26 }
27 @end
28
29 class AvatarButtonTest : public ui::CocoaTest {
30 public:
31 AvatarButtonTest() {
32 NSRect content_frame = [[test_window() contentView] frame];
33 base::scoped_nsobject<AvatarButton> button(
34 [[AvatarButton alloc] initWithFrame:content_frame]);
35 button_ = button.get();
36 [[test_window() contentView] addSubview:button_];
37 }
38
39 AvatarButton* button_;
40 };
41
42 TEST_F(AvatarButtonTest, RightClick) {
43 base::scoped_nsobject<AvatarButtonTestObserver> observer(
44 [[AvatarButtonTestObserver alloc] init]);
45 [button_ setTarget:observer.get()];
46 [button_ setRightAction:@selector(buttonRightClicked)];
47
48 ASSERT_FALSE(observer.get().clicked);
49
50 [button_ performRightClick];
51 ASSERT_TRUE(observer.get().clicked);
52 }
53
54 TEST_F(AvatarButtonTest, RightClickInView) {
55 base::scoped_nsobject<AvatarButtonTestObserver> observer(
56 [[AvatarButtonTestObserver alloc] init]);
57 [button_ setTarget:observer.get()];
58 [button_ setRightAction:@selector(buttonRightClicked)];
59
60 ASSERT_FALSE(observer.get().clicked);
61
62 std::pair<NSEvent*, NSEvent*> events =
63 cocoa_test_event_utils::RightMouseClickInView(button_, 1);
64
65 [NSApp postEvent:events.second atStart:YES];
66 [NSApp sendEvent:events.first];
67
68 ASSERT_TRUE(observer.get().clicked);
69 }
70
71 TEST_F(AvatarButtonTest, RightMouseUpOutOfView) {
72 base::scoped_nsobject<AvatarButtonTestObserver> observer(
73 [[AvatarButtonTestObserver alloc] init]);
74 [button_ setTarget:observer.get()];
75 [button_ setRightAction:@selector(buttonRightClicked)];
76
77 ASSERT_FALSE(observer.get().clicked);
78
79 const NSRect bounds = [button_ convertRect:[button_ bounds] toView:nil];
80 const NSPoint downLocation = NSMakePoint(NSMidX(bounds), NSMidY(bounds));
81 NSEvent* down = cocoa_test_event_utils::MouseEventAtPointInWindow(
82 downLocation, NSRightMouseDown, [button_ window], 1);
83
84 const NSPoint upLocation = NSMakePoint(downLocation.x + bounds.size.width,
85 downLocation.y + bounds.size.height);
86 NSEvent* up = cocoa_test_event_utils::MouseEventAtPointInWindow(
87 upLocation, NSRightMouseUp, [button_ window], 1);
88
89 [NSApp postEvent:up atStart:YES];
90 [NSApp sendEvent:down];
91
92 ASSERT_FALSE(observer.get().clicked);
93 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698