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

Side by Side Diff: ui/events/cocoa/cocoa_event_utils_unittest.mm

Issue 160083003: Split cocoa_event_utils in two parts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ui/events/cocoa/cocoa_event_utils.h"
6
5 #import <objc/objc-class.h> 7 #import <objc/objc-class.h>
6 8
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/platform_test.h" 10 #include "testing/platform_test.h"
9 #include "ui/base/cocoa/cocoa_event_utils.h"
10 #include "ui/events/event_constants.h" 11 #include "ui/events/event_constants.h"
11 #import "ui/events/test/cocoa_test_event_utils.h" 12 #import "ui/events/test/cocoa_test_event_utils.h"
12 #import "ui/gfx/test/ui_cocoa_test_helper.h" 13 #import "ui/gfx/test/ui_cocoa_test_helper.h"
13 14
14 // We provide a donor class with a specially modified |modifierFlags|
15 // implementation that we swap with NSEvent's. This is because we can't create a
16 // NSEvent that represents a middle click with modifiers.
17 @interface TestEvent : NSObject
18 @end
19 @implementation TestEvent
20 - (NSUInteger)modifierFlags { return NSShiftKeyMask; }
21 @end
22
23 namespace ui { 15 namespace ui {
24 16
25 namespace { 17 namespace {
26 18
27 class EventUtilsTest : public CocoaTest { 19 class CocoaEventUtilsTest : public CocoaTest {
28 }; 20 };
29 21
30 TEST_F(EventUtilsTest, TestWindowOpenDispositionFromNSEvent) { 22 TEST_F(CocoaEventUtilsTest, TestEventFlagsFromNSEvent) {
31 // Left Click = same tab.
32 NSEvent* me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
33 EXPECT_EQ(CURRENT_TAB, WindowOpenDispositionFromNSEvent(me));
34
35 // Middle Click = new background tab.
36 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0);
37 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
38
39 // Shift+Middle Click = new foreground tab.
40 {
41 ScopedClassSwizzler swizzler([NSEvent class], [TestEvent class],
42 @selector(modifierFlags));
43 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp,
44 NSShiftKeyMask);
45 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
46 }
47
48 // Cmd+Left Click = new background tab.
49 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
50 NSCommandKeyMask);
51 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
52
53 // Cmd+Shift+Left Click = new foreground tab.
54 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
55 NSCommandKeyMask |
56 NSShiftKeyMask);
57 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
58
59 // Shift+Left Click = new window
60 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
61 NSShiftKeyMask);
62 EXPECT_EQ(NEW_WINDOW, WindowOpenDispositionFromNSEvent(me));
63 }
64
65
66 TEST_F(EventUtilsTest, TestEventFlagsFromNSEvent) {
67 // Left click. 23 // Left click.
68 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); 24 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
69 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNSEvent(left)); 25 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNSEvent(left));
70 26
71 // Right click. 27 // Right click.
72 NSEvent* right = cocoa_test_event_utils::MouseEventWithType(NSRightMouseUp, 28 NSEvent* right = cocoa_test_event_utils::MouseEventWithType(NSRightMouseUp,
73 0); 29 0);
74 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, EventFlagsFromNSEvent(right)); 30 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, EventFlagsFromNSEvent(right));
75 31
76 // Middle click. 32 // Middle click.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 75 cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
120 NSCommandKeyMask | 76 NSCommandKeyMask |
121 NSAlternateKeyMask); 77 NSAlternateKeyMask);
122 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_COMMAND_DOWN | EF_ALT_DOWN, 78 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_COMMAND_DOWN | EF_ALT_DOWN,
123 EventFlagsFromNSEvent(cmdalt)); 79 EventFlagsFromNSEvent(cmdalt));
124 } 80 }
125 81
126 } // namespace 82 } // namespace
127 83
128 } // namespace ui 84 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698