| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "chrome/browser/app_menu_model.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chrome/test/browser_with_test_window_test.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 // A menu delegate that counts the number of times certain things are called |
| 12 // to make sure things are hooked up properly. |
| 13 class Delegate : public menus::SimpleMenuModel::Delegate { |
| 14 public: |
| 15 Delegate() : execute_count_(0), enable_count_(0) { } |
| 16 |
| 17 virtual bool IsCommandIdChecked(int command_id) const { return false; } |
| 18 virtual bool IsCommandIdEnabled(int command_id) const { |
| 19 ++enable_count_; |
| 20 return true; |
| 21 } |
| 22 virtual bool GetAcceleratorForCommandId( |
| 23 int command_id, |
| 24 menus::Accelerator* accelerator) { return false; } |
| 25 virtual void ExecuteCommand(int command_id) { ++execute_count_; } |
| 26 |
| 27 int execute_count_; |
| 28 mutable int enable_count_; |
| 29 }; |
| 30 |
| 31 class AppMenuModelTest : public BrowserWithTestWindowTest { |
| 32 }; |
| 33 |
| 34 TEST_F(AppMenuModelTest, Basics) { |
| 35 Delegate delegate; |
| 36 AppMenuModel model(&delegate, browser()); |
| 37 |
| 38 // Verify it has items. The number varies by platform, so we don't check |
| 39 // the exact number. |
| 40 EXPECT_GT(model.GetItemCount(), 5); |
| 41 |
| 42 // Execute a couple of the items and make sure it gets back to our delegate. |
| 43 model.ActivatedAt(0); |
| 44 EXPECT_TRUE(model.IsEnabledAt(0)); |
| 45 model.ActivatedAt(3); |
| 46 EXPECT_TRUE(model.IsEnabledAt(4)); |
| 47 EXPECT_EQ(delegate.execute_count_, 2); |
| 48 EXPECT_EQ(delegate.enable_count_, 2); |
| 49 |
| 50 delegate.execute_count_ = 0; |
| 51 delegate.enable_count_ = 0; |
| 52 } |
| OLD | NEW |