| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/accessibility/native_view_accessibility.h" |
| 6 |
| 5 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 7 #include "ui/accessibility/ax_node_data.h" | 9 #include "ui/accessibility/ax_node_data.h" |
| 8 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
| 9 #include "ui/views/accessibility/native_view_accessibility.h" | 11 #include "ui/views/accessibility/ax_aura_obj_cache.h" |
| 12 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" |
| 13 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" |
| 10 #include "ui/views/controls/button/button.h" | 14 #include "ui/views/controls/button/button.h" |
| 11 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 12 #include "ui/views/test/views_test_base.h" | 16 #include "ui/views/test/views_test_base.h" |
| 13 | 17 |
| 14 namespace views { | 18 namespace views { |
| 15 namespace test { | 19 namespace test { |
| 16 | 20 |
| 17 class NativeViewAccessibilityTest; | 21 class NativeViewAccessibilityTest; |
| 18 | 22 |
| 19 namespace { | 23 namespace { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Make sure that deleting the parent widget can't cause a crash | 154 // Make sure that deleting the parent widget can't cause a crash |
| 151 // due to NativeViewAccessibility not unregistering itself as a | 155 // due to NativeViewAccessibility not unregistering itself as a |
| 152 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass | 156 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass |
| 153 // defined above that destroys itself when its parent widget is destroyed. | 157 // defined above that destroys itself when its parent widget is destroyed. |
| 154 TestNativeViewAccessibility* child_accessible = | 158 TestNativeViewAccessibility* child_accessible = |
| 155 new TestNativeViewAccessibility(child_widget->GetRootView()); | 159 new TestNativeViewAccessibility(child_widget->GetRootView()); |
| 156 child_accessible->SetParentWidget(parent_widget.get()); | 160 child_accessible->SetParentWidget(parent_widget.get()); |
| 157 parent_widget.reset(); | 161 parent_widget.reset(); |
| 158 } | 162 } |
| 159 | 163 |
| 164 #if defined(USE_AURA) |
| 165 class DerivedTestView : public View { |
| 166 public: |
| 167 DerivedTestView() : View() {} |
| 168 ~DerivedTestView() override {} |
| 169 |
| 170 void OnBlur() override { SetVisible(false); } |
| 171 }; |
| 172 |
| 173 class AxTestViewsDelegate : public TestViewsDelegate { |
| 174 public: |
| 175 AxTestViewsDelegate() {} |
| 176 ~AxTestViewsDelegate() override {} |
| 177 |
| 178 void NotifyAccessibilityEvent(views::View* view, |
| 179 ui::AXEvent event_type) override { |
| 180 AXAuraObjCache* ax = AXAuraObjCache::GetInstance(); |
| 181 std::vector<AXAuraObjWrapper*> out_children; |
| 182 AXAuraObjWrapper* ax_obj = ax->GetOrCreate(view->GetWidget()); |
| 183 ax_obj->GetChildren(&out_children); |
| 184 } |
| 185 |
| 186 private: |
| 187 DISALLOW_COPY_AND_ASSIGN(AxTestViewsDelegate); |
| 188 }; |
| 189 |
| 190 class AXViewTest : public ViewsTestBase { |
| 191 public: |
| 192 AXViewTest() {} |
| 193 ~AXViewTest() override {} |
| 194 void SetUp() override { |
| 195 std::unique_ptr<TestViewsDelegate> views_delegate( |
| 196 new AxTestViewsDelegate()); |
| 197 set_views_delegate(std::move(views_delegate)); |
| 198 views::ViewsTestBase::SetUp(); |
| 199 } |
| 200 }; |
| 201 |
| 202 // Check if the destruction of the widget ends successfully if |view|'s |
| 203 // visibility changed during destruction. |
| 204 TEST_F(AXViewTest, LayoutCalledInvalidateRootView) { |
| 205 std::unique_ptr<Widget> widget(new Widget); |
| 206 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 207 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 208 widget->Init(params); |
| 209 widget->Show(); |
| 210 |
| 211 View* root = widget->GetRootView(); |
| 212 DerivedTestView* parent = new DerivedTestView(); |
| 213 DerivedTestView* child = new DerivedTestView(); |
| 214 root->AddChildView(parent); |
| 215 parent->AddChildView(child); |
| 216 child->SetFocusBehavior(DerivedTestView::FocusBehavior::ALWAYS); |
| 217 parent->SetFocusBehavior(DerivedTestView::FocusBehavior::ALWAYS); |
| 218 root->SetFocusBehavior(DerivedTestView::FocusBehavior::ALWAYS); |
| 219 parent->RequestFocus(); |
| 220 // During the destruction of parent, OnBlur will be called and change the |
| 221 // visibility to false. |
| 222 parent->SetVisible(true); |
| 223 AXAuraObjCache* ax = AXAuraObjCache::GetInstance(); |
| 224 ax->GetOrCreate(widget.get()); |
| 225 } |
| 226 #endif |
| 227 |
| 160 } // namespace test | 228 } // namespace test |
| 161 } // namespace views | 229 } // namespace views |
| OLD | NEW |