OLD | NEW |
---|---|
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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
6 #include "ui/base/hit_test.h" | 6 #include "ui/base/hit_test.h" |
7 #include "ui/views/bubble/bubble_delegate.h" | 7 #include "ui/views/bubble/bubble_delegate.h" |
8 #include "ui/views/bubble/bubble_frame_view.h" | 8 #include "ui/views/bubble/bubble_frame_view.h" |
9 #include "ui/views/test/test_widget_observer.h" | 9 #include "ui/views/test/test_widget_observer.h" |
10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 class TestBubbleDelegateView : public BubbleDelegateView { | 22 class TestBubbleDelegateView : public BubbleDelegateView { |
23 public: | 23 public: |
24 TestBubbleDelegateView(View* anchor_view) | 24 TestBubbleDelegateView(View* anchor_view) |
25 : BubbleDelegateView(anchor_view, BubbleBorder::TOP_LEFT), | 25 : BubbleDelegateView(anchor_view, BubbleBorder::TOP_LEFT), |
26 view_(new View()) { | 26 view_(new View()) { |
27 view_->set_focusable(true); | 27 view_->set_focusable(true); |
28 AddChildView(view_); | 28 AddChildView(view_); |
29 } | 29 } |
30 virtual ~TestBubbleDelegateView() {} | 30 virtual ~TestBubbleDelegateView() {} |
31 | 31 |
32 void SetAnchorRectForTest(gfx::Rect rect) { | |
33 set_anchor_rect(rect); | |
34 } | |
35 | |
36 void SetAnchorViewForTest(View* view) { | |
37 SetAnchorView(view); | |
38 } | |
39 | |
32 // BubbleDelegateView overrides: | 40 // BubbleDelegateView overrides: |
33 virtual View* GetInitiallyFocusedView() OVERRIDE { return view_; } | 41 virtual View* GetInitiallyFocusedView() OVERRIDE { return view_; } |
34 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } | 42 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } |
35 virtual int GetFadeDuration() OVERRIDE { return 1; } | 43 virtual int GetFadeDuration() OVERRIDE { return 1; } |
36 | 44 |
37 private: | 45 private: |
38 View* view_; | 46 View* view_; |
39 | 47 |
40 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); | 48 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); |
41 }; | 49 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 // aura::test::TestActivationClient::OnWindowDestroyed(). | 110 // aura::test::TestActivationClient::OnWindowDestroyed(). |
103 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); | 111 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); |
104 EXPECT_FALSE(bubble_observer.widget_closed()); | 112 EXPECT_FALSE(bubble_observer.widget_closed()); |
105 #endif | 113 #endif |
106 | 114 |
107 // Ensure that closing the anchor widget also closes the bubble itself. | 115 // Ensure that closing the anchor widget also closes the bubble itself. |
108 anchor_widget->CloseNow(); | 116 anchor_widget->CloseNow(); |
109 EXPECT_TRUE(bubble_observer.widget_closed()); | 117 EXPECT_TRUE(bubble_observer.widget_closed()); |
110 } | 118 } |
111 | 119 |
120 TEST_F(BubbleDelegateTest, CloseAnchorViewTest) { | |
121 // Create an anchor widget and add a view to be used as anchor view. | |
msw
2013/09/27 21:21:53
nit: "an anchor view."
Mr4D (OOO till 08-26)
2013/09/27 22:52:21
Done.
| |
122 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | |
123 scoped_ptr<View> anchor_view(new View()); | |
124 anchor_widget->GetContentsView()->AddChildView(anchor_view.get()); | |
125 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView( | |
126 anchor_view.get()); | |
127 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); | |
128 | |
129 // Check that the anchor view is correct and set up an anchor view rect. | |
130 // Make sure that this rect will get ignored (as long as the anchor view is | |
131 // attached). | |
132 EXPECT_EQ(anchor_view, bubble_delegate->GetAnchorView()); | |
133 EXPECT_TRUE(bubble_delegate->has_anchor_view()); | |
134 const gfx::Rect set_anchor_rect = gfx::Rect(10, 10, 100, 100); | |
135 bubble_delegate->SetAnchorRectForTest(set_anchor_rect); | |
136 const gfx::Rect view_rect = bubble_delegate->GetAnchorRect(); | |
137 EXPECT_NE(view_rect.ToString(), set_anchor_rect.ToString()); | |
138 | |
139 // Create the bubble. | |
140 bubble_widget->Show(); | |
141 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); | |
142 | |
143 // Remove now the anchor view and make sure that the original found rect | |
144 // is still kept, so that the bubble does not jump when the view gets deleted. | |
145 anchor_widget->GetContentsView()->RemoveChildView(anchor_view.get()); | |
146 anchor_view.reset(); | |
147 EXPECT_TRUE(bubble_delegate->has_anchor_view()); | |
148 EXPECT_EQ(NULL, bubble_delegate->GetAnchorView()); | |
149 EXPECT_EQ(view_rect.ToString(), bubble_delegate->GetAnchorRect().ToString()); | |
150 } | |
151 | |
152 TEST_F(BubbleDelegateTest, TestAnchorRectMovesWithViewTest) { | |
153 // Create an anchor widget and add a view to be used as anchor view. | |
154 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | |
155 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView( | |
156 anchor_widget->GetContentsView()); | |
157 BubbleDelegateView::CreateBubble(bubble_delegate); | |
158 | |
159 anchor_widget->GetContentsView()->SetBounds(10, 10, 100, 100); | |
160 const gfx::Rect view_rect = bubble_delegate->GetAnchorRect(); | |
161 | |
162 anchor_widget->GetContentsView()->SetBounds(20, 10, 100, 100); | |
163 const gfx::Rect view_rect_2 = bubble_delegate->GetAnchorRect(); | |
164 EXPECT_NE(view_rect.ToString(), view_rect_2.ToString()); | |
165 | |
msw
2013/09/27 21:21:53
nit: remove this blank line.
Mr4D (OOO till 08-26)
2013/09/27 22:52:21
Done.
| |
166 } | |
167 | |
112 TEST_F(BubbleDelegateTest, ResetAnchorWidget) { | 168 TEST_F(BubbleDelegateTest, ResetAnchorWidget) { |
113 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | 169 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); |
114 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( | 170 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( |
115 anchor_widget->GetContentsView(), BubbleBorder::NONE); | 171 anchor_widget->GetContentsView(), BubbleBorder::NONE); |
116 | 172 |
117 // Make sure the bubble widget is parented to a widget other than the anchor | 173 // Make sure the bubble widget is parented to a widget other than the anchor |
118 // widget so that closing the anchor widget does not close the bubble widget. | 174 // widget so that closing the anchor widget does not close the bubble widget. |
119 scoped_ptr<Widget> parent_widget(CreateTestWidget()); | 175 scoped_ptr<Widget> parent_widget(CreateTestWidget()); |
120 bubble_delegate->set_parent_window(parent_widget->GetNativeView()); | 176 bubble_delegate->set_parent_window(parent_widget->GetNativeView()); |
121 // Preventing close on deactivate should not prevent closing with the parent. | 177 // Preventing close on deactivate should not prevent closing with the parent. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 bubble_widget->GetFocusManager()->GetFocusedView()); | 295 bubble_widget->GetFocusManager()->GetFocusedView()); |
240 | 296 |
241 Observe(bubble_widget); | 297 Observe(bubble_widget); |
242 | 298 |
243 bubble_delegate->StartFade(false); | 299 bubble_delegate->StartFade(false); |
244 RunNestedLoop(); | 300 RunNestedLoop(); |
245 EXPECT_TRUE(bubble_destroyed()); | 301 EXPECT_TRUE(bubble_destroyed()); |
246 } | 302 } |
247 | 303 |
248 } // namespace views | 304 } // namespace views |
OLD | NEW |