| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/accessibility/accessibility_extension_api.h" | 10 #include "chrome/browser/accessibility/accessibility_extension_api.h" |
| 11 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" | 11 #include "chrome/browser/accessibility/accessibility_extension_api_constants.h" |
| 12 #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views
.h" | 12 #include "chrome/browser/ui/views/accessibility/accessibility_event_router_views
.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/accessibility/ax_enums.h" | 15 #include "ui/accessibility/ax_enums.h" |
| 16 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
| 17 #include "ui/base/models/simple_menu_model.h" | 17 #include "ui/base/models/simple_menu_model.h" |
| 18 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/controls/menu/menu_item_view.h" | 20 #include "ui/views/controls/menu/menu_item_view.h" |
| 21 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 21 #include "ui/views/controls/menu/menu_runner.h" | 22 #include "ui/views/controls/menu/menu_runner.h" |
| 22 #include "ui/views/controls/menu/submenu_view.h" | 23 #include "ui/views/controls/menu/submenu_view.h" |
| 23 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
| 24 #include "ui/views/test/test_views_delegate.h" | 25 #include "ui/views/test/test_views_delegate.h" |
| 25 #include "ui/views/widget/native_widget.h" | 26 #include "ui/views/widget/native_widget.h" |
| 26 #include "ui/views/widget/root_view.h" | 27 #include "ui/views/widget/root_view.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 29 | 30 |
| 30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 440 |
| 440 views::MenuItemView* BuildMenu() { | 441 views::MenuItemView* BuildMenu() { |
| 441 menu_model_.reset(new ui::SimpleMenuModel(this)); | 442 menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 442 menu_model_->AddItem(IDC_MENU_ITEM_1, ASCIIToUTF16("Item 1")); | 443 menu_model_->AddItem(IDC_MENU_ITEM_1, ASCIIToUTF16("Item 1")); |
| 443 menu_model_->AddItem(IDC_MENU_ITEM_2, ASCIIToUTF16("Item 2")); | 444 menu_model_->AddItem(IDC_MENU_ITEM_2, ASCIIToUTF16("Item 2")); |
| 444 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 445 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 445 menu_model_->AddItem(IDC_MENU_INVISIBLE, ASCIIToUTF16("Invisible")); | 446 menu_model_->AddItem(IDC_MENU_INVISIBLE, ASCIIToUTF16("Invisible")); |
| 446 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 447 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 447 menu_model_->AddItem(IDC_MENU_ITEM_3, ASCIIToUTF16("Item 3")); | 448 menu_model_->AddItem(IDC_MENU_ITEM_3, ASCIIToUTF16("Item 3")); |
| 448 | 449 |
| 449 menu_runner_.reset(new views::MenuRunner(menu_model_.get(), 0)); | 450 menu_adapter_.reset(new views::MenuModelAdapter(menu_model_.get())); |
| 450 return menu_runner_->GetMenu(); | 451 menu_view_.reset(menu_adapter->CreateMenu()); |
| 452 return menu_view_.get(); |
| 451 } | 453 } |
| 452 | 454 |
| 453 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { | 455 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE { |
| 454 return false; | 456 return false; |
| 455 } | 457 } |
| 456 | 458 |
| 457 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { | 459 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE { |
| 458 return true; | 460 return true; |
| 459 } | 461 } |
| 460 | 462 |
| 461 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE { | 463 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE { |
| 462 return command_id != IDC_MENU_INVISIBLE; | 464 return command_id != IDC_MENU_INVISIBLE; |
| 463 } | 465 } |
| 464 | 466 |
| 465 virtual bool GetAcceleratorForCommandId( | 467 virtual bool GetAcceleratorForCommandId( |
| 466 int command_id, | 468 int command_id, |
| 467 ui::Accelerator* accelerator) OVERRIDE { | 469 ui::Accelerator* accelerator) OVERRIDE { |
| 468 return false; | 470 return false; |
| 469 } | 471 } |
| 470 | 472 |
| 471 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE { | 473 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE { |
| 472 } | 474 } |
| 473 | 475 |
| 474 private: | 476 private: |
| 475 scoped_ptr<ui::SimpleMenuModel> menu_model_; | 477 scoped_ptr<ui::SimpleMenuModel> menu_model_; |
| 476 scoped_ptr<views::MenuRunner> menu_runner_; | 478 scoped_ptr<views::MenuModelAdapter> menu_adapter_; |
| 477 | 479 |
| 478 DISALLOW_COPY_AND_ASSIGN(SimpleMenuDelegate); | 480 DISALLOW_COPY_AND_ASSIGN(SimpleMenuDelegate); |
| 479 }; | 481 }; |
| 480 | 482 |
| 481 } // namespace | 483 } // namespace |
| 482 | 484 |
| 483 TEST_F(AccessibilityEventRouterViewsTest, MenuIndexAndCountForInvisibleMenu) { | 485 TEST_F(AccessibilityEventRouterViewsTest, MenuIndexAndCountForInvisibleMenu) { |
| 484 SimpleMenuDelegate menu_delegate; | 486 SimpleMenuDelegate menu_delegate; |
| 485 views::MenuItemView* menu = menu_delegate.BuildMenu(); | 487 views::MenuItemView* menu = menu_delegate.BuildMenu(); |
| 486 views::View* menu_container = menu->CreateSubmenu(); | 488 views::View* menu_container = menu->CreateSubmenu(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 502 | 504 |
| 503 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 505 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( |
| 504 menu_container, | 506 menu_container, |
| 505 menu->GetMenuItemByID(kTestCases[i].command_id), | 507 menu->GetMenuItemByID(kTestCases[i].command_id), |
| 506 &index, | 508 &index, |
| 507 &count); | 509 &count); |
| 508 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; | 510 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; |
| 509 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; | 511 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; |
| 510 } | 512 } |
| 511 } | 513 } |
| OLD | NEW |