OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/toolbar/wrench_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/prefs/browser_prefs.h" | 8 #include "chrome/browser/prefs/browser_prefs.h" |
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // Error class has a menu item. | 25 // Error class has a menu item. |
26 class MenuError : public GlobalError { | 26 class MenuError : public GlobalError { |
27 public: | 27 public: |
28 explicit MenuError(int command_id) | 28 explicit MenuError(int command_id) |
29 : command_id_(command_id), | 29 : command_id_(command_id), |
30 execute_count_(0) { | 30 execute_count_(0) { |
31 } | 31 } |
32 | 32 |
33 int execute_count() { return execute_count_; } | 33 int execute_count() { return execute_count_; } |
34 | 34 |
35 virtual bool HasMenuItem() override { return true; } | 35 bool HasMenuItem() override { return true; } |
36 virtual int MenuItemCommandID() override { return command_id_; } | 36 int MenuItemCommandID() override { return command_id_; } |
37 virtual base::string16 MenuItemLabel() override { return base::string16(); } | 37 base::string16 MenuItemLabel() override { return base::string16(); } |
38 virtual void ExecuteMenuItem(Browser* browser) override { execute_count_++; } | 38 void ExecuteMenuItem(Browser* browser) override { execute_count_++; } |
39 | 39 |
40 virtual bool HasBubbleView() override { return false; } | 40 bool HasBubbleView() override { return false; } |
41 virtual bool HasShownBubbleView() override { return false; } | 41 bool HasShownBubbleView() override { return false; } |
42 virtual void ShowBubbleView(Browser* browser) override { ADD_FAILURE(); } | 42 void ShowBubbleView(Browser* browser) override { ADD_FAILURE(); } |
43 virtual GlobalErrorBubbleViewBase* GetBubbleView() override { return NULL; } | 43 GlobalErrorBubbleViewBase* GetBubbleView() override { return NULL; } |
44 | 44 |
45 private: | 45 private: |
46 int command_id_; | 46 int command_id_; |
47 int execute_count_; | 47 int execute_count_; |
48 | 48 |
49 DISALLOW_COPY_AND_ASSIGN(MenuError); | 49 DISALLOW_COPY_AND_ASSIGN(MenuError); |
50 }; | 50 }; |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 class WrenchMenuModelTest : public BrowserWithTestWindowTest, | 54 class WrenchMenuModelTest : public BrowserWithTestWindowTest, |
55 public ui::AcceleratorProvider { | 55 public ui::AcceleratorProvider { |
56 public: | 56 public: |
57 // Don't handle accelerators. | 57 // Don't handle accelerators. |
58 virtual bool GetAcceleratorForCommandId( | 58 bool GetAcceleratorForCommandId(int command_id, |
59 int command_id, | 59 ui::Accelerator* accelerator) override { |
60 ui::Accelerator* accelerator) override { return false; } | 60 return false; |
| 61 } |
61 | 62 |
62 protected: | 63 protected: |
63 virtual void SetUp() override { | 64 virtual void SetUp() override { |
64 prefs_.reset(new TestingPrefServiceSimple()); | 65 prefs_.reset(new TestingPrefServiceSimple()); |
65 chrome::RegisterLocalState(prefs_->registry()); | 66 chrome::RegisterLocalState(prefs_->registry()); |
66 | 67 |
67 TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); | 68 TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); |
68 testing_io_thread_state_.reset(new chrome::TestingIOThreadState()); | 69 testing_io_thread_state_.reset(new chrome::TestingIOThreadState()); |
69 BrowserWithTestWindowTest::SetUp(); | 70 BrowserWithTestWindowTest::SetUp(); |
70 } | 71 } |
(...skipping 17 matching lines...) Expand all Loading... |
88 public: | 89 public: |
89 TestWrenchMenuModel(ui::AcceleratorProvider* provider, | 90 TestWrenchMenuModel(ui::AcceleratorProvider* provider, |
90 Browser* browser) | 91 Browser* browser) |
91 : WrenchMenuModel(provider, browser), | 92 : WrenchMenuModel(provider, browser), |
92 execute_count_(0), | 93 execute_count_(0), |
93 checked_count_(0), | 94 checked_count_(0), |
94 enable_count_(0) { | 95 enable_count_(0) { |
95 } | 96 } |
96 | 97 |
97 // Testing overrides to ui::SimpleMenuModel::Delegate: | 98 // Testing overrides to ui::SimpleMenuModel::Delegate: |
98 virtual bool IsCommandIdChecked(int command_id) const override { | 99 bool IsCommandIdChecked(int command_id) const override { |
99 bool val = WrenchMenuModel::IsCommandIdChecked(command_id); | 100 bool val = WrenchMenuModel::IsCommandIdChecked(command_id); |
100 if (val) | 101 if (val) |
101 checked_count_++; | 102 checked_count_++; |
102 return val; | 103 return val; |
103 } | 104 } |
104 | 105 |
105 virtual bool IsCommandIdEnabled(int command_id) const override { | 106 bool IsCommandIdEnabled(int command_id) const override { |
106 ++enable_count_; | 107 ++enable_count_; |
107 return true; | 108 return true; |
108 } | 109 } |
109 | 110 |
110 virtual void ExecuteCommand(int command_id, int event_flags) override { | 111 void ExecuteCommand(int command_id, int event_flags) override { |
111 ++execute_count_; | 112 ++execute_count_; |
112 } | 113 } |
113 | 114 |
114 int execute_count_; | 115 int execute_count_; |
115 mutable int checked_count_; | 116 mutable int checked_count_; |
116 mutable int enable_count_; | 117 mutable int enable_count_; |
117 }; | 118 }; |
118 | 119 |
119 TEST_F(WrenchMenuModelTest, Basics) { | 120 TEST_F(WrenchMenuModelTest, Basics) { |
120 TestWrenchMenuModel model(this, browser()); | 121 TestWrenchMenuModel model(this, browser()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 195 |
195 class EncodingMenuModelTest : public BrowserWithTestWindowTest, | 196 class EncodingMenuModelTest : public BrowserWithTestWindowTest, |
196 public MenuModelTest { | 197 public MenuModelTest { |
197 }; | 198 }; |
198 | 199 |
199 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { | 200 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { |
200 EncodingMenuModel model(browser()); | 201 EncodingMenuModel model(browser()); |
201 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); | 202 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); |
202 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); | 203 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); |
203 } | 204 } |
OLD | NEW |