Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / accelerator_table_unittest.cc
blob3984a3854236662fc869d73381a6cfa47edaa03a
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.
5 #include <set>
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"
12 #if defined(USE_ASH)
13 #include "ash/accelerators/accelerator_table.h"
14 #endif // USE_ASH
16 namespace chrome {
18 namespace {
20 struct Cmp {
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|.
30 } // namespace
32 TEST(AcceleratorTableTest, CheckDuplicatedAccelerators) {
33 std::set<AcceleratorMapping, Cmp> acclerators;
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(acclerators.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(USE_ASH) && !defined(OS_WIN)
47 TEST(AcceleratorTableTest, CheckDuplicatedAcceleratorsAsh) {
48 std::set<AcceleratorMapping, Cmp> acclerators;
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 acclerators.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 shortcut to toggle minimized state is defined on both ends
60 // by design. (see crbug.com/309915 and CL)
61 if (ash_entry.action == ash::WINDOW_MINIMIZE)
62 continue;
63 AcceleratorMapping entry;
64 entry.keycode = ash_entry.keycode;
65 entry.modifiers = ash_entry.modifiers;
66 entry.command_id = 0; // dummy
67 EXPECT_TRUE(acclerators.insert(entry).second)
68 << "Duplicated accelerator: " << entry.keycode << ", "
69 << (entry.modifiers & ui::EF_SHIFT_DOWN) << ", "
70 << (entry.modifiers & ui::EF_CONTROL_DOWN) << ", "
71 << (entry.modifiers & ui::EF_ALT_DOWN);
74 #endif // USE_ASH
76 } // namespace chrome