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 #include "chrome/browser/chromeos/events/event_rewriter.h" | 5 #include "chrome/browser/chromeos/events/event_rewriter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/sticky_keys/sticky_keys_controller.h" | 10 #include "ash/sticky_keys/sticky_keys_controller.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // Verify that the X11-based key event is as expected. | 108 // Verify that the X11-based key event is as expected. |
109 EXPECT_EQ(GetExpectedResultAsString( | 109 EXPECT_EQ(GetExpectedResultAsString( |
110 test.input.key_code, test.input.flags, test.type), | 110 test.input.key_code, test.input.flags, test.type), |
111 GetKeyEventAsString(xkey_event)); | 111 GetKeyEventAsString(xkey_event)); |
112 // Rewrite the event and check the result. | 112 // Rewrite the event and check the result. |
113 scoped_ptr<ui::Event> new_event; | 113 scoped_ptr<ui::Event> new_event; |
114 rewriter->RewriteEvent(xkey_event, &new_event); | 114 rewriter->RewriteEvent(xkey_event, &new_event); |
115 ui::KeyEvent& rewritten_key_event = | 115 ui::KeyEvent& rewritten_key_event = |
116 new_event ? *static_cast<ui::KeyEvent*>(new_event.get()) : xkey_event; | 116 new_event ? *static_cast<ui::KeyEvent*>(new_event.get()) : xkey_event; |
117 EXPECT_EQ(expected, GetKeyEventAsString(rewritten_key_event)); | 117 EXPECT_EQ(expected, GetKeyEventAsString(rewritten_key_event)); |
118 if (xevent->type == GenericEvent) | 118 if ((rewritten_key_event.key_code() != ui::VKEY_UNKNOWN) && |
119 EXPECT_EQ(nullptr, rewritten_key_event.native_event()); | 119 (rewritten_key_event.native_event()->xkey.keycode != 0)) { |
120 else | 120 // Build a new ui::KeyEvent from the rewritten native component, |
121 EXPECT_NE(nullptr, rewritten_key_event.native_event()); | 121 // and check that it also matches the rewritten event. |
| 122 EXPECT_TRUE(rewritten_key_event.native_event()); |
| 123 ui::KeyEvent from_native_event(rewritten_key_event.native_event()); |
| 124 EXPECT_EQ(expected, GetKeyEventAsString(from_native_event)); |
| 125 } |
122 } | 126 } |
123 #endif | 127 #endif |
124 | 128 |
125 // Tests a single stateless key rewrite operation. | 129 // Tests a single stateless key rewrite operation. |
126 // |i| is a an identifying number to locate failing tests in the tables. | 130 // |i| is a an identifying number to locate failing tests in the tables. |
127 void CheckKeyTestCase(chromeos::EventRewriter* rewriter, | 131 void CheckKeyTestCase(chromeos::EventRewriter* rewriter, |
128 const KeyTestCase& test) { | 132 const KeyTestCase& test) { |
129 std::string expected = | 133 std::string expected = |
130 GetExpectedResultAsString( | 134 GetExpectedResultAsString( |
131 test.expected.key_code, test.expected.flags, test.type); | 135 test.expected.key_code, test.expected.flags, test.type); |
(...skipping 2329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2461 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2465 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2462 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2466 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2463 | 2467 |
2464 // Turn off AltGr and Mod3. | 2468 // Turn off AltGr and Mod3. |
2465 sticky_keys_controller_->SetModifiersEnabled(false, false); | 2469 sticky_keys_controller_->SetModifiersEnabled(false, false); |
2466 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2470 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2467 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2471 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2468 } | 2472 } |
2469 | 2473 |
2470 } // namespace chromeos | 2474 } // namespace chromeos |
OLD | NEW |