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

Side by Side Diff: chrome/browser/wrench_menu_model_unittest.cc

Issue 3163035: Revert "Clean up the WrenchMenuModel so that it uses SimpleMenu::Delegate." (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/wrench_menu_model.cc ('k') | chrome/test/menu_model_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/wrench_menu_model.h" 5 #include "chrome/browser/wrench_menu_model.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/app/chrome_dll_resource.h" 8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/test/browser_with_test_window_test.h" 9 #include "chrome/test/browser_with_test_window_test.h"
10 #include "chrome/test/menu_model_test.h" 10 #include "chrome/test/menu_model_test.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 class WrenchMenuModelTest : public BrowserWithTestWindowTest, 14 class WrenchMenuModelTest : public BrowserWithTestWindowTest,
15 public menus::AcceleratorProvider { 15 public MenuModelTest {
16 public:
17 // Don't handle accelerators.
18 virtual bool GetAcceleratorForCommandId(
19 int command_id,
20 menus::Accelerator* accelerator) { return false; }
21 };
22
23 // Copies parts of MenuModelTest::Delegate and combines them with the
24 // WrenchMenuModel since WrenchMenuModel is now a SimpleMenuModel::Delegate and
25 // not derived from SimpleMenuModel.
26 class TestWrenchMenuModel : public WrenchMenuModel {
27 public:
28 TestWrenchMenuModel(menus::AcceleratorProvider* provider,
29 Browser* browser)
30 : WrenchMenuModel(provider, browser),
31 execute_count_(0),
32 checked_count_(0),
33 enable_count_(0) {
34 }
35
36 // Testing overrides to menus::SimpleMenuModel::Delegate:
37 virtual bool IsCommandIdChecked(int command_id) const {
38 bool val = WrenchMenuModel::IsCommandIdChecked(command_id);
39 if (val)
40 checked_count_++;
41 return val;
42 }
43
44 virtual bool IsCommandIdEnabled(int command_id) const {
45 ++enable_count_;
46 return true;
47 }
48
49 virtual void ExecuteCommand(int command_id) { ++execute_count_; }
50
51 int execute_count_;
52 mutable int checked_count_;
53 mutable int enable_count_;
54 }; 16 };
55 17
56 TEST_F(WrenchMenuModelTest, Basics) { 18 TEST_F(WrenchMenuModelTest, Basics) {
57 TestWrenchMenuModel wrench(this, browser()); 19 WrenchMenuModel model(&delegate_, browser());
58 menus::SimpleMenuModel* model = wrench.menu_model(); 20 int itemCount = model.GetItemCount();
59 int itemCount = model->GetItemCount();
60 21
61 // Verify it has items. The number varies by platform, so we don't check 22 // Verify it has items. The number varies by platform, so we don't check
62 // the exact number. 23 // the exact number.
63 EXPECT_GT(itemCount, 10); 24 EXPECT_GT(itemCount, 10);
64 25
65 // Execute a couple of the items and make sure it gets back to our delegate. 26 // Execute a couple of the items and make sure it gets back to our delegate.
66 // We can't use CountEnabledExecutable() here because the encoding menu's 27 // We can't use CountEnabledExecutable() here because the encoding menu's
67 // delegate is internal, it doesn't use the one we pass in. 28 // delegate is internal, it doesn't use the one we pass in.
68 model->ActivatedAt(0); 29 model.ActivatedAt(0);
69 EXPECT_TRUE(model->IsEnabledAt(0)); 30 EXPECT_TRUE(model.IsEnabledAt(0));
70 // Make sure to use the index that is not separator in all configurations. 31 // Make sure to use the index that is not separator in all configurations.
71 model->ActivatedAt(2); 32 model.ActivatedAt(2);
72 EXPECT_TRUE(model->IsEnabledAt(2)); 33 EXPECT_TRUE(model.IsEnabledAt(2));
73 EXPECT_EQ(wrench.execute_count_, 2); 34 EXPECT_EQ(delegate_.execute_count_, 2);
74 EXPECT_EQ(wrench.enable_count_, 2); 35 EXPECT_EQ(delegate_.enable_count_, 2);
75 36
76 wrench.execute_count_ = 0; 37 delegate_.execute_count_ = 0;
77 wrench.enable_count_ = 0; 38 delegate_.enable_count_ = 0;
78 39
79 // Choose something from the tools submenu and make sure it makes it back to 40 // Choose something from the tools submenu and make sure it makes it back to
80 // the delegate as well. Use the first submenu as the tools one. 41 // the delegate as well. Use the first submenu as the tools one.
81 int toolsModelIndex = -1; 42 int toolsModelIndex = -1;
82 for (int i = 0; i < itemCount; ++i) { 43 for (int i = 0; i < itemCount; ++i) {
83 if (model->GetTypeAt(i) == menus::MenuModel::TYPE_SUBMENU) { 44 if (model.GetTypeAt(i) == menus::MenuModel::TYPE_SUBMENU) {
84 toolsModelIndex = i; 45 toolsModelIndex = i;
85 break; 46 break;
86 } 47 }
87 } 48 }
88 EXPECT_GT(toolsModelIndex, -1); 49 EXPECT_GT(toolsModelIndex, -1);
89 menus::MenuModel* toolsModel = model->GetSubmenuModelAt(toolsModelIndex); 50 menus::MenuModel* toolsModel = model.GetSubmenuModelAt(toolsModelIndex);
90 EXPECT_TRUE(toolsModel); 51 EXPECT_TRUE(toolsModel);
91 EXPECT_GT(toolsModel->GetItemCount(), 2); 52 EXPECT_GT(toolsModel->GetItemCount(), 2);
92 toolsModel->ActivatedAt(2); 53 toolsModel->ActivatedAt(2);
93 EXPECT_TRUE(toolsModel->IsEnabledAt(2)); 54 EXPECT_TRUE(toolsModel->IsEnabledAt(2));
94 EXPECT_EQ(wrench.execute_count_, 1); 55 EXPECT_EQ(delegate_.execute_count_, 1);
95 EXPECT_EQ(wrench.enable_count_, 1); 56 EXPECT_EQ(delegate_.enable_count_, 1);
96 } 57 }
97 58
98 class EncodingMenuModelTest : public BrowserWithTestWindowTest, 59 class EncodingMenuModelTest : public BrowserWithTestWindowTest,
99 public MenuModelTest { 60 public MenuModelTest {
100 }; 61 };
101 62
102 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { 63 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) {
103 EncodingMenuModel model(browser()); 64 EncodingMenuModel model(browser());
104 ASSERT_EQ(NULL, browser()->GetSelectedTabContents()); 65 ASSERT_EQ(NULL, browser()->GetSelectedTabContents());
105 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); 66 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591));
106 } 67 }
OLDNEW
« no previous file with comments | « chrome/browser/wrench_menu_model.cc ('k') | chrome/test/menu_model_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698