OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/wrench_menu_model.h" | |
6 | |
7 #include "chrome/app/chrome_command_ids.h" | |
8 #include "chrome/test/browser_with_test_window_test.h" | |
9 #include "chrome/test/menu_model_test.h" | |
10 #include "chrome/test/testing_profile.h" | |
11 #include "grit/generated_resources.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 class WrenchMenuModelTest : public BrowserWithTestWindowTest, | |
15 public menus::AcceleratorProvider { | |
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 }; | |
55 | |
56 TEST_F(WrenchMenuModelTest, Basics) { | |
57 TestWrenchMenuModel model(this, browser()); | |
58 int itemCount = model.GetItemCount(); | |
59 | |
60 // Verify it has items. The number varies by platform, so we don't check | |
61 // the exact number. | |
62 EXPECT_GT(itemCount, 10); | |
63 | |
64 // Execute a couple of the items and make sure it gets back to our delegate. | |
65 // We can't use CountEnabledExecutable() here because the encoding menu's | |
66 // delegate is internal, it doesn't use the one we pass in. | |
67 model.ActivatedAt(0); | |
68 EXPECT_TRUE(model.IsEnabledAt(0)); | |
69 // Make sure to use the index that is not separator in all configurations. | |
70 model.ActivatedAt(2); | |
71 EXPECT_TRUE(model.IsEnabledAt(2)); | |
72 EXPECT_EQ(model.execute_count_, 2); | |
73 EXPECT_EQ(model.enable_count_, 2); | |
74 | |
75 model.execute_count_ = 0; | |
76 model.enable_count_ = 0; | |
77 | |
78 // Choose something from the tools submenu and make sure it makes it back to | |
79 // the delegate as well. Use the first submenu as the tools one. | |
80 int toolsModelIndex = -1; | |
81 for (int i = 0; i < itemCount; ++i) { | |
82 if (model.GetTypeAt(i) == menus::MenuModel::TYPE_SUBMENU) { | |
83 toolsModelIndex = i; | |
84 break; | |
85 } | |
86 } | |
87 EXPECT_GT(toolsModelIndex, -1); | |
88 menus::MenuModel* toolsModel = model.GetSubmenuModelAt(toolsModelIndex); | |
89 EXPECT_TRUE(toolsModel); | |
90 EXPECT_GT(toolsModel->GetItemCount(), 2); | |
91 toolsModel->ActivatedAt(2); | |
92 EXPECT_TRUE(toolsModel->IsEnabledAt(2)); | |
93 EXPECT_EQ(model.execute_count_, 1); | |
94 EXPECT_EQ(model.enable_count_, 1); | |
95 } | |
96 | |
97 class EncodingMenuModelTest : public BrowserWithTestWindowTest, | |
98 public MenuModelTest { | |
99 }; | |
100 | |
101 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { | |
102 EncodingMenuModel model(browser()); | |
103 ASSERT_EQ(NULL, browser()->GetSelectedTabContents()); | |
104 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); | |
105 } | |
OLD | NEW |