1 // Copyright (c) 2012 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.
7 #include "base/basictypes.h"
8 #include "ash/accelerators/accelerator_table.h"
9 #include "testing/gtest/include/gtest/gtest.h"
16 bool operator()(const AcceleratorData
& lhs
,
17 const AcceleratorData
& rhs
) {
18 if (lhs
.trigger_on_press
!= rhs
.trigger_on_press
)
19 return lhs
.trigger_on_press
< rhs
.trigger_on_press
;
20 if (lhs
.keycode
!= rhs
.keycode
)
21 return lhs
.keycode
< rhs
.keycode
;
22 return lhs
.modifiers
< rhs
.modifiers
;
23 // Do not check |action|.
29 TEST(AcceleratorTableTest
, CheckDuplicatedAccelerators
) {
30 std::set
<AcceleratorData
, Cmp
> accelerators
;
31 for (size_t i
= 0; i
< kAcceleratorDataLength
; ++i
) {
32 const AcceleratorData
& entry
= kAcceleratorData
[i
];
33 EXPECT_TRUE(accelerators
.insert(entry
).second
)
34 << "Duplicated accelerator: " << entry
.trigger_on_press
<< ", "
35 << entry
.keycode
<< ", " << (entry
.modifiers
& ui::EF_SHIFT_DOWN
)
36 << ", " << (entry
.modifiers
& ui::EF_CONTROL_DOWN
) << ", "
37 << (entry
.modifiers
& ui::EF_ALT_DOWN
);
41 TEST(AcceleratorTableTest
, CheckDuplicatedReservedActions
) {
42 std::set
<AcceleratorAction
> actions
;
43 for (size_t i
= 0; i
< kReservedActionsLength
; ++i
) {
44 EXPECT_TRUE(actions
.insert(kReservedActions
[i
]).second
)
45 << "Duplicated action: " << kReservedActions
[i
];
49 TEST(AcceleratorTableTest
, CheckDuplicatedActionsAllowedAtLoginOrLockScreen
) {
50 std::set
<AcceleratorAction
> actions
;
51 for (size_t i
= 0; i
< kActionsAllowedAtLoginOrLockScreenLength
; ++i
) {
52 EXPECT_TRUE(actions
.insert(kActionsAllowedAtLoginOrLockScreen
[i
]).second
)
53 << "Duplicated action: " << kActionsAllowedAtLoginOrLockScreen
[i
];
55 for (size_t i
= 0; i
< kActionsAllowedAtLockScreenLength
; ++i
) {
56 EXPECT_TRUE(actions
.insert(kActionsAllowedAtLockScreen
[i
]).second
)
57 << "Duplicated action: " << kActionsAllowedAtLockScreen
[i
];
61 TEST(AcceleratorTableTest
, CheckDuplicatedActionsAllowedAtModalWindow
) {
62 std::set
<AcceleratorAction
> actions
;
63 for (size_t i
= 0; i
< kActionsAllowedAtModalWindowLength
; ++i
) {
64 EXPECT_TRUE(actions
.insert(kActionsAllowedAtModalWindow
[i
]).second
)
65 << "Duplicated action: " << kActionsAllowedAtModalWindow
[i
]
66 << " at index: " << i
;
70 TEST(AcceleratorTableTest
, CheckDuplicatedNonrepeatableActions
) {
71 std::set
<AcceleratorAction
> actions
;
72 for (size_t i
= 0; i
< kNonrepeatableActionsLength
; ++i
) {
73 EXPECT_TRUE(actions
.insert(kNonrepeatableActions
[i
]).second
)
74 << "Duplicated action: " << kNonrepeatableActions
[i
]
75 << " at index: " << i
;
79 #if defined(OS_CHROMEOS)
81 TEST(AcceleratorTableTest
, CheckDeprecatedAccelerators
) {
82 std::set
<AcceleratorAction
> deprecated_actions
;
83 for (size_t i
= 0; i
< kDeprecatedAcceleratorsLength
; ++i
) {
84 // A deprecated action can never appear twice in the list.
85 AcceleratorAction deprecated_action
=
86 kDeprecatedAccelerators
[i
].deprecated_accelerator
.action
;
87 EXPECT_TRUE(deprecated_actions
.insert(deprecated_action
).second
)
88 << "Duplicated action: " << deprecated_action
<< " at index: " << i
;
90 // The UMA histogram name must be of the format "Ash.Accelerators.*"
91 std::string
uma_histogram(kDeprecatedAccelerators
[i
].uma_histogram_name
);
92 EXPECT_TRUE(uma_histogram
.find("Ash.Accelerators.") != std::string::npos
);
93 EXPECT_TRUE(uma_histogram
.find("Ash.Accelerators.") == 0);
97 #endif // defined(OS_CHROMEOS)