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

Side by Side Diff: Source/web/tests/WebInputEventFactoryTestMac.mm

Issue 1215633003: Fix false negatives in system key events recognition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add test Created 5 years, 2 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
« no previous file with comments | « Source/web/WebInputEventFactoryMac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #import <Cocoa/Cocoa.h> 33 #import <Cocoa/Cocoa.h>
34 #include <Carbon/Carbon.h>
34 #include <gtest/gtest.h> 35 #include <gtest/gtest.h>
35 36
36 #include "core/events/KeyboardEvent.h" 37 #include "core/events/KeyboardEvent.h"
37 #include "platform/WindowsKeyboardCodes.h" 38 #include "platform/WindowsKeyboardCodes.h"
38 #include "public/web/WebInputEvent.h" 39 #include "public/web/WebInputEvent.h"
39 #include "public/web/mac/WebInputEventFactory.h" 40 #include "public/web/mac/WebInputEventFactory.h"
40 41
41 using blink::WebInputEventFactory; 42 using blink::WebInputEventFactory;
42 using blink::WebKeyboardEvent; 43 using blink::WebKeyboardEvent;
43 using blink::WebInputEvent; 44 using blink::WebInputEvent;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 const ModifierKey& key = modifierKeys[i]; 186 const ModifierKey& key = modifierKeys[i];
186 NSEvent* macEvent = BuildFakeKeyEvent( 187 NSEvent* macEvent = BuildFakeKeyEvent(
187 key.macKeyCode, 0, key.nonSpecificMask, NSFlagsChanged); 188 key.macKeyCode, 0, key.nonSpecificMask, NSFlagsChanged);
188 WebKeyboardEvent webEvent = WebInputEventFactory::keyboardEvent(macEvent ); 189 WebKeyboardEvent webEvent = WebInputEventFactory::keyboardEvent(macEvent );
189 EXPECT_EQ(WebInputEvent::RawKeyDown, webEvent.type); 190 EXPECT_EQ(WebInputEvent::RawKeyDown, webEvent.type);
190 macEvent = BuildFakeKeyEvent(key.macKeyCode, 0, 0, NSFlagsChanged); 191 macEvent = BuildFakeKeyEvent(key.macKeyCode, 0, 0, NSFlagsChanged);
191 webEvent = WebInputEventFactory::keyboardEvent(macEvent); 192 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
192 EXPECT_EQ(WebInputEvent::KeyUp, webEvent.type); 193 EXPECT_EQ(WebInputEvent::KeyUp, webEvent.type);
193 } 194 }
194 } 195 }
196
197 // Test system key events recognition.
198 TEST(WebInputEventFactoryTestMac, SystemKeyEvents)
199 {
200 // Cmd + B should not be treated as system event.
201 NSEvent* macEvent = BuildFakeKeyEvent(kVK_ANSI_B, 'B', NSCommandKeyMask, NSK eyDown);
202 WebKeyboardEvent webEvent = WebInputEventFactory::keyboardEvent(macEvent);
203 EXPECT_FALSE(WebInputEventFactory::isSystemKeyEvent(webEvent));
204
205 // Cmd + I should not be treated as system event.
206 macEvent = BuildFakeKeyEvent(kVK_ANSI_I, 'I', NSCommandKeyMask, NSKeyDown);
207 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
208 EXPECT_FALSE(WebInputEventFactory::isSystemKeyEvent(webEvent));
209
210 // Cmd + <some other modifier> + <B|I> should be treated as system event.
211 macEvent = BuildFakeKeyEvent(kVK_ANSI_B, 'B', NSCommandKeyMask | NSShiftKeyM ask, NSKeyDown);
212 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
213 EXPECT_TRUE(WebInputEventFactory::isSystemKeyEvent(webEvent));
214 macEvent = BuildFakeKeyEvent(kVK_ANSI_I, 'I', NSCommandKeyMask | NSControlKe yMask, NSKeyDown);
215 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
216 EXPECT_TRUE(WebInputEventFactory::isSystemKeyEvent(webEvent));
217
218 // Cmd + <any letter other then B and I> should be treated as system event.
219 macEvent = BuildFakeKeyEvent(kVK_ANSI_S, 'S', NSCommandKeyMask, NSKeyDown);
220 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
221 EXPECT_TRUE(WebInputEventFactory::isSystemKeyEvent(webEvent));
222
223 // Cmd + <some other modifier> + <any letter other then B and I> should be t reated as system event.
224 macEvent = BuildFakeKeyEvent(kVK_ANSI_S, 'S', NSCommandKeyMask | NSShiftKeyM ask, NSKeyDown);
225 webEvent = WebInputEventFactory::keyboardEvent(macEvent);
226 EXPECT_TRUE(WebInputEventFactory::isSystemKeyEvent(webEvent));
227 }
OLDNEW
« no previous file with comments | « Source/web/WebInputEventFactoryMac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698