summaryrefslogtreecommitdiffstats
path: root/chrome/test/menu_model_test.h
blob: 06eaf241b7034dd6406ca55af29fd21563b8beaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

#ifndef CHROME_TEST_MENU_MODEL_TEST_H_
#define CHROME_TEST_MENU_MODEL_TEST_H_

#include "app/menus/simple_menu_model.h"

// A mix-in class to be used in addition to something that derrives from
// testing::Test to provide some extra functionality for testing menu models.
class MenuModelTest {
 public:
  MenuModelTest() { }
  virtual ~MenuModelTest() { }

 protected:
  // A menu delegate that counts the number of times certain things are called
  // to make sure things are hooked up properly.
  class Delegate : public menus::SimpleMenuModel::Delegate {
   public:
    Delegate() : execute_count_(0), enable_count_(0) { }

    virtual bool IsCommandIdChecked(int command_id) const { return false; }
    virtual bool IsCommandIdEnabled(int command_id) const {
      ++enable_count_;
      return true;
    }
    virtual bool GetAcceleratorForCommandId(
        int command_id,
        menus::Accelerator* accelerator) { return false; }
    virtual void ExecuteCommand(int command_id) { ++execute_count_; }

    int execute_count_;
    mutable int enable_count_;
  };

  // Recursively checks the enabled state and executes a command on every item
  // that's not a separator or a submenu parent item. The returned count should
  // match the number of times the delegate is called to ensure every item
  // works.
  void CountEnabledExecutable(menus::MenuModel* model, int* count);

  Delegate delegate_;
};

#endif  // CHROME_TEST_MENU_MODEL_TEST_H_