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 "chrome/browser/ui/views/accelerator_table.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/event_constants.h"
13 #include "ash/accelerators/accelerator_table.h"
21 bool operator()(const AcceleratorMapping
& lhs
,
22 const AcceleratorMapping
& rhs
) const {
23 if (lhs
.keycode
!= rhs
.keycode
)
24 return lhs
.keycode
< rhs
.keycode
;
25 return lhs
.modifiers
< rhs
.modifiers
;
26 // Do not check |command_id|.
32 TEST(AcceleratorTableTest
, CheckDuplicatedAccelerators
) {
33 std::set
<AcceleratorMapping
, Cmp
> accelerators
;
34 const std::vector
<AcceleratorMapping
> accelerator_list(GetAcceleratorList());
35 for (std::vector
<AcceleratorMapping
>::const_iterator it
=
36 accelerator_list
.begin(); it
!= accelerator_list
.end(); ++it
) {
37 const AcceleratorMapping
& entry
= *it
;
38 EXPECT_TRUE(accelerators
.insert(entry
).second
)
39 << "Duplicated accelerator: " << entry
.keycode
<< ", "
40 << (entry
.modifiers
& ui::EF_SHIFT_DOWN
) << ", "
41 << (entry
.modifiers
& ui::EF_CONTROL_DOWN
) << ", "
42 << (entry
.modifiers
& ui::EF_ALT_DOWN
);
46 #if defined(OS_CHROMEOS)
47 TEST(AcceleratorTableTest
, CheckDuplicatedAcceleratorsAsh
) {
48 std::set
<AcceleratorMapping
, Cmp
> accelerators
;
49 const std::vector
<AcceleratorMapping
> accelerator_list(GetAcceleratorList());
50 for (std::vector
<AcceleratorMapping
>::const_iterator it
=
51 accelerator_list
.begin(); it
!= accelerator_list
.end(); ++it
) {
52 const AcceleratorMapping
& entry
= *it
;
53 accelerators
.insert(entry
);
55 for (size_t i
= 0; i
< ash::kAcceleratorDataLength
; ++i
) {
56 const ash::AcceleratorData
& ash_entry
= ash::kAcceleratorData
[i
];
57 if (!ash_entry
.trigger_on_press
)
58 continue; // kAcceleratorMap does not have any release accelerators.
59 // The shortcuts to toggle minimized state, to show the task manager,
60 // to toggle touch HUD, and to open help page are defined on browser side
61 // as well as ash side by design so that web contents can consume these
62 // short cuts. (see crbug.com/309915, 370019, 412435, 321568 and CL)
63 if (ash_entry
.action
== ash::WINDOW_MINIMIZE
||
64 ash_entry
.action
== ash::SHOW_TASK_MANAGER
||
65 ash_entry
.action
== ash::TOUCH_HUD_PROJECTION_TOGGLE
||
66 ash_entry
.action
== ash::OPEN_GET_HELP
)
68 AcceleratorMapping entry
;
69 entry
.keycode
= ash_entry
.keycode
;
70 entry
.modifiers
= ash_entry
.modifiers
;
71 entry
.command_id
= 0; // dummy
72 EXPECT_TRUE(accelerators
.insert(entry
).second
)
73 << "Duplicated accelerator: " << entry
.keycode
<< ", "
74 << (entry
.modifiers
& ui::EF_SHIFT_DOWN
) << ", "
75 << (entry
.modifiers
& ui::EF_CONTROL_DOWN
) << ", "
76 << (entry
.modifiers
& ui::EF_ALT_DOWN
);