Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1953)

Unified Diff: chrome/browser/app_menu_model_unittest.cc

Issue 500030: Factor tab context menu into a shared model and fix mac and win to use it. Im... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/app_menu_model_unittest.cc
===================================================================
--- chrome/browser/app_menu_model_unittest.cc (revision 34596)
+++ chrome/browser/app_menu_model_unittest.cc (working copy)
@@ -31,6 +31,27 @@
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 @@
// 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_);
}

Powered by Google App Engine
This is Rietveld 408576698