| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_; | 82 scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_; |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 // Copies parts of MenuModelTest::Delegate and combines them with the | 85 // Copies parts of MenuModelTest::Delegate and combines them with the |
| 86 // WrenchMenuModel since WrenchMenuModel is now a SimpleMenuModel::Delegate and | 86 // WrenchMenuModel since WrenchMenuModel is now a SimpleMenuModel::Delegate and |
| 87 // not derived from SimpleMenuModel. | 87 // not derived from SimpleMenuModel. |
| 88 class TestWrenchMenuModel : public WrenchMenuModel { | 88 class TestWrenchMenuModel : public WrenchMenuModel { |
| 89 public: | 89 public: |
| 90 TestWrenchMenuModel(ui::AcceleratorProvider* provider, | 90 TestWrenchMenuModel(ui::AcceleratorProvider* provider, |
| 91 Browser* browser) | 91 Browser* browser) |
| 92 : WrenchMenuModel(provider, browser, false), | 92 : WrenchMenuModel(provider, browser), |
| 93 execute_count_(0), | 93 execute_count_(0), |
| 94 checked_count_(0), | 94 checked_count_(0), |
| 95 enable_count_(0) { | 95 enable_count_(0) { |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Testing overrides to ui::SimpleMenuModel::Delegate: | 98 // Testing overrides to ui::SimpleMenuModel::Delegate: |
| 99 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | 99 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { |
| 100 bool val = WrenchMenuModel::IsCommandIdChecked(command_id); | 100 bool val = WrenchMenuModel::IsCommandIdChecked(command_id); |
| 101 if (val) | 101 if (val) |
| 102 checked_count_++; | 102 checked_count_++; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); | 169 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); |
| 170 const int command1 = 1234567; | 170 const int command1 = 1234567; |
| 171 // AddGlobalError takes ownership of error1. | 171 // AddGlobalError takes ownership of error1. |
| 172 MenuError* error1 = new MenuError(command1); | 172 MenuError* error1 = new MenuError(command1); |
| 173 service->AddGlobalError(error1); | 173 service->AddGlobalError(error1); |
| 174 const int command2 = 1234568; | 174 const int command2 = 1234568; |
| 175 // AddGlobalError takes ownership of error2. | 175 // AddGlobalError takes ownership of error2. |
| 176 MenuError* error2 = new MenuError(command2); | 176 MenuError* error2 = new MenuError(command2); |
| 177 service->AddGlobalError(error2); | 177 service->AddGlobalError(error2); |
| 178 | 178 |
| 179 WrenchMenuModel model(this, browser(), false); | 179 WrenchMenuModel model(this, browser()); |
| 180 int index1 = model.GetIndexOfCommandId(command1); | 180 int index1 = model.GetIndexOfCommandId(command1); |
| 181 EXPECT_GT(index1, -1); | 181 EXPECT_GT(index1, -1); |
| 182 int index2 = model.GetIndexOfCommandId(command2); | 182 int index2 = model.GetIndexOfCommandId(command2); |
| 183 EXPECT_GT(index2, -1); | 183 EXPECT_GT(index2, -1); |
| 184 | 184 |
| 185 EXPECT_TRUE(model.IsEnabledAt(index1)); | 185 EXPECT_TRUE(model.IsEnabledAt(index1)); |
| 186 EXPECT_EQ(0, error1->execute_count()); | 186 EXPECT_EQ(0, error1->execute_count()); |
| 187 model.ActivatedAt(index1); | 187 model.ActivatedAt(index1); |
| 188 EXPECT_EQ(1, error1->execute_count()); | 188 EXPECT_EQ(1, error1->execute_count()); |
| 189 | 189 |
| 190 EXPECT_TRUE(model.IsEnabledAt(index2)); | 190 EXPECT_TRUE(model.IsEnabledAt(index2)); |
| 191 EXPECT_EQ(0, error2->execute_count()); | 191 EXPECT_EQ(0, error2->execute_count()); |
| 192 model.ActivatedAt(index2); | 192 model.ActivatedAt(index2); |
| 193 EXPECT_EQ(1, error1->execute_count()); | 193 EXPECT_EQ(1, error1->execute_count()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 class EncodingMenuModelTest : public BrowserWithTestWindowTest, | 196 class EncodingMenuModelTest : public BrowserWithTestWindowTest, |
| 197 public MenuModelTest { | 197 public MenuModelTest { |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { | 200 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { |
| 201 EncodingMenuModel model(browser()); | 201 EncodingMenuModel model(browser()); |
| 202 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); | 202 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); |
| 203 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); | 203 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_ISO88591)); |
| 204 } | 204 } |
| OLD | NEW |