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

Side by Side Diff: chrome/browser/ui/cocoa/event_utils_unittest.mm

Issue 6893046: added CTRL+Click and SHIFT+Click handler for context menu, Back and Forward. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: make this patch applicable to the latest trunk Created 9 years, 6 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <objc/objc-class.h> 5 #import <objc/objc-class.h>
6 6
7 #include "ui/base/events.h"
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
8 #include "chrome/browser/ui/cocoa/event_utils.h" 9 #include "chrome/browser/ui/cocoa/event_utils.h"
9 #include "chrome/browser/ui/cocoa/test_event_utils.h" 10 #include "chrome/browser/ui/cocoa/test_event_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
13 // We provide a donor class with a specially modified |modifierFlags| 14 // We provide a donor class with a specially modified |modifierFlags|
14 // implementation that we swap with NSEvent's. This is because we can't create a 15 // implementation that we swap with NSEvent's. This is because we can't create a
15 // NSEvent that represents a middle click with modifiers. 16 // NSEvent that represents a middle click with modifiers.
16 @interface TestEvent : NSObject 17 @interface TestEvent : NSObject
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Cmd+Shift+Left Click = new foreground tab. 52 // Cmd+Shift+Left Click = new foreground tab.
52 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSCommandKeyMask | NSShif tKeyMask); 53 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSCommandKeyMask | NSShif tKeyMask);
53 EXPECT_EQ(NEW_FOREGROUND_TAB, 54 EXPECT_EQ(NEW_FOREGROUND_TAB,
54 event_utils::WindowOpenDispositionFromNSEvent(me)); 55 event_utils::WindowOpenDispositionFromNSEvent(me));
55 56
56 // Shift+Left Click = new window 57 // Shift+Left Click = new window
57 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSShiftKeyMask); 58 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSShiftKeyMask);
58 EXPECT_EQ(NEW_WINDOW, event_utils::WindowOpenDispositionFromNSEvent(me)); 59 EXPECT_EQ(NEW_WINDOW, event_utils::WindowOpenDispositionFromNSEvent(me));
59 } 60 }
60 61
62 TEST_F(EventUtilsTest, TestEventFlagsFromNSEvent) {
63 // Left click.
64 NSEvent* left = test_event_utils::MakeMouseEvent(NSLeftMouseUp, 0);
65 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN,
66 event_utils::EventFlagsFromNSEvent(left));
67
68 // Right click.
69 NSEvent* right = test_event_utils::MakeMouseEvent(NSRightMouseUp, 0);
70 EXPECT_EQ(ui::EF_RIGHT_BUTTON_DOWN,
71 event_utils::EventFlagsFromNSEvent(right));
72
73 // Middle click.
74 NSEvent* middle = test_event_utils::MakeMouseEvent(NSOtherMouseUp, 0);
75 EXPECT_EQ(ui::EF_MIDDLE_BUTTON_DOWN,
76 event_utils::EventFlagsFromNSEvent(middle));
77
78 // Caps + Left
79 NSEvent* caps = test_event_utils::MakeMouseEvent(
80 NSLeftMouseUp, NSAlphaShiftKeyMask);
81 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_CAPS_LOCK_DOWN,
82 event_utils::EventFlagsFromNSEvent(caps));
83
84 // Shift + Left
85 NSEvent* shift = test_event_utils::MakeMouseEvent(
86 NSLeftMouseUp, NSShiftKeyMask);
87 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_SHIFT_DOWN,
88 event_utils::EventFlagsFromNSEvent(shift));
89
90 // Ctrl + Left
91 NSEvent* ctrl = test_event_utils::MakeMouseEvent(
92 NSLeftMouseUp, NSControlKeyMask);
93 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_CONTROL_DOWN,
94 event_utils::EventFlagsFromNSEvent(ctrl));
95
96 // Alt + Left
97 NSEvent* alt = test_event_utils::MakeMouseEvent(
98 NSLeftMouseUp, NSAlternateKeyMask);
99 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_ALT_DOWN,
100 event_utils::EventFlagsFromNSEvent(alt));
101
102 // Cmd + Left
103 NSEvent* cmd = test_event_utils::MakeMouseEvent(
104 NSLeftMouseUp, NSCommandKeyMask);
105 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_COMMAND_DOWN,
106 event_utils::EventFlagsFromNSEvent(cmd));
107
108 // Shift + Ctrl + Left
109 NSEvent* shiftctrl = test_event_utils::MakeMouseEvent(
110 NSLeftMouseUp, NSShiftKeyMask | NSControlKeyMask);
111 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
112 event_utils::EventFlagsFromNSEvent(shiftctrl));
113
114 // Cmd + Alt + Right
115 NSEvent* cmdalt = test_event_utils::MakeMouseEvent(
116 NSLeftMouseUp, NSCommandKeyMask | NSAlternateKeyMask);
117 EXPECT_EQ(ui::EF_LEFT_BUTTON_DOWN | ui::EF_COMMAND_DOWN | ui::EF_ALT_DOWN,
118 event_utils::EventFlagsFromNSEvent(cmdalt));
119 }
120
61 } // namespace 121 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/event_utils.mm ('k') | chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698