Chromium Code Reviews
|
| 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/tab_menu_model.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "testing/platform_test.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
|
viettrungluu
2009/12/15 23:18:45
g < p, and we usually order in the simplest way, I
pink (ping after 24hrs)
2009/12/16 14:52:49
Done.
| |
| 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 { | |
|
viettrungluu
2009/12/15 23:18:45
I've seen this before. Perhaps we should have a fi
pink (ping after 24hrs)
2009/12/16 14:52:49
I'll refactor this in a new cl, i don't want to cl
| |
| 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 TabMenuModelTest : public PlatformTest { | |
| 32 }; | |
| 33 | |
| 34 // Recursively checks the enabled state and executes a command on every item | |
| 35 // that's not a separator or a submenu parent item. The returned count should | |
| 36 // match the number of times the delegate is called to ensure every item works. | |
| 37 static void CountEnabledExecutable(menus::MenuModel* model, int* count) { | |
|
viettrungluu
2009/12/15 23:18:45
This too.
pink (ping after 24hrs)
2009/12/16 14:52:49
same.
| |
| 38 for (int i = 0; i < model->GetItemCount(); ++i) { | |
| 39 menus::MenuModel::ItemType type = model->GetTypeAt(i); | |
| 40 switch (type) { | |
| 41 case menus::MenuModel::TYPE_SEPARATOR: | |
| 42 continue; | |
| 43 case menus::MenuModel::TYPE_SUBMENU: | |
| 44 CountEnabledExecutable(model->GetSubmenuModelAt(i), count); | |
| 45 break; | |
| 46 default: | |
| 47 model->IsEnabledAt(i); // Check if it's enabled (ignore answer). | |
| 48 model->ActivatedAt(i); // Execute it. | |
| 49 (*count)++; // Increment the count of executable items seen. | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 TEST_F(TabMenuModelTest, Basics) { | |
| 56 Delegate delegate; | |
| 57 TabMenuModel model(&delegate); | |
| 58 | |
| 59 // Verify it has items. The number varies by platform, so we don't check | |
| 60 // the exact number. | |
| 61 EXPECT_GT(model.GetItemCount(), 5); | |
| 62 | |
| 63 int item_count = 0; | |
| 64 CountEnabledExecutable(&model, &item_count); | |
| 65 EXPECT_GT(item_count, 0); | |
| 66 EXPECT_EQ(item_count, delegate.execute_count_); | |
| 67 EXPECT_EQ(item_count, delegate.enable_count_); | |
| 68 } | |
| OLD | NEW |