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.
4
5#include <set>
6
7#include "base/basictypes.h"
8#include "ash/accelerators/accelerator_table.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace ash {
12
13namespace {
14
15struct Cmp {
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|.
24  }
25};
26
27}  // namespace
28
29TEST(AcceleratorTableTest, CheckDuplicatedAccelerators) {
30  std::set<AcceleratorData, Cmp> acclerators;
31  for (size_t i = 0; i < kAcceleratorDataLength; ++i) {
32    const AcceleratorData& entry = kAcceleratorData[i];
33    EXPECT_TRUE(acclerators.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);
38  }
39}
40
41TEST(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];
46  }
47}
48
49TEST(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];
54  }
55  for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) {
56    EXPECT_TRUE(actions.insert(kActionsAllowedAtLockScreen[i]).second)
57        << "Duplicated action: " << kActionsAllowedAtLockScreen[i];
58  }
59}
60
61TEST(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;
67  }
68}
69
70TEST(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;
76  }
77}
78
79}  // namespace ash
80