| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 13 const size_t kExpectedMappedKeyCount = 138; | 13 const size_t kExpectedMappedKeyCount = 138; |
| 14 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} | 14 #define USB_KEYMAP(usb, xkb, win, mac) {usb, win} |
| 15 #elif defined(OS_LINUX) | 15 #elif defined(OS_LINUX) |
| 16 const size_t kExpectedMappedKeyCount = 143; | 16 const size_t kExpectedMappedKeyCount = 143; |
| 17 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} | 17 #define USB_KEYMAP(usb, xkb, win, mac) {usb, xkb} |
| 18 #elif defined(OS_MACOSX) | 18 #elif defined(OS_MACOSX) |
| 19 const size_t kExpectedMappedKeyCount = 118; | 19 const size_t kExpectedMappedKeyCount = 118; |
| 20 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} | 20 #define USB_KEYMAP(usb, xkb, win, mac) {usb, mac} |
| 21 #else | 21 #else |
| 22 const size_t kExpectedMappedKeyCount = 0; | 22 const size_t kExpectedMappedKeyCount = 0; |
| 23 #define USB_KEYMAP(usb, xkb, win, mac) {usb, 0} | 23 #define USB_KEYMAP(usb, xkb, win, mac) {usb, 0} |
| 24 #endif | 24 #endif |
| 25 #include "ui/base/keycodes/usb_keycode_map.h" | 25 #include "ui/base/keycodes/usb_keycode_map.h" |
| 26 #undef USB_KEYMAP | 26 #undef USB_KEYMAP |
| 27 | 27 |
| 28 const uint32_t kUsbInvalidKeycode = 0x000000; | |
| 29 const uint32_t kUsbNonExistentKeycode = 0xffffff; | 28 const uint32_t kUsbNonExistentKeycode = 0xffffff; |
| 30 const uint32_t kUsbUsBackslash = 0x070031; | 29 const uint32_t kUsbUsBackslash = 0x070031; |
| 31 const uint32_t kUsbNonUsHash = 0x070032; | 30 const uint32_t kUsbNonUsHash = 0x070032; |
| 32 | 31 |
| 33 TEST(UsbKeycodeMap, Basic) { | 32 TEST(UsbKeycodeMap, Basic) { |
| 34 // Verify that the first element in the table is the "invalid" code. | 33 // Verify that the first element in the table is the "invalid" code. |
| 35 EXPECT_EQ(kUsbInvalidKeycode, usb_keycode_map[0].usb_keycode); | 34 EXPECT_EQ(InvalidUsbKeycode(), usb_keycode_map[0].usb_keycode); |
| 36 EXPECT_EQ(kInvalidKeycode, usb_keycode_map[0].native_keycode); | 35 EXPECT_EQ(InvalidNativeKeycode(), usb_keycode_map[0].native_keycode); |
| 37 | 36 |
| 38 // Verify that there are no duplicate entries in the mapping. | 37 // Verify that there are no duplicate entries in the mapping. |
| 39 std::map<uint32_t, uint16_t> usb_to_native; | 38 std::map<uint32_t, uint16_t> usb_to_native; |
| 40 std::map<uint16_t, uint32_t> native_to_usb; | 39 std::map<uint16_t, uint32_t> native_to_usb; |
| 41 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 40 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
| 42 // Don't test keys with no native keycode mapping on this platform. | 41 // Don't test keys with no native keycode mapping on this platform. |
| 43 if (usb_keycode_map[i].native_keycode == kInvalidKeycode) | 42 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) |
| 44 continue; | 43 continue; |
| 45 | 44 |
| 46 // Verify UsbKeycodeToNativeKeycode works for this key. | 45 // Verify UsbKeycodeToNativeKeycode works for this key. |
| 47 EXPECT_EQ(usb_keycode_map[i].native_keycode, | 46 EXPECT_EQ(usb_keycode_map[i].native_keycode, |
| 48 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); | 47 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); |
| 49 | 48 |
| 50 // Verify that the USB or native codes aren't duplicated. | 49 // Verify that the USB or native codes aren't duplicated. |
| 51 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) | 50 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) |
| 52 << " duplicate of USB code 0x" << std::hex << std::setfill('0') | 51 << " duplicate of USB code 0x" << std::hex << std::setfill('0') |
| 53 << std::setw(6) << usb_keycode_map[i].usb_keycode | 52 << std::setw(6) << usb_keycode_map[i].usb_keycode |
| (...skipping 17 matching lines...) Expand all Loading... |
| 71 } | 70 } |
| 72 ASSERT_EQ(usb_to_native.size(), native_to_usb.size()); | 71 ASSERT_EQ(usb_to_native.size(), native_to_usb.size()); |
| 73 | 72 |
| 74 // Verify that the number of mapped keys is what we expect, i.e. we haven't | 73 // Verify that the number of mapped keys is what we expect, i.e. we haven't |
| 75 // lost any, and if we've added some then the expectation has been updated. | 74 // lost any, and if we've added some then the expectation has been updated. |
| 76 EXPECT_EQ(kExpectedMappedKeyCount, usb_to_native.size()); | 75 EXPECT_EQ(kExpectedMappedKeyCount, usb_to_native.size()); |
| 77 } | 76 } |
| 78 | 77 |
| 79 TEST(UsbKeycodeMap, NonExistent) { | 78 TEST(UsbKeycodeMap, NonExistent) { |
| 80 // Verify that UsbKeycodeToNativeKeycode works for a non-existent USB keycode. | 79 // Verify that UsbKeycodeToNativeKeycode works for a non-existent USB keycode. |
| 81 EXPECT_EQ(kInvalidKeycode, UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); | 80 EXPECT_EQ(InvalidNativeKeycode(), |
| 81 UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { | 84 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { |
| 85 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key | 85 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key |
| 86 // as equivalent to the US "backslash" key. | 86 // as equivalent to the US "backslash" key. |
| 87 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), | 87 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), |
| 88 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); | 88 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); |
| 89 | 89 |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| OLD | NEW |