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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "ui/accessibility/ax_view_state.h" | 6 #include "ui/accessibility/ax_view_state.h" |
7 #include "ui/views/accessibility/native_view_accessibility.h" | 7 #include "ui/views/accessibility/native_view_accessibility.h" |
8 #include "ui/views/controls/button/button.h" | 8 #include "ui/views/controls/button/button.h" |
9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 void TearDown() override { | 42 void TearDown() override { |
43 button_accessibility_->Destroy(); | 43 button_accessibility_->Destroy(); |
44 button_accessibility_ = NULL; | 44 button_accessibility_ = NULL; |
45 label_accessibility_->Destroy(); | 45 label_accessibility_->Destroy(); |
46 label_accessibility_ = NULL; | 46 label_accessibility_ = NULL; |
47 ViewsTestBase::TearDown(); | 47 ViewsTestBase::TearDown(); |
48 } | 48 } |
49 | 49 |
50 protected: | 50 protected: |
51 scoped_ptr<TestButton> button_; | 51 std::unique_ptr<TestButton> button_; |
52 NativeViewAccessibility* button_accessibility_; | 52 NativeViewAccessibility* button_accessibility_; |
53 scoped_ptr<Label> label_; | 53 std::unique_ptr<Label> label_; |
54 NativeViewAccessibility* label_accessibility_; | 54 NativeViewAccessibility* label_accessibility_; |
55 }; | 55 }; |
56 | 56 |
57 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { | 57 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { |
58 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); | 58 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); |
59 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); | 59 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); |
60 } | 60 } |
61 | 61 |
62 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { | 62 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { |
63 gfx::Rect bounds = button_accessibility_->GetData().location; | 63 gfx::Rect bounds = button_accessibility_->GetData().location; |
(...skipping 19 matching lines...) Expand all Loading... |
83 | 83 |
84 void OnWidgetDestroying(Widget* widget) override { | 84 void OnWidgetDestroying(Widget* widget) override { |
85 bool is_destroying_parent_widget = (parent_widget_ == widget); | 85 bool is_destroying_parent_widget = (parent_widget_ == widget); |
86 NativeViewAccessibility::OnWidgetDestroying(widget); | 86 NativeViewAccessibility::OnWidgetDestroying(widget); |
87 if (is_destroying_parent_widget) | 87 if (is_destroying_parent_widget) |
88 delete this; | 88 delete this; |
89 } | 89 } |
90 }; | 90 }; |
91 | 91 |
92 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) { | 92 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) { |
93 scoped_ptr<Widget> parent_widget(new Widget); | 93 std::unique_ptr<Widget> parent_widget(new Widget); |
94 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 94 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
95 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 95 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
96 params.bounds = gfx::Rect(50, 50, 650, 650); | 96 params.bounds = gfx::Rect(50, 50, 650, 650); |
97 parent_widget->Init(params); | 97 parent_widget->Init(params); |
98 | 98 |
99 scoped_ptr<Widget> child_widget(new Widget); | 99 std::unique_ptr<Widget> child_widget(new Widget); |
100 child_widget->Init(params); | 100 child_widget->Init(params); |
101 | 101 |
102 // Make sure that deleting the parent widget can't cause a crash | 102 // Make sure that deleting the parent widget can't cause a crash |
103 // due to NativeViewAccessibility not unregistering itself as a | 103 // due to NativeViewAccessibility not unregistering itself as a |
104 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass | 104 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass |
105 // defined above that destroys itself when its parent widget is destroyed. | 105 // defined above that destroys itself when its parent widget is destroyed. |
106 TestNativeViewAccessibility* child_accessible = | 106 TestNativeViewAccessibility* child_accessible = |
107 new TestNativeViewAccessibility(child_widget->GetRootView()); | 107 new TestNativeViewAccessibility(child_widget->GetRootView()); |
108 child_accessible->SetParentWidget(parent_widget.get()); | 108 child_accessible->SetParentWidget(parent_widget.get()); |
109 parent_widget.reset(); | 109 parent_widget.reset(); |
110 } | 110 } |
111 | 111 |
112 } // namespace test | 112 } // namespace test |
113 } // namespace views | 113 } // namespace views |
OLD | NEW |