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

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

Issue 2439953005: Support NSFlagsChanged in ui::EventFromNative. (Closed)
Patch Set: Unify NSFlagsChanged handling between content and ui/events. Created 4 years, 1 month 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 | « ui/events/cocoa/events_mac.mm ('k') | ui/events/test/cocoa_test_event_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <Carbon/Carbon.h>
5 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
6 #include <stdint.h> 7 #include <stdint.h>
7 8
8 #include <memory> 9 #include <memory>
10 #include <utility>
9 11
10 #include "base/mac/scoped_cftyperef.h" 12 #include "base/mac/scoped_cftyperef.h"
11 #include "base/mac/sdk_forward_declarations.h" 13 #include "base/mac/sdk_forward_declarations.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #import "ui/events/cocoa/cocoa_event_utils.h" 16 #import "ui/events/cocoa/cocoa_event_utils.h"
15 #include "ui/events/event_constants.h" 17 #include "ui/events/event_constants.h"
16 #include "ui/events/event_utils.h" 18 #include "ui/events/event_utils.h"
17 #import "ui/events/test/cocoa_test_event_utils.h" 19 #import "ui/events/test/cocoa_test_event_utils.h"
18 #include "ui/gfx/geometry/point.h" 20 #include "ui/gfx/geometry/point.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ui::ScrollEvent update(ns_events[4]); 492 ui::ScrollEvent update(ns_events[4]);
491 EXPECT_EQ(ui::EventMomentumPhase::INERTIAL_UPDATE, update.momentum_phase()); 493 EXPECT_EQ(ui::EventMomentumPhase::INERTIAL_UPDATE, update.momentum_phase());
492 EXPECT_EQ(momentum_delta_y, update.y_offset_ordinal()); 494 EXPECT_EQ(momentum_delta_y, update.y_offset_ordinal());
493 495
494 ui::ScrollEvent end(ns_events[5]); 496 ui::ScrollEvent end(ns_events[5]);
495 EXPECT_EQ(ui::EventMomentumPhase::END, end.momentum_phase()); 497 EXPECT_EQ(ui::EventMomentumPhase::END, end.momentum_phase());
496 EXPECT_EQ(0, end.y_offset_ordinal()); 498 EXPECT_EQ(0, end.y_offset_ordinal());
497 } 499 }
498 } 500 }
499 501
502 // Check that NSFlagsChanged event is translated to key press or release event.
503 TEST_F(EventsMacTest, HandleModifierOnlyKeyEvents) {
504 struct {
505 const char* description;
506 NSEventModifierFlags modifier_flags;
507 uint16_t key_code;
508 EventType expected_type;
509 KeyboardCode expected_key_code;
510 } test_cases[] = {
511 {"CapsLock pressed", NSAlphaShiftKeyMask, kVK_CapsLock, ET_KEY_PRESSED,
512 VKEY_CAPITAL},
513 {"CapsLock released", 0, kVK_CapsLock, ET_KEY_RELEASED, VKEY_CAPITAL},
514 {"Shift pressed", NSShiftKeyMask, kVK_Shift, ET_KEY_PRESSED, VKEY_SHIFT},
515 {"Shift released", 0, kVK_Shift, ET_KEY_RELEASED, VKEY_SHIFT},
516 {"Control pressed", NSControlKeyMask, kVK_Control, ET_KEY_PRESSED,
517 VKEY_CONTROL},
518 {"Control released", 0, kVK_Control, ET_KEY_RELEASED, VKEY_CONTROL},
519 {"Option pressed", NSAlternateKeyMask, kVK_Option, ET_KEY_PRESSED,
520 VKEY_MENU},
521 {"Option released", 0, kVK_Option, ET_KEY_RELEASED, VKEY_MENU},
522 {"Command pressed", NSCommandKeyMask, kVK_Command, ET_KEY_PRESSED,
523 VKEY_LWIN},
524 {"Command released", 0, kVK_Command, ET_KEY_RELEASED, VKEY_LWIN},
525 {"Shift pressed with CapsLock on", NSShiftKeyMask | NSAlphaShiftKeyMask,
526 kVK_Shift, ET_KEY_PRESSED, VKEY_SHIFT},
527 {"Shift released with CapsLock off", NSAlphaShiftKeyMask, kVK_Shift,
528 ET_KEY_RELEASED, VKEY_SHIFT},
529 };
530 for (const auto& test_case : test_cases) {
531 SCOPED_TRACE(::testing::Message() << "While checking case: "
532 << test_case.description);
533 NSEvent* native_event = cocoa_test_event_utils::KeyEventWithModifierOnly(
534 test_case.key_code, test_case.modifier_flags);
535 std::unique_ptr<ui::Event> event = EventFromNative(native_event);
536 EXPECT_TRUE(event);
537 EXPECT_EQ(test_case.expected_type, event->type());
538 EXPECT_EQ(test_case.expected_key_code, event->AsKeyEvent()->key_code());
539 }
540 }
541
500 } // namespace ui 542 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/cocoa/events_mac.mm ('k') | ui/events/test/cocoa_test_event_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698