1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
ash / webui / shortcut_customization_ui / mojom / shortcut_customization_mojom_traits_unittest.cc [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/webui/shortcut_customization_ui/mojom/shortcut_customization_mojom_traits.h"
#include "ash/webui/shortcut_customization_ui/mojom/shortcut_customization.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
namespace ash {
using ash::shortcut_customization::mojom::SimpleAccelerator;
class ShortcutCustomizationStructTraitsTest : public testing::Test {
public:
ShortcutCustomizationStructTraitsTest() = default;
~ShortcutCustomizationStructTraitsTest() override = default;
};
TEST_F(ShortcutCustomizationStructTraitsTest,
SerializeAndDeserializeValidModifiers) {
ui::Accelerator accelerator(ui::KeyboardCode::VKEY_TAB, ui::EF_CONTROL_DOWN,
ui::Accelerator::KeyState::RELEASED);
ui::Accelerator deserialized;
ASSERT_TRUE(SimpleAccelerator::Deserialize(
SimpleAccelerator::Serialize(&accelerator), &deserialized));
EXPECT_EQ(accelerator, deserialized);
}
TEST_F(ShortcutCustomizationStructTraitsTest,
SerializeAndDeserializeInvalidModifiers) {
ui::Accelerator accelerator(ui::KeyboardCode::VKEY_TAB,
ui::EF_CONTROL_DOWN | ui::EF_IME_FABRICATED_KEY);
// `EF_IME_FABRICATED_KEY` is an invalid modifier, it verify it was stripped
// off after serializing/deserializing.
ui::Accelerator expected_accelerator(
ui::KeyboardCode::VKEY_TAB,
ui::EF_CONTROL_DOWN | ui::EF_IME_FABRICATED_KEY);
ui::Accelerator deserialized;
ASSERT_TRUE(SimpleAccelerator::Deserialize(
SimpleAccelerator::Serialize(&accelerator), &deserialized));
EXPECT_EQ(expected_accelerator, deserialized);
}
} // namespace ash