Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / events / keyboard_driven_event_rewriter_unittest.cc
blob38a777b4cef7442afe2e80f18fa67eff4229eb9c
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
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/chromeos/events/keyboard_driven_event_rewriter.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/events/event.h"
14 namespace chromeos {
16 class KeyboardDrivenEventRewriterTest : public testing::Test {
17 public:
18 KeyboardDrivenEventRewriterTest() {}
20 ~KeyboardDrivenEventRewriterTest() override {}
22 protected:
23 std::string GetRewrittenEventAsString(ui::KeyboardCode ui_keycode,
24 int ui_flags,
25 ui::EventType ui_type) {
26 ui::KeyEvent keyevent(ui_type, ui_keycode, ui_flags);
27 scoped_ptr<ui::Event> rewritten_event;
28 ui::EventRewriteStatus status =
29 rewriter_.RewriteForTesting(keyevent, &rewritten_event);
30 return base::StringPrintf(
31 "ui_flags=%d status=%d",
32 rewritten_event ? rewritten_event->flags() : keyevent.flags(),
33 status);
36 std::string GetExpectedResultAsString(int ui_flags,
37 ui::EventRewriteStatus status) {
38 return base::StringPrintf("ui_flags=%d status=%u", ui_flags, status);
41 KeyboardDrivenEventRewriter rewriter_;
43 private:
44 DISALLOW_COPY_AND_ASSIGN(KeyboardDrivenEventRewriterTest);
47 TEST_F(KeyboardDrivenEventRewriterTest, PassThrough) {
48 struct {
49 ui::KeyboardCode ui_keycode;
50 int ui_flags;
51 } kTests[] = {
52 { ui::VKEY_A, ui::EF_NONE },
53 { ui::VKEY_A, ui::EF_CONTROL_DOWN },
54 { ui::VKEY_A, ui::EF_ALT_DOWN },
55 { ui::VKEY_A, ui::EF_SHIFT_DOWN },
56 { ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
57 { ui::VKEY_A, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN | ui::EF_SHIFT_DOWN },
59 { ui::VKEY_LEFT, ui::EF_NONE },
60 { ui::VKEY_LEFT, ui::EF_CONTROL_DOWN },
61 { ui::VKEY_LEFT, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
63 { ui::VKEY_RIGHT, ui::EF_NONE },
64 { ui::VKEY_RIGHT, ui::EF_CONTROL_DOWN },
65 { ui::VKEY_RIGHT, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
67 { ui::VKEY_UP, ui::EF_NONE },
68 { ui::VKEY_UP, ui::EF_CONTROL_DOWN },
69 { ui::VKEY_UP, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
71 { ui::VKEY_DOWN, ui::EF_NONE },
72 { ui::VKEY_DOWN, ui::EF_CONTROL_DOWN },
73 { ui::VKEY_DOWN, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
75 { ui::VKEY_RETURN, ui::EF_NONE },
76 { ui::VKEY_RETURN, ui::EF_CONTROL_DOWN },
77 { ui::VKEY_RETURN, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN },
80 for (size_t i = 0; i < arraysize(kTests); ++i) {
81 EXPECT_EQ(GetExpectedResultAsString(kTests[i].ui_flags,
82 ui::EVENT_REWRITE_CONTINUE),
83 GetRewrittenEventAsString(kTests[i].ui_keycode,
84 kTests[i].ui_flags,
85 ui::ET_KEY_PRESSED))
86 << "Test case " << i;
90 TEST_F(KeyboardDrivenEventRewriterTest, Rewrite) {
91 const int kModifierMask = ui::EF_SHIFT_DOWN;
93 struct {
94 ui::KeyboardCode ui_keycode;
95 int ui_flags;
96 } kTests[] = {
97 { ui::VKEY_LEFT, kModifierMask },
98 { ui::VKEY_RIGHT, kModifierMask },
99 { ui::VKEY_UP, kModifierMask },
100 { ui::VKEY_DOWN, kModifierMask },
101 { ui::VKEY_RETURN, kModifierMask },
102 { ui::VKEY_F6, kModifierMask },
105 for (size_t i = 0; i < arraysize(kTests); ++i) {
106 EXPECT_EQ(GetExpectedResultAsString(ui::EF_NONE,
107 ui::EVENT_REWRITE_REWRITTEN),
108 GetRewrittenEventAsString(kTests[i].ui_keycode,
109 kTests[i].ui_flags,
110 ui::ET_KEY_PRESSED))
111 << "Test case " << i;
115 } // namespace chromeos