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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "ui/aura/window_event_dispatcher.h" | 37 #include "ui/aura/window_event_dispatcher.h" |
38 #include "ui/compositor/test/context_factories_for_test.h" | 38 #include "ui/compositor/test/context_factories_for_test.h" |
39 #include "ui/wm/core/default_activation_client.h" | 39 #include "ui/wm/core/default_activation_client.h" |
40 #endif | 40 #endif |
41 | 41 |
42 using base::ASCIIToUTF16; | 42 using base::ASCIIToUTF16; |
43 | 43 |
44 class AccessibilityViewsDelegate : public views::TestViewsDelegate { | 44 class AccessibilityViewsDelegate : public views::TestViewsDelegate { |
45 public: | 45 public: |
46 AccessibilityViewsDelegate() {} | 46 AccessibilityViewsDelegate() {} |
47 virtual ~AccessibilityViewsDelegate() {} | 47 ~AccessibilityViewsDelegate() override {} |
48 | 48 |
49 // Overridden from views::TestViewsDelegate: | 49 // Overridden from views::TestViewsDelegate: |
50 virtual void NotifyAccessibilityEvent( | 50 void NotifyAccessibilityEvent(views::View* view, |
51 views::View* view, ui::AXEvent event_type) override { | 51 ui::AXEvent event_type) override { |
52 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( | 52 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( |
53 view, event_type); | 53 view, event_type); |
54 } | 54 } |
55 | 55 |
56 private: | 56 private: |
57 DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); | 57 DISALLOW_COPY_AND_ASSIGN(AccessibilityViewsDelegate); |
58 }; | 58 }; |
59 | 59 |
60 class AccessibilityWindowDelegate : public views::WidgetDelegate { | 60 class AccessibilityWindowDelegate : public views::WidgetDelegate { |
61 public: | 61 public: |
62 explicit AccessibilityWindowDelegate(views::View* contents) | 62 explicit AccessibilityWindowDelegate(views::View* contents) |
63 : contents_(contents) { } | 63 : contents_(contents) { } |
64 | 64 |
65 // Overridden from views::WidgetDelegate: | 65 // Overridden from views::WidgetDelegate: |
66 virtual void DeleteDelegate() override { delete this; } | 66 void DeleteDelegate() override { delete this; } |
67 virtual views::View* GetContentsView() override { return contents_; } | 67 views::View* GetContentsView() override { return contents_; } |
68 virtual const views::Widget* GetWidget() const override { | 68 const views::Widget* GetWidget() const override { |
69 return contents_->GetWidget(); | 69 return contents_->GetWidget(); |
70 } | 70 } |
71 virtual views::Widget* GetWidget() override { return contents_->GetWidget(); } | 71 views::Widget* GetWidget() override { return contents_->GetWidget(); } |
72 | 72 |
73 private: | 73 private: |
74 views::View* contents_; | 74 views::View* contents_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(AccessibilityWindowDelegate); | 76 DISALLOW_COPY_AND_ASSIGN(AccessibilityWindowDelegate); |
77 }; | 77 }; |
78 | 78 |
79 class ViewWithNameAndRole : public views::View { | 79 class ViewWithNameAndRole : public views::View { |
80 public: | 80 public: |
81 explicit ViewWithNameAndRole(const base::string16& name, | 81 explicit ViewWithNameAndRole(const base::string16& name, |
82 ui::AXRole role) | 82 ui::AXRole role) |
83 : name_(name), | 83 : name_(name), |
84 role_(role) { | 84 role_(role) { |
85 } | 85 } |
86 | 86 |
87 virtual void GetAccessibleState(ui::AXViewState* state) override { | 87 void GetAccessibleState(ui::AXViewState* state) override { |
88 views::View::GetAccessibleState(state); | 88 views::View::GetAccessibleState(state); |
89 state->name = name_; | 89 state->name = name_; |
90 state->role = role_; | 90 state->role = role_; |
91 } | 91 } |
92 | 92 |
93 void set_name(const base::string16& name) { name_ = name; } | 93 void set_name(const base::string16& name) { name_ = name; } |
94 | 94 |
95 private: | 95 private: |
96 base::string16 name_; | 96 base::string16 name_; |
97 ui::AXRole role_; | 97 ui::AXRole role_; |
98 DISALLOW_COPY_AND_ASSIGN(ViewWithNameAndRole); | 98 DISALLOW_COPY_AND_ASSIGN(ViewWithNameAndRole); |
99 }; | 99 }; |
100 | 100 |
101 class AccessibilityEventRouterViewsTest | 101 class AccessibilityEventRouterViewsTest |
102 : public testing::Test { | 102 : public testing::Test { |
103 public: | 103 public: |
104 AccessibilityEventRouterViewsTest() : control_event_count_(0) { | 104 AccessibilityEventRouterViewsTest() : control_event_count_(0) { |
105 } | 105 } |
106 | 106 |
107 virtual void SetUp() { | 107 void SetUp() override { |
108 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
109 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 109 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
110 #endif | 110 #endif |
111 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); | 111 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); |
112 #if defined(USE_AURA) | 112 #if defined(USE_AURA) |
113 // The ContextFactory must exist before any Compositors are created. | 113 // The ContextFactory must exist before any Compositors are created. |
114 bool enable_pixel_output = false; | 114 bool enable_pixel_output = false; |
115 ui::ContextFactory* context_factory = | 115 ui::ContextFactory* context_factory = |
116 ui::InitializeContextFactoryForTests(enable_pixel_output); | 116 ui::InitializeContextFactoryForTests(enable_pixel_output); |
117 | 117 |
118 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 118 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
119 aura_test_helper_->SetUp(context_factory); | 119 aura_test_helper_->SetUp(context_factory); |
120 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 120 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
121 #endif // USE_AURA | 121 #endif // USE_AURA |
122 EnableAccessibilityAndListenToFocusNotifications(); | 122 EnableAccessibilityAndListenToFocusNotifications(); |
123 } | 123 } |
124 | 124 |
125 virtual void TearDown() { | 125 void TearDown() override { |
126 ClearCallback(); | 126 ClearCallback(); |
127 #if defined(USE_AURA) | 127 #if defined(USE_AURA) |
128 aura_test_helper_->TearDown(); | 128 aura_test_helper_->TearDown(); |
129 ui::TerminateContextFactoryForTests(); | 129 ui::TerminateContextFactoryForTests(); |
130 #endif | 130 #endif |
131 delete views::ViewsDelegate::views_delegate; | 131 delete views::ViewsDelegate::views_delegate; |
132 | 132 |
133 // The Widget's FocusManager is deleted using DeleteSoon - this | 133 // The Widget's FocusManager is deleted using DeleteSoon - this |
134 // forces it to be deleted now, so we don't have any memory leaks | 134 // forces it to be deleted now, so we don't have any memory leaks |
135 // when this method exits. | 135 // when this method exits. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 class SimpleMenuDelegate : public ui::SimpleMenuModel::Delegate { | 455 class SimpleMenuDelegate : public ui::SimpleMenuModel::Delegate { |
456 public: | 456 public: |
457 enum { | 457 enum { |
458 IDC_MENU_ITEM_1, | 458 IDC_MENU_ITEM_1, |
459 IDC_MENU_ITEM_2, | 459 IDC_MENU_ITEM_2, |
460 IDC_MENU_INVISIBLE, | 460 IDC_MENU_INVISIBLE, |
461 IDC_MENU_ITEM_3, | 461 IDC_MENU_ITEM_3, |
462 }; | 462 }; |
463 | 463 |
464 SimpleMenuDelegate() {} | 464 SimpleMenuDelegate() {} |
465 virtual ~SimpleMenuDelegate() {} | 465 ~SimpleMenuDelegate() override {} |
466 | 466 |
467 views::MenuItemView* BuildMenu() { | 467 views::MenuItemView* BuildMenu() { |
468 menu_model_.reset(new ui::SimpleMenuModel(this)); | 468 menu_model_.reset(new ui::SimpleMenuModel(this)); |
469 menu_model_->AddItem(IDC_MENU_ITEM_1, ASCIIToUTF16("Item 1")); | 469 menu_model_->AddItem(IDC_MENU_ITEM_1, ASCIIToUTF16("Item 1")); |
470 menu_model_->AddItem(IDC_MENU_ITEM_2, ASCIIToUTF16("Item 2")); | 470 menu_model_->AddItem(IDC_MENU_ITEM_2, ASCIIToUTF16("Item 2")); |
471 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 471 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
472 menu_model_->AddItem(IDC_MENU_INVISIBLE, ASCIIToUTF16("Invisible")); | 472 menu_model_->AddItem(IDC_MENU_INVISIBLE, ASCIIToUTF16("Invisible")); |
473 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 473 menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
474 menu_model_->AddItem(IDC_MENU_ITEM_3, ASCIIToUTF16("Item 3")); | 474 menu_model_->AddItem(IDC_MENU_ITEM_3, ASCIIToUTF16("Item 3")); |
475 | 475 |
476 menu_adapter_.reset(new views::MenuModelAdapter(menu_model_.get())); | 476 menu_adapter_.reset(new views::MenuModelAdapter(menu_model_.get())); |
477 views::MenuItemView* menu_view = menu_adapter_->CreateMenu(); | 477 views::MenuItemView* menu_view = menu_adapter_->CreateMenu(); |
478 menu_runner_.reset(new views::MenuRunner(menu_view, 0)); | 478 menu_runner_.reset(new views::MenuRunner(menu_view, 0)); |
479 return menu_view; | 479 return menu_view; |
480 } | 480 } |
481 | 481 |
482 virtual bool IsCommandIdChecked(int command_id) const override { | 482 bool IsCommandIdChecked(int command_id) const override { return false; } |
| 483 |
| 484 bool IsCommandIdEnabled(int command_id) const override { return true; } |
| 485 |
| 486 bool IsCommandIdVisible(int command_id) const override { |
| 487 return command_id != IDC_MENU_INVISIBLE; |
| 488 } |
| 489 |
| 490 bool GetAcceleratorForCommandId(int command_id, |
| 491 ui::Accelerator* accelerator) override { |
483 return false; | 492 return false; |
484 } | 493 } |
485 | 494 |
486 virtual bool IsCommandIdEnabled(int command_id) const override { | 495 void ExecuteCommand(int command_id, int event_flags) override {} |
487 return true; | |
488 } | |
489 | |
490 virtual bool IsCommandIdVisible(int command_id) const override { | |
491 return command_id != IDC_MENU_INVISIBLE; | |
492 } | |
493 | |
494 virtual bool GetAcceleratorForCommandId( | |
495 int command_id, | |
496 ui::Accelerator* accelerator) override { | |
497 return false; | |
498 } | |
499 | |
500 virtual void ExecuteCommand(int command_id, int event_flags) override { | |
501 } | |
502 | 496 |
503 private: | 497 private: |
504 scoped_ptr<ui::SimpleMenuModel> menu_model_; | 498 scoped_ptr<ui::SimpleMenuModel> menu_model_; |
505 scoped_ptr<views::MenuModelAdapter> menu_adapter_; | 499 scoped_ptr<views::MenuModelAdapter> menu_adapter_; |
506 scoped_ptr<views::MenuRunner> menu_runner_; | 500 scoped_ptr<views::MenuRunner> menu_runner_; |
507 | 501 |
508 DISALLOW_COPY_AND_ASSIGN(SimpleMenuDelegate); | 502 DISALLOW_COPY_AND_ASSIGN(SimpleMenuDelegate); |
509 }; | 503 }; |
510 | 504 |
511 } // namespace | 505 } // namespace |
(...skipping 20 matching lines...) Expand all Loading... |
532 | 526 |
533 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 527 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( |
534 menu_container, | 528 menu_container, |
535 menu->GetMenuItemByID(kTestCases[i].command_id), | 529 menu->GetMenuItemByID(kTestCases[i].command_id), |
536 &index, | 530 &index, |
537 &count); | 531 &count); |
538 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; | 532 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; |
539 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; | 533 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; |
540 } | 534 } |
541 } | 535 } |
OLD | NEW |