| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace ash { | 11 namespace ash { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 struct Cmp { | 15 struct Cmp { |
| 16 bool operator()(const AcceleratorData& lhs, | 16 bool operator()(const AcceleratorData& lhs, |
| 17 const AcceleratorData& rhs) { | 17 const AcceleratorData& rhs) { |
| 18 if (lhs.trigger_on_press != rhs.trigger_on_press) | 18 if (lhs.trigger_on_press != rhs.trigger_on_press) |
| 19 return lhs.trigger_on_press < rhs.trigger_on_press; | 19 return lhs.trigger_on_press < rhs.trigger_on_press; |
| 20 if (lhs.keycode != rhs.keycode) | 20 if (lhs.keycode != rhs.keycode) |
| 21 return lhs.keycode < rhs.keycode; | 21 return lhs.keycode < rhs.keycode; |
| 22 if (lhs.shift != rhs.shift) | 22 return lhs.modifiers < rhs.modifiers; |
| 23 return lhs.shift < rhs.shift; | |
| 24 if (lhs.ctrl != rhs.ctrl) | |
| 25 return lhs.ctrl < rhs.ctrl; | |
| 26 return lhs.alt < rhs.alt; | |
| 27 // Do not check |action|. | 23 // Do not check |action|. |
| 28 } | 24 } |
| 29 }; | 25 }; |
| 30 | 26 |
| 31 } // namespace | 27 } // namespace |
| 32 | 28 |
| 33 TEST(AcceleratorTableTest, CheckDuplicatedAccelerators) { | 29 TEST(AcceleratorTableTest, CheckDuplicatedAccelerators) { |
| 34 std::set<AcceleratorData, Cmp> acclerators; | 30 std::set<AcceleratorData, Cmp> acclerators; |
| 35 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { | 31 for (size_t i = 0; i < kAcceleratorDataLength; ++i) { |
| 36 const AcceleratorData& entry = kAcceleratorData[i]; | 32 const AcceleratorData& entry = kAcceleratorData[i]; |
| 37 EXPECT_TRUE(acclerators.insert(entry).second) | 33 EXPECT_TRUE(acclerators.insert(entry).second) |
| 38 << "Duplicated accelerator: " << entry.trigger_on_press << ", " | 34 << "Duplicated accelerator: " << entry.trigger_on_press << ", " |
| 39 << entry.keycode << ", " << entry.shift << ", " << entry.ctrl << ", " | 35 << entry.keycode << ", " << (entry.modifiers & ui::EF_SHIFT_DOWN) |
| 40 << entry.alt; | 36 << ", " << (entry.modifiers & ui::EF_CONTROL_DOWN) << ", " |
| 37 << (entry.modifiers & ui::EF_ALT_DOWN); |
| 41 } | 38 } |
| 42 } | 39 } |
| 43 | 40 |
| 44 TEST(AcceleratorTableTest, CheckDuplicatedActionsAllowedAtLoginScreen) { | 41 TEST(AcceleratorTableTest, CheckDuplicatedActionsAllowedAtLoginScreen) { |
| 45 std::set<AcceleratorAction> actions; | 42 std::set<AcceleratorAction> actions; |
| 46 for (size_t i = 0; i < kActionsAllowedAtLoginScreenLength; ++i) { | 43 for (size_t i = 0; i < kActionsAllowedAtLoginScreenLength; ++i) { |
| 47 EXPECT_TRUE(actions.insert(kActionsAllowedAtLoginScreen[i]).second) | 44 EXPECT_TRUE(actions.insert(kActionsAllowedAtLoginScreen[i]).second) |
| 48 << "Duplicated action: " << kActionsAllowedAtLoginScreen[i]; | 45 << "Duplicated action: " << kActionsAllowedAtLoginScreen[i]; |
| 49 } | 46 } |
| 50 } | 47 } |
| 51 | 48 |
| 52 } // namespace ash | 49 } // namespace ash |
| OLD | NEW |