Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ui/views/accessibility/native_view_accessibility_unittest.cc

Issue 1287463002: Call RemoveObserver from OnWidgetDestroying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { 68 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) {
69 EXPECT_EQ(1, button_accessibility_->GetChildCount()); 69 EXPECT_EQ(1, button_accessibility_->GetChildCount());
70 EXPECT_EQ(label_->GetNativeViewAccessible(), 70 EXPECT_EQ(label_->GetNativeViewAccessible(),
71 button_accessibility_->ChildAtIndex(0)); 71 button_accessibility_->ChildAtIndex(0));
72 EXPECT_EQ(button_->GetNativeViewAccessible(), 72 EXPECT_EQ(button_->GetNativeViewAccessible(),
73 label_accessibility_->GetParent()); 73 label_accessibility_->GetParent());
74 } 74 }
75 75
76 // Subclass of NativeViewAccessibility that destroys itself when its
77 // parent widget is destroyed, for the purposes of making sure this
78 // doesn't lead to a crash.
79 class TestNativeViewAccessibility : public NativeViewAccessibility {
80 public:
81 explicit TestNativeViewAccessibility(View* view)
82 : NativeViewAccessibility(view) {}
83
84 void OnWidgetDestroying(Widget* widget) override {
85 bool is_destroying_parent_widget = (parent_widget_ == widget);
86 NativeViewAccessibility::OnWidgetDestroying(widget);
87 if (is_destroying_parent_widget)
88 delete this;
89 }
90 };
91
92 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) {
93 scoped_ptr<Widget> parent_widget(new Widget);
94 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
95 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
96 params.bounds = gfx::Rect(50, 50, 650, 650);
97 parent_widget->Init(params);
98
99 scoped_ptr<Widget> child_widget(new Widget);
100 child_widget->Init(params);
101
102 // Make sure that deleting the parent widget can't cause a crash
103 // due to NativeViewAccessibility not unregistering itself as a
104 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass
105 // defined above that destroys itself when its parent widget is destroyed.
106 TestNativeViewAccessibility* child_accessible =
107 new TestNativeViewAccessibility(child_widget->GetRootView());
108 child_accessible->SetParentWidget(parent_widget.get());
109 parent_widget.reset();
110 }
111
76 } // namespace test 112 } // namespace test
77 } // namespace views 113 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698