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

Unified Diff: chrome/browser/tab_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
« no previous file with comments | « chrome/browser/tab_menu_model.cc ('k') | chrome/browser/views/tabs/tab.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_menu_model_unittest.cc
===================================================================
--- chrome/browser/tab_menu_model_unittest.cc (revision 0)
+++ chrome/browser/tab_menu_model_unittest.cc (revision 0)
@@ -0,0 +1,68 @@
+// 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.
+
+#include "chrome/browser/tab_menu_model.h"
+
+#include "base/logging.h"
+#include "testing/platform_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
viettrungluu 2009/12/15 23:18:45 g < p, and we usually order in the simplest way, I
pink (ping after 24hrs) 2009/12/16 14:52:49 Done.
+
+// 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 {
viettrungluu 2009/12/15 23:18:45 I've seen this before. Perhaps we should have a fi
pink (ping after 24hrs) 2009/12/16 14:52:49 I'll refactor this in a new cl, i don't want to cl
+ 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_;
+};
+
+class TabMenuModelTest : public PlatformTest {
+};
+
+// 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) {
viettrungluu 2009/12/15 23:18:45 This too.
pink (ping after 24hrs) 2009/12/16 14:52:49 same.
+ 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(TabMenuModelTest, Basics) {
+ Delegate delegate;
+ TabMenuModel model(&delegate);
+
+ // Verify it has items. The number varies by platform, so we don't check
+ // the exact number.
+ EXPECT_GT(model.GetItemCount(), 5);
+
+ 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_);
+}
Property changes on: chrome/browser/tab_menu_model_unittest.cc
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/tab_menu_model.cc ('k') | chrome/browser/views/tabs/tab.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698