summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_menu_model_unittest.cc
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 16:21:36 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-16 16:21:36 +0000
commitf8a0cb584078998db374e3df2e0f4290377b0be6 (patch)
tree3c32b4283e37d37d07dd9dc6737efa4e7e4d7ec3 /chrome/browser/app_menu_model_unittest.cc
parent5db3af57ca8994249f0ba0efbb60ac103f7f0934 (diff)
downloadchromium_src-f8a0cb584078998db374e3df2e0f4290377b0be6.zip
chromium_src-f8a0cb584078998db374e3df2e0f4290377b0be6.tar.gz
chromium_src-f8a0cb584078998db374e3df2e0f4290377b0be6.tar.bz2
Factor tab context menu into a shared model and fix mac and win to use it. Improve a couple of model unit tests. Remove unused members in the models.
BUG=28977 TEST=context menus on tabs should work and enable/disable properly Review URL: http://codereview.chromium.org/500030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34718 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/app_menu_model_unittest.cc')
-rw-r--r--chrome/browser/app_menu_model_unittest.cc36
1 files changed, 26 insertions, 10 deletions
diff --git a/chrome/browser/app_menu_model_unittest.cc b/chrome/browser/app_menu_model_unittest.cc
index b354292..1200c63 100644
--- a/chrome/browser/app_menu_model_unittest.cc
+++ b/chrome/browser/app_menu_model_unittest.cc
@@ -31,6 +31,27 @@ class Delegate : public menus::SimpleMenuModel::Delegate {
class AppMenuModelTest : public BrowserWithTestWindowTest {
};
+// 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.
+static void CountEnabledExecutable(menus::MenuModel* model, int* count) {
+ for (int i = 0; i < model->GetItemCount(); ++i) {
+ menus::MenuModel::ItemType type = model->GetTypeAt(i);
+ switch (type) {
+ case menus::MenuModel::TYPE_SEPARATOR:
+ continue;
+ case menus::MenuModel::TYPE_SUBMENU:
+ CountEnabledExecutable(model->GetSubmenuModelAt(i), count);
+ break;
+ default:
+ model->IsEnabledAt(i); // Check if it's enabled (ignore answer).
+ model->ActivatedAt(i); // Execute it.
+ (*count)++; // Increment the count of executable items seen.
+ break;
+ }
+ }
+}
+
TEST_F(AppMenuModelTest, Basics) {
Delegate delegate;
AppMenuModel model(&delegate, browser());
@@ -39,14 +60,9 @@ TEST_F(AppMenuModelTest, Basics) {
// the exact number.
EXPECT_GT(model.GetItemCount(), 5);
- // Execute a couple of the items and make sure it gets back to our delegate.
- model.ActivatedAt(0);
- EXPECT_TRUE(model.IsEnabledAt(0));
- model.ActivatedAt(3);
- EXPECT_TRUE(model.IsEnabledAt(4));
- EXPECT_EQ(delegate.execute_count_, 2);
- EXPECT_EQ(delegate.enable_count_, 2);
-
- delegate.execute_count_ = 0;
- delegate.enable_count_ = 0;
+ int item_count = 0;
+ CountEnabledExecutable(&model, &item_count);
+ EXPECT_GT(item_count, 0);
+ EXPECT_EQ(item_count, delegate.execute_count_);
+ EXPECT_EQ(item_count, delegate.enable_count_);
}