OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/events/keycodes/dom4/keycode_converter.h" | 5 #include "ui/events/keycodes/dom4/keycode_converter.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 const size_t kExpectedMappedKeyCount = 118; | 21 const size_t kExpectedMappedKeyCount = 118; |
22 #else | 22 #else |
23 const size_t kExpectedMappedKeyCount = 0; | 23 const size_t kExpectedMappedKeyCount = 0; |
24 #endif | 24 #endif |
25 | 25 |
26 const uint32_t kUsbNonExistentKeycode = 0xffffff; | 26 const uint32_t kUsbNonExistentKeycode = 0xffffff; |
27 const uint32_t kUsbUsBackslash = 0x070031; | 27 const uint32_t kUsbUsBackslash = 0x070031; |
28 const uint32_t kUsbNonUsHash = 0x070032; | 28 const uint32_t kUsbNonUsHash = 0x070032; |
29 | 29 |
30 TEST(UsbKeycodeMap, Basic) { | 30 TEST(UsbKeycodeMap, Basic) { |
31 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); | |
32 // Verify that the first element in the table is the "invalid" code. | 31 // Verify that the first element in the table is the "invalid" code. |
33 const ui::KeycodeMapEntry* keycode_map = | 32 const ui::KeycodeMapEntry* keycode_map = |
34 key_converter->GetKeycodeMapForTest(); | 33 ui::KeycodeConverter::GetKeycodeMapForTest(); |
35 EXPECT_EQ(key_converter->InvalidUsbKeycode(), keycode_map[0].usb_keycode); | 34 EXPECT_EQ(ui::KeycodeConverter::InvalidUsbKeycode(), |
36 EXPECT_EQ(key_converter->InvalidNativeKeycode(), | 35 keycode_map[0].usb_keycode); |
| 36 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), |
37 keycode_map[0].native_keycode); | 37 keycode_map[0].native_keycode); |
38 EXPECT_STREQ(key_converter->InvalidKeyboardEventCode(), "Unidentified"); | 38 EXPECT_STREQ(ui::KeycodeConverter::InvalidKeyboardEventCode(), |
39 EXPECT_EQ(key_converter->InvalidNativeKeycode(), | 39 "Unidentified"); |
40 key_converter->CodeToNativeKeycode("Unidentified")); | 40 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), |
| 41 ui::KeycodeConverter::CodeToNativeKeycode("Unidentified")); |
41 | 42 |
42 // Verify that there are no duplicate entries in the mapping. | 43 // Verify that there are no duplicate entries in the mapping. |
43 std::map<uint32_t, uint16_t> usb_to_native; | 44 std::map<uint32_t, uint16_t> usb_to_native; |
44 std::map<uint16_t, uint32_t> native_to_usb; | 45 std::map<uint16_t, uint32_t> native_to_usb; |
45 size_t numEntries = key_converter->NumKeycodeMapEntriesForTest(); | 46 size_t numEntries = ui::KeycodeConverter::NumKeycodeMapEntriesForTest(); |
46 for (size_t i = 0; i < numEntries; ++i) { | 47 for (size_t i = 0; i < numEntries; ++i) { |
47 const ui::KeycodeMapEntry* entry = &keycode_map[i]; | 48 const ui::KeycodeMapEntry* entry = &keycode_map[i]; |
48 // Don't test keys with no native keycode mapping on this platform. | 49 // Don't test keys with no native keycode mapping on this platform. |
49 if (entry->native_keycode == key_converter->InvalidNativeKeycode()) | 50 if (entry->native_keycode == ui::KeycodeConverter::InvalidNativeKeycode()) |
50 continue; | 51 continue; |
51 | 52 |
52 // Verify UsbKeycodeToNativeKeycode works for this key. | 53 // Verify UsbKeycodeToNativeKeycode works for this key. |
53 EXPECT_EQ(entry->native_keycode, | 54 EXPECT_EQ( |
54 key_converter->UsbKeycodeToNativeKeycode(entry->usb_keycode)); | 55 entry->native_keycode, |
| 56 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(entry->usb_keycode)); |
55 | 57 |
56 // Verify CodeToNativeKeycode and NativeKeycodeToCode work correctly. | 58 // Verify CodeToNativeKeycode and NativeKeycodeToCode work correctly. |
57 if (entry->code) { | 59 if (entry->code) { |
58 EXPECT_EQ(entry->native_keycode, | 60 EXPECT_EQ(entry->native_keycode, |
59 key_converter->CodeToNativeKeycode(entry->code)); | 61 ui::KeycodeConverter::CodeToNativeKeycode(entry->code)); |
60 EXPECT_STREQ(entry->code, | 62 EXPECT_STREQ( |
61 key_converter->NativeKeycodeToCode(entry->native_keycode)); | 63 entry->code, |
| 64 ui::KeycodeConverter::NativeKeycodeToCode(entry->native_keycode)); |
62 } | 65 } |
63 else { | 66 else { |
64 EXPECT_EQ(key_converter->InvalidNativeKeycode(), | 67 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), |
65 key_converter->CodeToNativeKeycode(entry->code)); | 68 ui::KeycodeConverter::CodeToNativeKeycode(entry->code)); |
66 } | 69 } |
67 | 70 |
68 // Verify that the USB or native codes aren't duplicated. | 71 // Verify that the USB or native codes aren't duplicated. |
69 EXPECT_EQ(0U, usb_to_native.count(entry->usb_keycode)) | 72 EXPECT_EQ(0U, usb_to_native.count(entry->usb_keycode)) |
70 << " duplicate of USB code 0x" << std::hex << std::setfill('0') | 73 << " duplicate of USB code 0x" << std::hex << std::setfill('0') |
71 << std::setw(6) << entry->usb_keycode | 74 << std::setw(6) << entry->usb_keycode |
72 << " to native 0x" | 75 << " to native 0x" |
73 << std::setw(4) << entry->native_keycode | 76 << std::setw(4) << entry->native_keycode |
74 << " (previous was 0x" | 77 << " (previous was 0x" |
75 << std::setw(4) << usb_to_native[entry->usb_keycode] | 78 << std::setw(4) << usb_to_native[entry->usb_keycode] |
(...skipping 11 matching lines...) Expand all Loading... |
87 } | 90 } |
88 ASSERT_EQ(usb_to_native.size(), native_to_usb.size()); | 91 ASSERT_EQ(usb_to_native.size(), native_to_usb.size()); |
89 | 92 |
90 // Verify that the number of mapped keys is what we expect, i.e. we haven't | 93 // Verify that the number of mapped keys is what we expect, i.e. we haven't |
91 // lost any, and if we've added some then the expectation has been updated. | 94 // lost any, and if we've added some then the expectation has been updated. |
92 EXPECT_EQ(kExpectedMappedKeyCount, usb_to_native.size()); | 95 EXPECT_EQ(kExpectedMappedKeyCount, usb_to_native.size()); |
93 } | 96 } |
94 | 97 |
95 TEST(UsbKeycodeMap, NonExistent) { | 98 TEST(UsbKeycodeMap, NonExistent) { |
96 // Verify that UsbKeycodeToNativeKeycode works for a non-existent USB keycode. | 99 // Verify that UsbKeycodeToNativeKeycode works for a non-existent USB keycode. |
97 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); | 100 EXPECT_EQ( |
98 EXPECT_EQ(key_converter->InvalidNativeKeycode(), | 101 ui::KeycodeConverter::InvalidNativeKeycode(), |
99 key_converter->UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); | 102 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(kUsbNonExistentKeycode)); |
100 } | 103 } |
101 | 104 |
102 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { | 105 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { |
103 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key | 106 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key |
104 // as equivalent to the US "backslash" key. | 107 // as equivalent to the US "backslash" key. |
105 ui::KeycodeConverter* key_converter = ui::KeycodeConverter::GetInstance(); | 108 EXPECT_EQ(ui::KeycodeConverter::UsbKeycodeToNativeKeycode(kUsbUsBackslash), |
106 EXPECT_EQ(key_converter->UsbKeycodeToNativeKeycode(kUsbUsBackslash), | 109 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(kUsbNonUsHash)); |
107 key_converter->UsbKeycodeToNativeKeycode(kUsbNonUsHash)); | |
108 } | 110 } |
109 | 111 |
110 } // namespace | 112 } // namespace |
OLD | NEW |