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

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: Unit testing Avatar Button 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 - (id)init;
19 - (void)buttonRightClicked;
20 @end
21
22 @implementation AvatarButtonTestObserver
23 @synthesize clicked_;
24
25 - (id)init {
26 self.clicked_ = NO;
27 return self;
28 }
29 - (void)buttonRightClicked {
30 self.clicked_ = YES;
31 }
32 @end
33
34 class AvatarButtonTest : public ui::CocoaTest {
35 public:
36 AvatarButtonTest() {
37 NSRect content_frame = [[test_window() contentView] frame];
38 base::scoped_nsobject<AvatarButton> button(
39 [[AvatarButton alloc] initWithFrame:content_frame]);
40 button_ = button.get();
41 [[test_window() contentView] addSubview:button_];
42 }
43
44 AvatarButton* button_;
45 };
46
47 TEST_F(AvatarButtonTest, RightClick) {
48 base::scoped_nsobject<AvatarButtonTestObserver> observer(
49 [[AvatarButtonTestObserver alloc] init]);
50 [button_ setTarget:observer.get()];
51 [button_ setRightAction:@selector(buttonRightClicked)];
52
53 ASSERT_FALSE(observer.get().clicked_);
54
55 [button_ performRightClick];
56 ASSERT_TRUE(observer.get().clicked_);
57 }
58
59 TEST_F(AvatarButtonTest, RightClickInView) {
60 base::scoped_nsobject<AvatarButtonTestObserver> observer(
61 [[AvatarButtonTestObserver alloc] init]);
62 [button_ setTarget:observer.get()];
63 [button_ setRightAction:@selector(buttonRightClicked)];
64
65 ASSERT_FALSE(observer.get().clicked_);
66
67 std::pair<NSEvent*, NSEvent*> events =
68 cocoa_test_event_utils::RightMouseClickInView(button_, 1);
69
70 [NSApp postEvent:events.second atStart:YES];
71 [NSApp sendEvent:events.first];
72
73 ASSERT_TRUE(observer.get().clicked_);
74 }
75
76 TEST_F(AvatarButtonTest, RightMouseUpOutOfView) {
77 base::scoped_nsobject<AvatarButtonTestObserver> observer(
78 [[AvatarButtonTestObserver alloc] init]);
79 [button_ setTarget:observer.get()];
80 [button_ setRightAction:@selector(buttonRightClicked)];
81
82 ASSERT_FALSE(observer.get().clicked_);
83
84 const NSRect bounds = [button_ convertRect:[button_ bounds] toView:nil];
85 const NSPoint downLocation = NSMakePoint(NSMidX(bounds), NSMidY(bounds));
86 NSEvent* down = cocoa_test_event_utils::MouseEventAtPointInWindow(
87 downLocation, NSRightMouseDown, [button_ window], 1);
88
89 const NSPoint upLocation = NSMakePoint(downLocation.x + bounds.size.width,
90 downLocation.y + bounds.size.height);
91 NSEvent* up = cocoa_test_event_utils::MouseEventAtPointInWindow(
92 upLocation, NSRightMouseUp, [button_ window], 1);
93
94 [NSApp postEvent:up atStart:YES];
95 [NSApp sendEvent:down];
96
97 ASSERT_FALSE(observer.get().clicked_);
98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698