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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/chromeos/keyboard_driven_event_rewriter.h" | 8 #include "chrome/browser/chromeos/keyboard_driven_event_rewriter.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/x/x11_util.h" | 10 #include "ui/base/x/x11_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ui_keycode, | 28 ui_keycode, |
29 ui_flags, | 29 ui_flags, |
30 event); | 30 event); |
31 event->xkey.keycode = x_keycode; | 31 event->xkey.keycode = x_keycode; |
32 event->xkey.state = x_state; | 32 event->xkey.state = x_state; |
33 } | 33 } |
34 | 34 |
35 class KeyboardDrivenEventRewriterTest : public testing::Test { | 35 class KeyboardDrivenEventRewriterTest : public testing::Test { |
36 public: | 36 public: |
37 KeyboardDrivenEventRewriterTest() | 37 KeyboardDrivenEventRewriterTest() |
38 : display_(ui::GetXDisplay()), | 38 : display_(gfx::GetXDisplay()), |
39 keycode_a_(XKeysymToKeycode(display_, XK_a)), | 39 keycode_a_(XKeysymToKeycode(display_, XK_a)), |
40 keycode_up_(XKeysymToKeycode(display_, XK_Up)), | 40 keycode_up_(XKeysymToKeycode(display_, XK_Up)), |
41 keycode_down_(XKeysymToKeycode(display_, XK_Down)), | 41 keycode_down_(XKeysymToKeycode(display_, XK_Down)), |
42 keycode_left_(XKeysymToKeycode(display_, XK_Left)), | 42 keycode_left_(XKeysymToKeycode(display_, XK_Left)), |
43 keycode_right_(XKeysymToKeycode(display_, XK_Right)), | 43 keycode_right_(XKeysymToKeycode(display_, XK_Right)), |
44 keycode_return_(XKeysymToKeycode(display_, XK_Return)) { | 44 keycode_return_(XKeysymToKeycode(display_, XK_Return)) { |
45 } | 45 } |
46 | 46 |
47 virtual ~KeyboardDrivenEventRewriterTest() {} | 47 virtual ~KeyboardDrivenEventRewriterTest() {} |
48 | 48 |
49 protected: | 49 protected: |
50 std::string GetRewrittenEventAsString(ui::KeyboardCode ui_keycode, | 50 std::string GetRewrittenEventAsString(ui::KeyboardCode ui_keycode, |
51 int ui_flags, | 51 int ui_flags, |
52 ui::EventType ui_type, | 52 ui::EventType ui_type, |
53 KeyCode x_keycode, | 53 KeyCode x_keycode, |
54 unsigned int x_state) { | 54 unsigned int x_state) { |
55 XEvent xev; | 55 XEvent xev; |
56 InitXKeyEvent(ui_keycode, ui_flags, ui_type, x_keycode, x_state, &xev); | 56 InitXKeyEvent(ui_keycode, ui_flags, ui_type, x_keycode, x_state, &xev); |
57 ui::KeyEvent keyevent(&xev, false /* is_char */); | 57 ui::KeyEvent keyevent(&xev, false /* is_char */); |
58 rewriter_.RewriteForTesting(&keyevent); | 58 rewriter_.RewriteForTesting(&keyevent); |
59 return base::StringPrintf( | 59 return base::StringPrintf( |
60 "ui_flags=%d x_state=%u", keyevent.flags(), xev.xkey.state); | 60 "ui_flags=%d x_state=%u", keyevent.flags(), xev.xkey.state); |
61 } | 61 } |
62 | 62 |
63 std::string GetExpectedResultAsString(int ui_flags, unsigned int x_state) { | 63 std::string GetExpectedResultAsString(int ui_flags, unsigned int x_state) { |
64 return base::StringPrintf("ui_flags=%d x_state=%u", ui_flags, x_state); | 64 return base::StringPrintf("ui_flags=%d x_state=%u", ui_flags, x_state); |
65 } | 65 } |
66 | 66 |
67 Display* display_; | 67 XDisplay* display_; |
68 const KeyCode keycode_a_; | 68 const KeyCode keycode_a_; |
69 const KeyCode keycode_up_; | 69 const KeyCode keycode_up_; |
70 const KeyCode keycode_down_; | 70 const KeyCode keycode_down_; |
71 const KeyCode keycode_left_; | 71 const KeyCode keycode_left_; |
72 const KeyCode keycode_right_; | 72 const KeyCode keycode_right_; |
73 const KeyCode keycode_return_; | 73 const KeyCode keycode_return_; |
74 | 74 |
75 KeyboardDrivenEventRewriter rewriter_; | 75 KeyboardDrivenEventRewriter rewriter_; |
76 | 76 |
77 private: | 77 private: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 GetRewrittenEventAsString(kTests[i].ui_keycode, | 154 GetRewrittenEventAsString(kTests[i].ui_keycode, |
155 kTests[i].ui_flags, | 155 kTests[i].ui_flags, |
156 ui::ET_KEY_PRESSED, | 156 ui::ET_KEY_PRESSED, |
157 kTests[i].x_keycode, | 157 kTests[i].x_keycode, |
158 kTests[i].x_state)) | 158 kTests[i].x_state)) |
159 << "Test case " << i; | 159 << "Test case " << i; |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 } // namespace chromeos | 163 } // namespace chromeos |
OLD | NEW |