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
3 // found in the LICENSE file.
5 #include "chrome/test/base/menu_model_test.h"
6 #include "testing/gtest/include/gtest/gtest.h"
9 bool MenuModelTest::Delegate::IsCommandIdChecked(int command_id
) const {
13 bool MenuModelTest::Delegate::IsCommandIdEnabled(int command_id
) const {
18 bool MenuModelTest::Delegate::GetAcceleratorForCommandId(
20 ui::Accelerator
* accelerator
) {
24 void MenuModelTest::Delegate::ExecuteCommand(int command_id
, int event_flags
) {
28 // 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
30 // match the number of times the delegate is called to ensure every item works.
31 void MenuModelTest::CountEnabledExecutable(ui::MenuModel
* model
,
33 for (int i
= 0; i
< model
->GetItemCount(); ++i
) {
34 ui::MenuModel::ItemType type
= model
->GetTypeAt(i
);
36 case ui::MenuModel::TYPE_SEPARATOR
:
38 case ui::MenuModel::TYPE_SUBMENU
:
39 CountEnabledExecutable(model
->GetSubmenuModelAt(i
), count
);
41 case ui::MenuModel::TYPE_COMMAND
:
42 case ui::MenuModel::TYPE_CHECK
:
43 case ui::MenuModel::TYPE_RADIO
:
44 model
->IsEnabledAt(i
); // Check if it's enabled (ignore answer).
45 model
->ActivatedAt(i
); // Execute it.
46 (*count
)++; // Increment the count of executable items seen.
49 FAIL(); // Ensure every case is tested.