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

Side by Side Diff: content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm

Issue 1374933002: Fix false negatives in system key events recognition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « content/browser/renderer_host/input/web_input_event_builders_mac.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 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "content/browser/renderer_host/input/web_input_event_builders_mac.h" 5 #include "content/browser/renderer_host/input/web_input_event_builders_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <Carbon/Carbon.h>
8 9
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/keycodes/dom/dom_code.h" 11 #include "ui/events/keycodes/dom/dom_code.h"
11 #include "ui/events/keycodes/dom/dom_key.h" 12 #include "ui/events/keycodes/dom/dom_key.h"
12 #include "ui/events/keycodes/keyboard_codes.h" 13 #include "ui/events/keycodes/keyboard_codes.h"
13 14
14 using blink::WebKeyboardEvent; 15 using blink::WebKeyboardEvent;
15 using blink::WebInputEvent; 16 using blink::WebInputEvent;
16 using content::WebKeyboardEventBuilder; 17 using content::WebKeyboardEventBuilder;
17 18
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const ModifierKey& key = kModifierKeys[i]; 201 const ModifierKey& key = kModifierKeys[i];
201 NSEvent* mac_event = BuildFakeKeyEvent( 202 NSEvent* mac_event = BuildFakeKeyEvent(
202 key.mac_key_code, 0, key.non_specific_mask, NSFlagsChanged); 203 key.mac_key_code, 0, key.non_specific_mask, NSFlagsChanged);
203 WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event); 204 WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event);
204 EXPECT_EQ(WebInputEvent::RawKeyDown, web_event.type); 205 EXPECT_EQ(WebInputEvent::RawKeyDown, web_event.type);
205 mac_event = BuildFakeKeyEvent(key.mac_key_code, 0, 0, NSFlagsChanged); 206 mac_event = BuildFakeKeyEvent(key.mac_key_code, 0, 0, NSFlagsChanged);
206 web_event = WebKeyboardEventBuilder::Build(mac_event); 207 web_event = WebKeyboardEventBuilder::Build(mac_event);
207 EXPECT_EQ(WebInputEvent::KeyUp, web_event.type); 208 EXPECT_EQ(WebInputEvent::KeyUp, web_event.type);
208 } 209 }
209 } 210 }
211
212 // Test system key events recognition.
213 TEST(WebInputEventBuilderMacTest, SystemKeyEvents) {
214 // Cmd + B should not be treated as system event.
215 NSEvent* macEvent =
216 BuildFakeKeyEvent(kVK_ANSI_B, 'B', NSCommandKeyMask, NSKeyDown);
217 WebKeyboardEvent webEvent = WebKeyboardEventBuilder::Build(macEvent);
218 EXPECT_FALSE(webEvent.isSystemKey);
219
220 // Cmd + I should not be treated as system event.
221 macEvent = BuildFakeKeyEvent(kVK_ANSI_I, 'I', NSCommandKeyMask, NSKeyDown);
222 webEvent = WebKeyboardEventBuilder::Build(macEvent);
223 EXPECT_FALSE(webEvent.isSystemKey);
224
225 // Cmd + <some other modifier> + <B|I> should be treated as system event.
226 macEvent = BuildFakeKeyEvent(kVK_ANSI_B, 'B',
227 NSCommandKeyMask | NSShiftKeyMask, NSKeyDown);
228 webEvent = WebKeyboardEventBuilder::Build(macEvent);
229 EXPECT_TRUE(webEvent.isSystemKey);
230 macEvent = BuildFakeKeyEvent(kVK_ANSI_I, 'I',
231 NSCommandKeyMask | NSControlKeyMask, NSKeyDown);
232 webEvent = WebKeyboardEventBuilder::Build(macEvent);
233 EXPECT_TRUE(webEvent.isSystemKey);
234
235 // Cmd + <any letter other then B and I> should be treated as system event.
236 macEvent = BuildFakeKeyEvent(kVK_ANSI_S, 'S', NSCommandKeyMask, NSKeyDown);
237 webEvent = WebKeyboardEventBuilder::Build(macEvent);
238 EXPECT_TRUE(webEvent.isSystemKey);
239
240 // Cmd + <some other modifier> + <any letter other then B and I> should be
241 // treated as system event.
242 macEvent = BuildFakeKeyEvent(kVK_ANSI_S, 'S',
243 NSCommandKeyMask | NSShiftKeyMask, NSKeyDown);
244 webEvent = WebKeyboardEventBuilder::Build(macEvent);
245 EXPECT_TRUE(webEvent.isSystemKey);
246 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698