OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/menu_model_test.h" | 5 #include "chrome/test/base/menu_model_test.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 | 8 |
9 bool MenuModelTest::Delegate::IsCommandIdChecked(int command_id) const { | 9 bool MenuModelTest::Delegate::IsCommandIdChecked(int command_id) const { |
10 return false; | 10 return false; |
11 } | 11 } |
12 | 12 |
13 bool MenuModelTest::Delegate::IsCommandIdEnabled(int command_id) const { | 13 bool MenuModelTest::Delegate::IsCommandIdEnabled(int command_id) const { |
14 ++enable_count_; | 14 ++enable_count_; |
15 return true; | 15 return true; |
16 } | 16 } |
17 | 17 |
18 bool MenuModelTest::Delegate::GetAcceleratorForCommandId( | |
19 int command_id, | |
20 ui::Accelerator* accelerator) const { | |
21 return false; | |
22 } | |
23 | |
24 void MenuModelTest::Delegate::ExecuteCommand(int command_id, int event_flags) { | 18 void MenuModelTest::Delegate::ExecuteCommand(int command_id, int event_flags) { |
25 ++execute_count_; | 19 ++execute_count_; |
26 } | 20 } |
27 | 21 |
28 // Recursively checks the enabled state and executes a command on every item | 22 // Recursively checks the enabled state and executes a command on every item |
29 // that's not a separator or a submenu parent item. The returned count should | 23 // that's not a separator or a submenu parent item. The returned count should |
30 // match the number of times the delegate is called to ensure every item works. | 24 // match the number of times the delegate is called to ensure every item works. |
31 void MenuModelTest::CountEnabledExecutable(ui::MenuModel* model, | 25 void MenuModelTest::CountEnabledExecutable(ui::MenuModel* model, |
32 int* count) { | 26 int* count) { |
33 for (int i = 0; i < model->GetItemCount(); ++i) { | 27 for (int i = 0; i < model->GetItemCount(); ++i) { |
34 ui::MenuModel::ItemType type = model->GetTypeAt(i); | 28 ui::MenuModel::ItemType type = model->GetTypeAt(i); |
35 switch (type) { | 29 switch (type) { |
36 case ui::MenuModel::TYPE_SEPARATOR: | 30 case ui::MenuModel::TYPE_SEPARATOR: |
37 continue; | 31 continue; |
38 case ui::MenuModel::TYPE_SUBMENU: | 32 case ui::MenuModel::TYPE_SUBMENU: |
39 CountEnabledExecutable(model->GetSubmenuModelAt(i), count); | 33 CountEnabledExecutable(model->GetSubmenuModelAt(i), count); |
40 break; | 34 break; |
41 case ui::MenuModel::TYPE_COMMAND: | 35 case ui::MenuModel::TYPE_COMMAND: |
42 case ui::MenuModel::TYPE_CHECK: | 36 case ui::MenuModel::TYPE_CHECK: |
43 case ui::MenuModel::TYPE_RADIO: | 37 case ui::MenuModel::TYPE_RADIO: |
44 model->IsEnabledAt(i); // Check if it's enabled (ignore answer). | 38 model->IsEnabledAt(i); // Check if it's enabled (ignore answer). |
45 model->ActivatedAt(i); // Execute it. | 39 model->ActivatedAt(i); // Execute it. |
46 (*count)++; // Increment the count of executable items seen. | 40 (*count)++; // Increment the count of executable items seen. |
47 break; | 41 break; |
48 default: | 42 default: |
49 FAIL(); // Ensure every case is tested. | 43 FAIL(); // Ensure every case is tested. |
50 } | 44 } |
51 } | 45 } |
52 } | 46 } |
OLD | NEW |