| OLD | NEW |
| (Empty) |
| 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 "ash/common/accelerators/accelerator_table.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 struct Cmp { | |
| 16 bool operator()(const AcceleratorData& lhs, const AcceleratorData& rhs) { | |
| 17 if (lhs.trigger_on_press != rhs.trigger_on_press) | |
| 18 return lhs.trigger_on_press < rhs.trigger_on_press; | |
| 19 if (lhs.keycode != rhs.keycode) | |
| 20 return lhs.keycode < rhs.keycode; | |
| 21 return lhs.modifiers < rhs.modifiers; | |
| 22 // Do not check |action|. | |
| 23 } | |
| 24 }; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 TEST(AcceleratorTableTest, CheckDuplicatedAccelerators) { | |
| 29 std::set<AcceleratorData, Cmp> accelerators; | |
| 30 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { | |
| 31 const AcceleratorData& entry = kAcceleratorData[i]; | |
| 32 EXPECT_TRUE(accelerators.insert(entry).second) | |
| 33 << "Duplicated accelerator: " << entry.trigger_on_press << ", " | |
| 34 << entry.keycode << ", " << (entry.modifiers & ui::EF_SHIFT_DOWN) | |
| 35 << ", " << (entry.modifiers & ui::EF_CONTROL_DOWN) << ", " | |
| 36 << (entry.modifiers & ui::EF_ALT_DOWN); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 TEST(AcceleratorTableTest, CheckDuplicatedReservedActions) { | |
| 41 std::set<AcceleratorAction> actions; | |
| 42 for (size_t i = 0; i < kReservedActionsLength; ++i) { | |
| 43 EXPECT_TRUE(actions.insert(kReservedActions[i]).second) | |
| 44 << "Duplicated action: " << kReservedActions[i]; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 TEST(AcceleratorTableTest, CheckDuplicatedActionsAllowedAtLoginOrLockScreen) { | |
| 49 std::set<AcceleratorAction> actions; | |
| 50 for (size_t i = 0; i < kActionsAllowedAtLoginOrLockScreenLength; ++i) { | |
| 51 EXPECT_TRUE(actions.insert(kActionsAllowedAtLoginOrLockScreen[i]).second) | |
| 52 << "Duplicated action: " << kActionsAllowedAtLoginOrLockScreen[i]; | |
| 53 } | |
| 54 for (size_t i = 0; i < kActionsAllowedAtLockScreenLength; ++i) { | |
| 55 EXPECT_TRUE(actions.insert(kActionsAllowedAtLockScreen[i]).second) | |
| 56 << "Duplicated action: " << kActionsAllowedAtLockScreen[i]; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 TEST(AcceleratorTableTest, CheckDuplicatedActionsAllowedAtModalWindow) { | |
| 61 std::set<AcceleratorAction> actions; | |
| 62 for (size_t i = 0; i < kActionsAllowedAtModalWindowLength; ++i) { | |
| 63 EXPECT_TRUE(actions.insert(kActionsAllowedAtModalWindow[i]).second) | |
| 64 << "Duplicated action: " << kActionsAllowedAtModalWindow[i] | |
| 65 << " at index: " << i; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 TEST(AcceleratorTableTest, CheckDuplicatedRepeatableActions) { | |
| 70 std::set<AcceleratorAction> actions; | |
| 71 for (size_t i = 0; i < kRepeatableActionsLength; ++i) { | |
| 72 EXPECT_TRUE(actions.insert(kRepeatableActions[i]).second) | |
| 73 << "Duplicated action: " << kRepeatableActions[i] << " at index: " << i; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 TEST(AcceleratorTableTest, CheckDeprecatedAccelerators) { | |
| 78 std::set<AcceleratorData, Cmp> deprecated_actions; | |
| 79 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { | |
| 80 // A deprecated action can never appear twice in the list. | |
| 81 const AcceleratorData& entry = kDeprecatedAccelerators[i]; | |
| 82 EXPECT_TRUE(deprecated_actions.insert(entry).second) | |
| 83 << "Duplicate deprecated accelerator: " << entry.trigger_on_press | |
| 84 << ", " << entry.keycode << ", " | |
| 85 << (entry.modifiers & ui::EF_SHIFT_DOWN) << ", " | |
| 86 << (entry.modifiers & ui::EF_CONTROL_DOWN) << ", " | |
| 87 << (entry.modifiers & ui::EF_ALT_DOWN); | |
| 88 } | |
| 89 | |
| 90 std::set<AcceleratorAction> actions; | |
| 91 for (size_t i = 0; i < kDeprecatedAcceleratorsDataLength; ++i) { | |
| 92 // There must never be any duplicated actions. | |
| 93 const DeprecatedAcceleratorData& data = kDeprecatedAcceleratorsData[i]; | |
| 94 EXPECT_TRUE(actions.insert(data.action).second) << "Deprecated action: " | |
| 95 << data.action; | |
| 96 | |
| 97 // The UMA histogram name must be of the format "Ash.Accelerators.*" | |
| 98 std::string uma_histogram(data.uma_histogram_name); | |
| 99 EXPECT_TRUE(base::StartsWith(uma_histogram, "Ash.Accelerators.", | |
| 100 base::CompareCase::SENSITIVE)); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 } // namespace ash | |
| OLD | NEW |