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

Unified Diff: ui/views/bubble/bubble_delegate_unittest.cc

Issue 24469006: Fixing crash Report - Magic Signature: views::View::ConvertPointToScreen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/bubble/bubble_delegate.cc ('k') | ui/views/bubble/tray_bubble_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/bubble/bubble_delegate_unittest.cc
diff --git a/ui/views/bubble/bubble_delegate_unittest.cc b/ui/views/bubble/bubble_delegate_unittest.cc
index 5cf4a377ec521ae4380d288f3d651bca70993efa..10763c3f4a40eebf8ae6ed2ae83b0195f655a000 100644
--- a/ui/views/bubble/bubble_delegate_unittest.cc
+++ b/ui/views/bubble/bubble_delegate_unittest.cc
@@ -29,6 +29,14 @@ class TestBubbleDelegateView : public BubbleDelegateView {
}
virtual ~TestBubbleDelegateView() {}
+ void SetAnchorRectForTest(gfx::Rect rect) {
+ set_anchor_rect(rect);
+ }
+
+ void SetAnchorViewForTest(View* view) {
+ SetAnchorView(view);
+ }
+
// BubbleDelegateView overrides:
virtual View* GetInitiallyFocusedView() OVERRIDE { return view_; }
virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); }
@@ -109,6 +117,57 @@ TEST_F(BubbleDelegateTest, CloseAnchorWidget) {
EXPECT_TRUE(bubble_observer.widget_closed());
}
+// This test checks that the bubble delegate is capable to handle an early
+// destruction of the used anchor view. (Animations and delayed closure of the
+// bubble will call upon the anchor view to get its location).
+TEST_F(BubbleDelegateTest, CloseAnchorViewTest) {
+ // Create an anchor widget and add a view to be used as an anchor view.
+ scoped_ptr<Widget> anchor_widget(CreateTestWidget());
+ scoped_ptr<View> anchor_view(new View());
+ anchor_widget->GetContentsView()->AddChildView(anchor_view.get());
+ TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView(
+ anchor_view.get());
+ // Prevent flakes by avoiding closing on activation changes.
+ bubble_delegate->set_close_on_deactivate(false);
+ Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate);
+
+ // Check that the anchor view is correct and set up an anchor view rect.
+ // Make sure that this rect will get ignored (as long as the anchor view is
+ // attached).
+ EXPECT_EQ(anchor_view, bubble_delegate->GetAnchorView());
+ const gfx::Rect set_anchor_rect = gfx::Rect(10, 10, 100, 100);
+ bubble_delegate->SetAnchorRectForTest(set_anchor_rect);
+ const gfx::Rect view_rect = bubble_delegate->GetAnchorRect();
+ EXPECT_NE(view_rect.ToString(), set_anchor_rect.ToString());
+
+ // Create the bubble.
+ bubble_widget->Show();
+ EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget());
+
+ // Remove now the anchor view and make sure that the original found rect
+ // is still kept, so that the bubble does not jump when the view gets deleted.
+ anchor_widget->GetContentsView()->RemoveChildView(anchor_view.get());
+ anchor_view.reset();
+ EXPECT_EQ(NULL, bubble_delegate->GetAnchorView());
+ EXPECT_EQ(view_rect.ToString(), bubble_delegate->GetAnchorRect().ToString());
+}
+
+// Testing that a move of the anchor view will lead to new bubble locations.
+TEST_F(BubbleDelegateTest, TestAnchorRectMovesWithViewTest) {
+ // Create an anchor widget and add a view to be used as anchor view.
+ scoped_ptr<Widget> anchor_widget(CreateTestWidget());
+ TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView(
+ anchor_widget->GetContentsView());
+ BubbleDelegateView::CreateBubble(bubble_delegate);
+
+ anchor_widget->GetContentsView()->SetBounds(10, 10, 100, 100);
+ const gfx::Rect view_rect = bubble_delegate->GetAnchorRect();
+
+ anchor_widget->GetContentsView()->SetBounds(20, 10, 100, 100);
+ const gfx::Rect view_rect_2 = bubble_delegate->GetAnchorRect();
+ EXPECT_NE(view_rect.ToString(), view_rect_2.ToString());
+}
+
TEST_F(BubbleDelegateTest, ResetAnchorWidget) {
scoped_ptr<Widget> anchor_widget(CreateTestWidget());
BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
« no previous file with comments | « ui/views/bubble/bubble_delegate.cc ('k') | ui/views/bubble/tray_bubble_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698