Chromium Code Reviews| 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 SetAnchorRect(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 which has multiple views, one of them will be used | |
|
msw
2013/09/27 18:20:31
I don't see multiple views, revise this comment.
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Well there is already the content view. Therefore
| |
| 122 // as anchor view. | |
| 123 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | |
| 124 scoped_ptr<View> anchor_view(new View()); | |
|
msw
2013/09/27 18:20:31
Do not use a scoped_ptr here, the View is owned by
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
That is not correct. The view will get removed fro
msw
2013/09/27 21:21:52
Nope, I incorrectly assumed that RemoveChildView w
| |
| 125 anchor_widget->GetContentsView()->AddChildView(anchor_view.get()); | |
| 126 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView( | |
| 127 anchor_view.get()); | |
| 128 // Preventing close on deactivate should not prevent closing with the anchor. | |
|
msw
2013/09/27 18:20:31
Why are you testing this and calling set_close_on_
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 129 bubble_delegate->set_close_on_deactivate(false); | |
| 130 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); | |
| 131 EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate()); | |
|
msw
2013/09/27 18:20:31
Remove the expectations checked by other tests, th
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 132 EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget()); | |
| 133 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); | |
| 134 test::TestWidgetObserver bubble_observer(bubble_widget); | |
|
msw
2013/09/27 18:20:31
Remove this observer, it's not needed for this tes
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 135 EXPECT_FALSE(bubble_observer.widget_closed()); | |
| 136 // Check that the anchor view is correct and set up an anchor view rect. | |
|
msw
2013/09/27 18:20:31
It's probably good to test that the anchor_view bo
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Not quite sure I get what you are asking for here.
msw
2013/09/27 21:21:52
I'm asking you to simplify this test. The interact
| |
| 137 // Make sure that this rect will get ignored (as long as the anchor view is | |
| 138 // attached). | |
| 139 EXPECT_EQ(anchor_view, bubble_delegate->AnchorView()); | |
| 140 EXPECT_TRUE(bubble_delegate->has_anchor_view()); | |
| 141 gfx::Rect set_anchor_rect = gfx::Rect(10, 10, 100, 100); | |
|
msw
2013/09/27 18:20:31
nit: const.
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 142 bubble_delegate->SetAnchorRectForTest(set_anchor_rect); | |
| 143 gfx::Rect view_rect = bubble_delegate->GetAnchorRect(); | |
|
msw
2013/09/27 18:20:31
nit: const.
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 144 EXPECT_NE(view_rect.ToString(), set_anchor_rect.ToString()); | |
| 145 | |
| 146 // Create the bubble. | |
| 147 bubble_widget->Show(); | |
| 148 EXPECT_EQ(anchor_widget, bubble_delegate->anchor_widget()); | |
| 149 EXPECT_FALSE(bubble_observer.widget_closed()); | |
| 150 | |
| 151 // Remove now the anchor view and make sure that the original found rect | |
| 152 // is still kept, so that the bubble does not jump when the view gets deleted. | |
| 153 anchor_widget->GetContentsView()->RemoveChildView(anchor_view.get()); | |
| 154 anchor_view.reset(); | |
| 155 EXPECT_TRUE(bubble_delegate->has_anchor_view()); | |
| 156 EXPECT_EQ(NULL, bubble_delegate->AnchorView()); | |
| 157 EXPECT_EQ(view_rect.ToString(), bubble_delegate->GetAnchorRect().ToString()); | |
| 158 | |
| 159 // Inform now the bubble that the anchor view is gone and expect it to | |
|
msw
2013/09/27 18:20:31
I think this behavior is unnecessary; is it ever u
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
You asked for this yesterday. Done. removed.
| |
| 160 // remember the originally set anchor rect which was ignored till now. | |
| 161 bubble_delegate->SetAnchorViewForTest(NULL); | |
| 162 EXPECT_FALSE(bubble_delegate->has_anchor_view()); | |
| 163 EXPECT_EQ(set_anchor_rect.ToString(), | |
| 164 bubble_delegate->GetAnchorRect().ToString()); | |
| 165 | |
| 166 // Ensure that closing the anchor widget also closes the bubble itself. | |
|
msw
2013/09/27 18:20:31
This test does not need to check this.
Mr4D (OOO till 08-26)
2013/09/27 20:29:35
Done.
| |
| 167 anchor_widget->CloseNow(); | |
| 168 EXPECT_TRUE(bubble_observer.widget_closed()); | |
| 169 } | |
| 170 | |
| 112 TEST_F(BubbleDelegateTest, ResetAnchorWidget) { | 171 TEST_F(BubbleDelegateTest, ResetAnchorWidget) { |
| 113 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | 172 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); |
| 114 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( | 173 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( |
| 115 anchor_widget->GetContentsView(), BubbleBorder::NONE); | 174 anchor_widget->GetContentsView(), BubbleBorder::NONE); |
| 116 | 175 |
| 117 // Make sure the bubble widget is parented to a widget other than the anchor | 176 // 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. | 177 // widget so that closing the anchor widget does not close the bubble widget. |
| 119 scoped_ptr<Widget> parent_widget(CreateTestWidget()); | 178 scoped_ptr<Widget> parent_widget(CreateTestWidget()); |
| 120 bubble_delegate->set_parent_window(parent_widget->GetNativeView()); | 179 bubble_delegate->set_parent_window(parent_widget->GetNativeView()); |
| 121 // Preventing close on deactivate should not prevent closing with the parent. | 180 // 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()); | 298 bubble_widget->GetFocusManager()->GetFocusedView()); |
| 240 | 299 |
| 241 Observe(bubble_widget); | 300 Observe(bubble_widget); |
| 242 | 301 |
| 243 bubble_delegate->StartFade(false); | 302 bubble_delegate->StartFade(false); |
| 244 RunNestedLoop(); | 303 RunNestedLoop(); |
| 245 EXPECT_TRUE(bubble_destroyed()); | 304 EXPECT_TRUE(bubble_destroyed()); |
| 246 } | 305 } |
| 247 | 306 |
| 248 } // namespace views | 307 } // namespace views |
| OLD | NEW |