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

Side by Side Diff: ui/views/bubble/bubble_delegate_unittest.cc

Issue 1440593004: Make operators on scoped_ptr match the ones defined for std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrequals: followupfix-after-rebase Created 5 years, 1 month 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/aura/window.cc ('k') | ui/views/controls/webview/webview.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/base/hit_test.h" 5 #include "ui/base/hit_test.h"
6 #include "ui/views/bubble/bubble_delegate.h" 6 #include "ui/views/bubble/bubble_delegate.h"
7 #include "ui/views/bubble/bubble_frame_view.h" 7 #include "ui/views/bubble/bubble_frame_view.h"
8 #include "ui/views/test/test_widget_observer.h" 8 #include "ui/views/test/test_widget_observer.h"
9 #include "ui/views/test/views_test_base.h" 9 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 TEST_F(BubbleDelegateTest, CloseAnchorWidget) { 85 TEST_F(BubbleDelegateTest, CloseAnchorWidget) {
86 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); 86 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
87 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( 87 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
88 anchor_widget->GetContentsView(), BubbleBorder::NONE); 88 anchor_widget->GetContentsView(), BubbleBorder::NONE);
89 // Preventing close on deactivate should not prevent closing with the anchor. 89 // Preventing close on deactivate should not prevent closing with the anchor.
90 bubble_delegate->set_close_on_deactivate(false); 90 bubble_delegate->set_close_on_deactivate(false);
91 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 91 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
92 EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate()); 92 EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate());
93 EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget()); 93 EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget());
94 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 94 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
95 test::TestWidgetObserver bubble_observer(bubble_widget); 95 test::TestWidgetObserver bubble_observer(bubble_widget);
96 EXPECT_FALSE(bubble_observer.widget_closed()); 96 EXPECT_FALSE(bubble_observer.widget_closed());
97 97
98 bubble_widget->Show(); 98 bubble_widget->Show();
99 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 99 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
100 EXPECT_FALSE(bubble_observer.widget_closed()); 100 EXPECT_FALSE(bubble_observer.widget_closed());
101 101
102 // TODO(msw): Remove activation hack to prevent bookkeeping errors in: 102 // TODO(msw): Remove activation hack to prevent bookkeeping errors in:
103 // aura::test::TestActivationClient::OnWindowDestroyed(). 103 // aura::test::TestActivationClient::OnWindowDestroyed().
104 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); 104 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget());
105 EXPECT_FALSE(bubble_observer.widget_closed()); 105 EXPECT_FALSE(bubble_observer.widget_closed());
106 106
107 // Ensure that closing the anchor widget also closes the bubble itself. 107 // Ensure that closing the anchor widget also closes the bubble itself.
108 anchor_widget->CloseNow(); 108 anchor_widget->CloseNow();
109 EXPECT_TRUE(bubble_observer.widget_closed()); 109 EXPECT_TRUE(bubble_observer.widget_closed());
110 } 110 }
111 111
112 // This test checks that the bubble delegate is capable to handle an early 112 // This test checks that the bubble delegate is capable to handle an early
113 // destruction of the used anchor view. (Animations and delayed closure of the 113 // destruction of the used anchor view. (Animations and delayed closure of the
114 // bubble will call upon the anchor view to get its location). 114 // bubble will call upon the anchor view to get its location).
115 TEST_F(BubbleDelegateTest, CloseAnchorViewTest) { 115 TEST_F(BubbleDelegateTest, CloseAnchorViewTest) {
116 // Create an anchor widget and add a view to be used as an anchor view. 116 // Create an anchor widget and add a view to be used as an anchor view.
117 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); 117 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
118 scoped_ptr<View> anchor_view(new View()); 118 scoped_ptr<View> anchor_view(new View());
119 anchor_widget->GetContentsView()->AddChildView(anchor_view.get()); 119 anchor_widget->GetContentsView()->AddChildView(anchor_view.get());
120 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView( 120 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView(
121 anchor_view.get()); 121 anchor_view.get());
122 // Prevent flakes by avoiding closing on activation changes. 122 // Prevent flakes by avoiding closing on activation changes.
123 bubble_delegate->set_close_on_deactivate(false); 123 bubble_delegate->set_close_on_deactivate(false);
124 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 124 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
125 125
126 // Check that the anchor view is correct and set up an anchor view rect. 126 // Check that the anchor view is correct and set up an anchor view rect.
127 // Make sure that this rect will get ignored (as long as the anchor view is 127 // Make sure that this rect will get ignored (as long as the anchor view is
128 // attached). 128 // attached).
129 EXPECT_EQ(anchor_view, bubble_delegate->GetAnchorView()); 129 EXPECT_EQ(anchor_view.get(), bubble_delegate->GetAnchorView());
130 const gfx::Rect set_anchor_rect = gfx::Rect(10, 10, 100, 100); 130 const gfx::Rect set_anchor_rect = gfx::Rect(10, 10, 100, 100);
131 bubble_delegate->SetAnchorRectForTest(set_anchor_rect); 131 bubble_delegate->SetAnchorRectForTest(set_anchor_rect);
132 const gfx::Rect view_rect = bubble_delegate->GetAnchorRect(); 132 const gfx::Rect view_rect = bubble_delegate->GetAnchorRect();
133 EXPECT_NE(view_rect.ToString(), set_anchor_rect.ToString()); 133 EXPECT_NE(view_rect.ToString(), set_anchor_rect.ToString());
134 134
135 // Create the bubble. 135 // Create the bubble.
136 bubble_widget->Show(); 136 bubble_widget->Show();
137 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 137 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
138 138
139 // Remove now the anchor view and make sure that the original found rect 139 // Remove now the anchor view and make sure that the original found rect
140 // is still kept, so that the bubble does not jump when the view gets deleted. 140 // is still kept, so that the bubble does not jump when the view gets deleted.
141 anchor_widget->GetContentsView()->RemoveChildView(anchor_view.get()); 141 anchor_widget->GetContentsView()->RemoveChildView(anchor_view.get());
142 anchor_view.reset(); 142 anchor_view.reset();
143 EXPECT_EQ(NULL, bubble_delegate->GetAnchorView()); 143 EXPECT_EQ(NULL, bubble_delegate->GetAnchorView());
144 EXPECT_EQ(view_rect.ToString(), bubble_delegate->GetAnchorRect().ToString()); 144 EXPECT_EQ(view_rect.ToString(), bubble_delegate->GetAnchorRect().ToString());
145 } 145 }
146 146
147 // Testing that a move of the anchor view will lead to new bubble locations. 147 // Testing that a move of the anchor view will lead to new bubble locations.
(...skipping 19 matching lines...) Expand all
167 167
168 // Make sure the bubble widget is parented to a widget other than the anchor 168 // Make sure the bubble widget is parented to a widget other than the anchor
169 // widget so that closing the anchor widget does not close the bubble widget. 169 // widget so that closing the anchor widget does not close the bubble widget.
170 scoped_ptr<Widget> parent_widget(CreateTestWidget()); 170 scoped_ptr<Widget> parent_widget(CreateTestWidget());
171 bubble_delegate->set_parent_window(parent_widget->GetNativeView()); 171 bubble_delegate->set_parent_window(parent_widget->GetNativeView());
172 // Preventing close on deactivate should not prevent closing with the parent. 172 // Preventing close on deactivate should not prevent closing with the parent.
173 bubble_delegate->set_close_on_deactivate(false); 173 bubble_delegate->set_close_on_deactivate(false);
174 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 174 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
175 EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate()); 175 EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate());
176 EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget()); 176 EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget());
177 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 177 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
178 test::TestWidgetObserver bubble_observer(bubble_widget); 178 test::TestWidgetObserver bubble_observer(bubble_widget);
179 EXPECT_FALSE(bubble_observer.widget_closed()); 179 EXPECT_FALSE(bubble_observer.widget_closed());
180 180
181 // Showing and hiding the bubble widget should have no effect on its anchor. 181 // Showing and hiding the bubble widget should have no effect on its anchor.
182 bubble_widget->Show(); 182 bubble_widget->Show();
183 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 183 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
184 bubble_widget->Hide(); 184 bubble_widget->Hide();
185 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); 185 EXPECT_EQ(anchor_widget.get(), bubble_delegate->anchor_widget());
186 186
187 // Ensure that closing the anchor widget clears the bubble's reference to that 187 // Ensure that closing the anchor widget clears the bubble's reference to that
188 // anchor widget, but the bubble itself does not close. 188 // anchor widget, but the bubble itself does not close.
189 anchor_widget->CloseNow(); 189 anchor_widget->CloseNow();
190 EXPECT_NE(anchor_widget, bubble_delegate->anchor_widget()); 190 EXPECT_NE(anchor_widget.get(), bubble_delegate->anchor_widget());
191 EXPECT_FALSE(bubble_observer.widget_closed()); 191 EXPECT_FALSE(bubble_observer.widget_closed());
192 192
193 // TODO(msw): Remove activation hack to prevent bookkeeping errors in: 193 // TODO(msw): Remove activation hack to prevent bookkeeping errors in:
194 // aura::test::TestActivationClient::OnWindowDestroyed(). 194 // aura::test::TestActivationClient::OnWindowDestroyed().
195 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); 195 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget());
196 EXPECT_FALSE(bubble_observer.widget_closed()); 196 EXPECT_FALSE(bubble_observer.widget_closed());
197 197
198 // Ensure that closing the parent widget also closes the bubble itself. 198 // Ensure that closing the parent widget also closes the bubble itself.
199 parent_widget->CloseNow(); 199 parent_widget->CloseNow();
200 EXPECT_TRUE(bubble_observer.widget_closed()); 200 EXPECT_TRUE(bubble_observer.widget_closed());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); 255 scoped_ptr<Widget> anchor_widget(CreateTestWidget());
256 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( 256 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
257 anchor_widget->GetContentsView(), BubbleBorder::NONE); 257 anchor_widget->GetContentsView(), BubbleBorder::NONE);
258 bubble_delegate->set_can_activate(false); 258 bubble_delegate->set_can_activate(false);
259 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); 259 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
260 bubble_widget->Show(); 260 bubble_widget->Show();
261 EXPECT_FALSE(bubble_widget->CanActivate()); 261 EXPECT_FALSE(bubble_widget->CanActivate());
262 } 262 }
263 263
264 } // namespace views 264 } // namespace views
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | ui/views/controls/webview/webview.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698