| 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/compositor/test/context_factories_for_test.h" |
| 18 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/controls/menu/menu_item_view.h" | 21 #include "ui/views/controls/menu/menu_item_view.h" |
| 21 #include "ui/views/controls/menu/menu_model_adapter.h" | 22 #include "ui/views/controls/menu/menu_model_adapter.h" |
| 22 #include "ui/views/controls/menu/menu_runner.h" | 23 #include "ui/views/controls/menu/menu_runner.h" |
| 23 #include "ui/views/controls/menu/submenu_view.h" | 24 #include "ui/views/controls/menu/submenu_view.h" |
| 24 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
| 25 #include "ui/views/test/test_views_delegate.h" | 26 #include "ui/views/test/test_views_delegate.h" |
| 26 #include "ui/views/widget/native_widget.h" | 27 #include "ui/views/widget/native_widget.h" |
| 27 #include "ui/views/widget/root_view.h" | 28 #include "ui/views/widget/root_view.h" |
| 28 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 30 #include "ui/views/widget/widget_delegate.h" |
| 30 | 31 |
| 31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 32 #include "ui/base/win/scoped_ole_initializer.h" | 33 #include "ui/base/win/scoped_ole_initializer.h" |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 #if defined(USE_AURA) | 36 #if defined(USE_AURA) |
| 36 #include "ui/aura/test/aura_test_helper.h" | 37 #include "ui/aura/test/aura_test_helper.h" |
| 37 #include "ui/aura/window_event_dispatcher.h" | 38 #include "ui/aura/window_event_dispatcher.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 explicit AccessibilityViewsDelegate(ui::ContextFactory* context_factory) { |
| 47 set_context_factory(context_factory); |
| 48 } |
| 47 ~AccessibilityViewsDelegate() override {} | 49 ~AccessibilityViewsDelegate() override {} |
| 48 | 50 |
| 49 // Overridden from views::TestViewsDelegate: | 51 // Overridden from views::TestViewsDelegate: |
| 50 void NotifyAccessibilityEvent(views::View* view, | 52 void NotifyAccessibilityEvent(views::View* view, |
| 51 ui::AXEvent event_type) override { | 53 ui::AXEvent event_type) override { |
| 52 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( | 54 AccessibilityEventRouterViews::GetInstance()->HandleAccessibilityEvent( |
| 53 view, event_type); | 55 view, event_type); |
| 54 } | 56 } |
| 55 | 57 |
| 56 private: | 58 private: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 class AccessibilityEventRouterViewsTest | 103 class AccessibilityEventRouterViewsTest |
| 102 : public testing::Test { | 104 : public testing::Test { |
| 103 public: | 105 public: |
| 104 AccessibilityEventRouterViewsTest() : control_event_count_(0) { | 106 AccessibilityEventRouterViewsTest() : control_event_count_(0) { |
| 105 } | 107 } |
| 106 | 108 |
| 107 void SetUp() override { | 109 void SetUp() override { |
| 108 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
| 109 ole_initializer_.reset(new ui::ScopedOleInitializer()); | 111 ole_initializer_.reset(new ui::ScopedOleInitializer()); |
| 110 #endif | 112 #endif |
| 111 views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate(); | |
| 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 views::ViewsDelegate::views_delegate = |
| 118 new AccessibilityViewsDelegate(context_factory); |
| 119 #if defined(USE_AURA) |
| 118 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); | 120 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_)); |
| 119 aura_test_helper_->SetUp(context_factory); | 121 aura_test_helper_->SetUp(context_factory); |
| 120 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | 122 new wm::DefaultActivationClient(aura_test_helper_->root_window()); |
| 121 #endif // USE_AURA | 123 #endif // USE_AURA |
| 122 EnableAccessibilityAndListenToFocusNotifications(); | 124 EnableAccessibilityAndListenToFocusNotifications(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void TearDown() override { | 127 void TearDown() override { |
| 126 ClearCallback(); | 128 ClearCallback(); |
| 127 #if defined(USE_AURA) | 129 #if defined(USE_AURA) |
| 128 aura_test_helper_->TearDown(); | 130 aura_test_helper_->TearDown(); |
| 129 ui::TerminateContextFactoryForTests(); | |
| 130 #endif | 131 #endif |
| 131 delete views::ViewsDelegate::views_delegate; | 132 delete views::ViewsDelegate::views_delegate; |
| 133 ui::TerminateContextFactoryForTests(); |
| 132 | 134 |
| 133 // The Widget's FocusManager is deleted using DeleteSoon - this | 135 // The Widget's FocusManager is deleted using DeleteSoon - this |
| 134 // forces it to be deleted now, so we don't have any memory leaks | 136 // forces it to be deleted now, so we don't have any memory leaks |
| 135 // when this method exits. | 137 // when this method exits. |
| 136 base::MessageLoop::current()->RunUntilIdle(); | 138 base::MessageLoop::current()->RunUntilIdle(); |
| 137 | 139 |
| 138 #if defined(OS_WIN) | 140 #if defined(OS_WIN) |
| 139 ole_initializer_.reset(); | 141 ole_initializer_.reset(); |
| 140 #endif | 142 #endif |
| 141 } | 143 } |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 528 |
| 527 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 529 AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( |
| 528 menu_container, | 530 menu_container, |
| 529 menu->GetMenuItemByID(kTestCases[i].command_id), | 531 menu->GetMenuItemByID(kTestCases[i].command_id), |
| 530 &index, | 532 &index, |
| 531 &count); | 533 &count); |
| 532 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; | 534 EXPECT_EQ(kTestCases[i].expected_index, index) << "Case " << i; |
| 533 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; | 535 EXPECT_EQ(kTestCases[i].expected_count, count) << "Case " << i; |
| 534 } | 536 } |
| 535 } | 537 } |
| OLD | NEW |