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

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

Issue 23622020: Fixing the dynamic positioning (move with anchor) for the app launcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit test 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
« ui/app_list/views/app_list_view.h ('K') | « ui/views/bubble/bubble_delegate.cc ('k') | no next file » | 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..e91a68764623e65510411ce8cf52b3b9a09446ff 100644
--- a/ui/views/bubble/bubble_delegate_unittest.cc
+++ b/ui/views/bubble/bubble_delegate_unittest.cc
@@ -34,6 +34,18 @@ class TestBubbleDelegateView : public BubbleDelegateView {
virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); }
virtual int GetFadeDuration() OVERRIDE { return 1; }
+ // Accessors for the protected anchor functionality - avoiding making them
+ // public.
+ 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.
+ set_anchor_view(anchor_view);
+ }
+ void test_set_anchor_rect(const gfx::Rect& rect) {
+ set_anchor_rect(rect);
+ }
+ void test_set_anchor_offset(const gfx::Point& offset) {
+ set_anchor_offset(offset);
+ }
+
private:
View* view_;
@@ -151,6 +163,39 @@ TEST_F(BubbleDelegateTest, ResetAnchorWidget) {
EXPECT_TRUE(bubble_observer.widget_closed());
}
+TEST_F(BubbleDelegateTest, OffsetAnchorCoordinates) {
+ scoped_ptr<Widget> anchor_widget(CreateTestWidget());
+ TestBubbleDelegateView* bubble_delegate = new TestBubbleDelegateView(
+ anchor_widget->GetContentsView());
+
+ // If no anchor is given the provided anchor rectangle should get returned and
+ // the offset should get ignored.
+ bubble_delegate->test_set_anchor_offset(gfx::Point(20, 20));
+ bubble_delegate->test_set_anchor_view(NULL);
+ gfx::Rect static_anchor_rect(20, 20, 30, 30);
+ bubble_delegate->test_set_anchor_rect(static_anchor_rect);
+ EXPECT_EQ(static_anchor_rect.ToString(),
+ bubble_delegate->GetAnchorRect().ToString());
+ bubble_delegate->test_set_anchor_offset(gfx::Point(0, 0));
+ EXPECT_EQ(static_anchor_rect.ToString(),
+ bubble_delegate->GetAnchorRect().ToString());
+
+ // 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.
+ gfx::Rect widget_bounds(
+ anchor_widget->GetContentsView()->GetBoundsInScreen());
+ bubble_delegate->test_set_anchor_view(anchor_widget->GetContentsView());
+ EXPECT_EQ(widget_bounds.ToString(),
+ bubble_delegate->GetAnchorRect().ToString());
+
+ // If the offset is provided, it should get added to the bounds of the widget.
+ bubble_delegate->test_set_anchor_offset(gfx::Point(20, 20));
+ EXPECT_EQ(gfx::Rect(widget_bounds.x() + 20,
+ widget_bounds.y() + 20,
+ widget_bounds.width(),
+ widget_bounds.height()).ToString(),
+ bubble_delegate->GetAnchorRect().ToString());
+}
+
TEST_F(BubbleDelegateTest, InitiallyFocusedView) {
scoped_ptr<Widget> anchor_widget(CreateTestWidget());
BubbleDelegateView* bubble_delegate = new BubbleDelegateView(
« ui/app_list/views/app_list_view.h ('K') | « ui/views/bubble/bubble_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698