| 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 "ui/views/controls/menu/menu_model_adapter.h" | 5 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 8 #include "ui/base/l10n/l10n_util.h" |
| 9 #include "ui/base/models/menu_model.h" | 9 #include "ui/base/models/menu_model.h" |
| 10 #include "ui/base/models/menu_model_delegate.h" | 10 #include "ui/base/models/menu_model_delegate.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 typedef ViewsTestBase MenuModelAdapterTest; | 200 typedef ViewsTestBase MenuModelAdapterTest; |
| 201 | 201 |
| 202 TEST_F(MenuModelAdapterTest, BasicTest) { | 202 TEST_F(MenuModelAdapterTest, BasicTest) { |
| 203 // Build model and adapter. | 203 // Build model and adapter. |
| 204 RootModel model; | 204 RootModel model; |
| 205 views::MenuModelAdapter delegate(&model); | 205 views::MenuModelAdapter delegate(&model); |
| 206 | 206 |
| 207 // Create menu. Build menu twice to check that rebuilding works properly. | 207 // Create menu. Build menu twice to check that rebuilding works properly. |
| 208 MenuItemView* menu = new views::MenuItemView(&delegate); | 208 MenuItemView* menu = new views::MenuItemView(&delegate); |
| 209 // MenuRunner takes ownership of menu. | 209 // MenuRunner takes ownership of menu. |
| 210 scoped_ptr<MenuRunner> menu_runner(new MenuRunner(menu)); | 210 scoped_ptr<MenuRunner> menu_runner(new MenuRunner(menu, 0)); |
| 211 delegate.BuildMenu(menu); | 211 delegate.BuildMenu(menu); |
| 212 delegate.BuildMenu(menu); | 212 delegate.BuildMenu(menu); |
| 213 EXPECT_TRUE(menu->HasSubmenu()); | 213 EXPECT_TRUE(menu->HasSubmenu()); |
| 214 | 214 |
| 215 // Check top level menu items. | 215 // Check top level menu items. |
| 216 views::SubmenuView* item_container = menu->GetSubmenu(); | 216 views::SubmenuView* item_container = menu->GetSubmenu(); |
| 217 EXPECT_EQ(5, item_container->child_count()); | 217 EXPECT_EQ(5, item_container->child_count()); |
| 218 | 218 |
| 219 for (int i = 0; i < item_container->child_count(); ++i) { | 219 for (int i = 0; i < item_container->child_count(); ++i) { |
| 220 const MenuModelBase::Item& model_item = model.GetItemDefinition(i); | 220 const MenuModelBase::Item& model_item = model.GetItemDefinition(i); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 submodel->set_last_activation(-1); | 301 submodel->set_last_activation(-1); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // Check that selecting the root item is safe. The MenuModel does | 304 // Check that selecting the root item is safe. The MenuModel does |
| 305 // not care about the root so MenuModelAdapter should do nothing | 305 // not care about the root so MenuModelAdapter should do nothing |
| 306 // (not hit the NOTREACHED check) when the root is selected. | 306 // (not hit the NOTREACHED check) when the root is selected. |
| 307 static_cast<views::MenuDelegate*>(&delegate)->SelectionChanged(menu); | 307 static_cast<views::MenuDelegate*>(&delegate)->SelectionChanged(menu); |
| 308 } | 308 } |
| 309 | 309 |
| 310 } // namespace views | 310 } // namespace views |
| OLD | NEW |