Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 TEST_F(EventsMacTest, NSFlagsChanged) { | |
|
tapted
2016/10/25 06:55:10
test should have a comment above describing its pu
alshabalin
2016/10/28 19:58:13
Done.
| |
| 503 struct { | |
| 504 NSEventModifierFlags modifierFlags; | |
|
tapted
2016/10/25 06:55:10
this isn't between @implementation/@end, so we sho
alshabalin
2016/10/28 19:58:13
Done.
| |
| 505 uint16_t keyCode; | |
| 506 EventType expectedType; | |
| 507 KeyboardCode expectedKeyboardCode; | |
| 508 } test_cases[] = { | |
| 509 // CapsLock. | |
|
tapted
2016/10/25 06:55:10
optional: Perhaps include a const char* member, an
alshabalin
2016/10/28 19:58:13
Good idea, thanks! Done.
| |
| 510 {NSAlphaShiftKeyMask, kVK_CapsLock, ET_KEY_PRESSED, VKEY_CAPITAL}, | |
| 511 {0, kVK_CapsLock, ET_KEY_RELEASED, VKEY_CAPITAL}, | |
| 512 // Shift. | |
| 513 {NSShiftKeyMask, kVK_Shift, ET_KEY_PRESSED, VKEY_SHIFT}, | |
| 514 {0, kVK_Shift, ET_KEY_RELEASED, VKEY_SHIFT}, | |
| 515 // Control. | |
| 516 {NSControlKeyMask, kVK_Control, ET_KEY_PRESSED, VKEY_CONTROL}, | |
| 517 {0, kVK_Control, ET_KEY_RELEASED, VKEY_CONTROL}, | |
| 518 // Option. | |
| 519 {NSAlternateKeyMask, kVK_Option, ET_KEY_PRESSED, VKEY_MENU}, | |
| 520 {0, kVK_Option, ET_KEY_RELEASED, VKEY_MENU}, | |
| 521 // Command. | |
| 522 {NSCommandKeyMask, kVK_Command, ET_KEY_PRESSED, VKEY_LWIN}, | |
| 523 {0, kVK_Command, ET_KEY_RELEASED, VKEY_LWIN}, | |
| 524 // Shift + CapsLock. | |
| 525 {NSShiftKeyMask | NSAlphaShiftKeyMask, kVK_Shift, ET_KEY_PRESSED, | |
| 526 VKEY_SHIFT}, | |
| 527 {NSAlphaShiftKeyMask, kVK_Shift, ET_KEY_RELEASED, VKEY_SHIFT}, | |
| 528 }; | |
| 529 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
|
tapted
2016/10/25 06:55:10
..then here I think you can do `for (const auto& t
| |
| 530 const auto& test_case = test_cases[i]; | |
| 531 SCOPED_TRACE(::testing::Message() << "While checking case #" << i); | |
|
tapted
2016/10/25 06:55:09
... and here output the const char*
| |
| 532 NSEvent* nativeEvent = cocoa_test_event_utils::KeyEventWithModifierOnly( | |
|
tapted
2016/10/25 06:55:10
native_event, or ns_event
alshabalin
2016/10/28 19:58:13
Done.
| |
| 533 test_case.keyCode, test_case.modifierFlags); | |
| 534 auto event = EventFromNative(nativeEvent); | |
|
tapted
2016/10/25 06:55:10
this isn't a good use of `auto` per https://google
alshabalin
2016/10/28 19:58:14
Done.
| |
| 535 EXPECT_TRUE(event); | |
| 536 EXPECT_EQ(test_case.expectedType, event->type()); | |
| 537 EXPECT_EQ(test_case.expectedKeyboardCode, event->AsKeyEvent()->key_code()); | |
| 538 } | |
| 539 } | |
| 540 | |
| 500 } // namespace ui | 541 } // namespace ui |
| OLD | NEW |