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 16 matching lines...) Expand all Loading... | |
| 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 // BubbleDelegateView overrides: | 32 // BubbleDelegateView overrides: |
| 33 virtual View* GetInitiallyFocusedView() OVERRIDE { return view_; } | 33 virtual View* GetInitiallyFocusedView() OVERRIDE { return view_; } |
| 34 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } | 34 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); } |
| 35 virtual int GetFadeDuration() OVERRIDE { return 1; } | 35 virtual int GetFadeDuration() OVERRIDE { return 1; } |
| 36 | 36 |
| 37 // Accessors for the protected anchor functionality - avoiding making them | |
| 38 // public. | |
| 39 void test_set_anchor_view(View* anchor_view) { | |
|
James Cook
2013/09/05 20:05:17
nit: set_anchor_view_for_test?
Mr4D (OOO till 08-26)
2013/09/05 20:52:00
Done.
| |
| 40 set_anchor_view(anchor_view); | |
| 41 } | |
| 42 void test_set_anchor_rect(const gfx::Rect& rect) { | |
| 43 set_anchor_rect(rect); | |
| 44 } | |
| 45 void test_set_anchor_offset(const gfx::Point& offset) { | |
| 46 set_anchor_offset(offset); | |
| 47 } | |
| 48 | |
| 37 private: | 49 private: |
| 38 View* view_; | 50 View* view_; |
| 39 | 51 |
| 40 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); | 52 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView); |
| 41 }; | 53 }; |
| 42 | 54 |
| 43 class BubbleDelegateTest : public ViewsTestBase { | 55 class BubbleDelegateTest : public ViewsTestBase { |
| 44 public: | 56 public: |
| 45 BubbleDelegateTest() {} | 57 BubbleDelegateTest() {} |
| 46 virtual ~BubbleDelegateTest() {} | 58 virtual ~BubbleDelegateTest() {} |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 // aura::test::TestActivationClient::OnWindowDestroyed(). | 156 // aura::test::TestActivationClient::OnWindowDestroyed(). |
| 145 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); | 157 scoped_ptr<Widget> smoke_and_mirrors_widget(CreateTestWidget()); |
| 146 EXPECT_FALSE(bubble_observer.widget_closed()); | 158 EXPECT_FALSE(bubble_observer.widget_closed()); |
| 147 #endif | 159 #endif |
| 148 | 160 |
| 149 // Ensure that closing the parent widget also closes the bubble itself. | 161 // Ensure that closing the parent widget also closes the bubble itself. |
| 150 parent_widget->CloseNow(); | 162 parent_widget->CloseNow(); |
| 151 EXPECT_TRUE(bubble_observer.widget_closed()); | 163 EXPECT_TRUE(bubble_observer.widget_closed()); |
| 152 } | 164 } |
| 153 | 165 |
| 166 TEST_F(BubbleDelegateTest, OffsetAnchorCoordinates) { | |
| 167 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | |
| 168 TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView( | |
| 169 anchor_widget->GetContentsView()); | |
| 170 | |
| 171 // If no anchor is given the provided anchor rectangle should get returned and | |
| 172 // the offset should get ignored. | |
| 173 bubble_delegate->test_set_anchor_offset(gfx::Point(20, 20)); | |
| 174 bubble_delegate->test_set_anchor_view(NULL); | |
| 175 gfx::Rect static_anchor_rect(20, 20, 30, 30); | |
| 176 bubble_delegate->test_set_anchor_rect(static_anchor_rect); | |
| 177 EXPECT_EQ(static_anchor_rect.ToString(), | |
| 178 bubble_delegate->GetAnchorRect().ToString()); | |
| 179 bubble_delegate->test_set_anchor_offset(gfx::Point(0, 0)); | |
| 180 EXPECT_EQ(static_anchor_rect.ToString(), | |
| 181 bubble_delegate->GetAnchorRect().ToString()); | |
| 182 | |
| 183 // If an anchor view is provided, it's coordinates should get returned. | |
|
James Cook
2013/09/05 20:05:17
nit: it's -> its
Mr4D (OOO till 08-26)
2013/09/05 20:52:00
Done.
| |
| 184 gfx::Rect widget_bounds( | |
| 185 anchor_widget->GetContentsView()->GetBoundsInScreen()); | |
| 186 bubble_delegate->test_set_anchor_view(anchor_widget->GetContentsView()); | |
| 187 EXPECT_EQ(widget_bounds.ToString(), | |
| 188 bubble_delegate->GetAnchorRect().ToString()); | |
| 189 | |
| 190 // If the offset is provided, it should get added to the bounds of the widget. | |
| 191 bubble_delegate->test_set_anchor_offset(gfx::Point(20, 20)); | |
| 192 EXPECT_EQ(gfx::Rect(widget_bounds.x() + 20, | |
| 193 widget_bounds.y() + 20, | |
| 194 widget_bounds.width(), | |
| 195 widget_bounds.height()).ToString(), | |
| 196 bubble_delegate->GetAnchorRect().ToString()); | |
| 197 } | |
| 198 | |
| 154 TEST_F(BubbleDelegateTest, InitiallyFocusedView) { | 199 TEST_F(BubbleDelegateTest, InitiallyFocusedView) { |
| 155 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); | 200 scoped_ptr<Widget> anchor_widget(CreateTestWidget()); |
| 156 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( | 201 BubbleDelegateView* bubble_delegate = new BubbleDelegateView( |
| 157 anchor_widget->GetContentsView(), BubbleBorder::NONE); | 202 anchor_widget->GetContentsView(), BubbleBorder::NONE); |
| 158 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); | 203 Widget* bubble_widget = BubbleDelegateView::CreateBubble(bubble_delegate); |
| 159 EXPECT_EQ(bubble_delegate->GetInitiallyFocusedView(), | 204 EXPECT_EQ(bubble_delegate->GetInitiallyFocusedView(), |
| 160 bubble_widget->GetFocusManager()->GetFocusedView()); | 205 bubble_widget->GetFocusManager()->GetFocusedView()); |
| 161 bubble_widget->CloseNow(); | 206 bubble_widget->CloseNow(); |
| 162 } | 207 } |
| 163 | 208 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 bubble_widget->GetFocusManager()->GetFocusedView()); | 284 bubble_widget->GetFocusManager()->GetFocusedView()); |
| 240 | 285 |
| 241 Observe(bubble_widget); | 286 Observe(bubble_widget); |
| 242 | 287 |
| 243 bubble_delegate->StartFade(false); | 288 bubble_delegate->StartFade(false); |
| 244 RunNestedLoop(); | 289 RunNestedLoop(); |
| 245 EXPECT_TRUE(bubble_destroyed()); | 290 EXPECT_TRUE(bubble_destroyed()); |
| 246 } | 291 } |
| 247 | 292 |
| 248 } // namespace views | 293 } // namespace views |
| OLD | NEW |