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

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: 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
« ui/views/bubble/bubble_delegate.cc ('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..e394b83f46dd8a45438a721d228f1940ef0e7120 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
msw 2013/09/06 16:32:00 nit: make the test a friend instead of wrapping th
Mr4D (OOO till 08-26) 2013/09/06 17:57:31 I was trying to not touch the class and instead ad
msw 2013/09/06 18:18:41 Moot, but I hoped you could add that friend test d
+ // public.
+ void set_anchor_view_for_test(View* anchor_view) {
+ set_anchor_view(anchor_view);
+ }
+ void set_anchor_rect_for_test(const gfx::Rect& rect) {
+ set_anchor_rect(rect);
+ }
+ void set_anchor_offset_for_test(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->set_anchor_offset_for_test(gfx::Point(20, 20));
+ bubble_delegate->set_anchor_view_for_test(NULL);
+ gfx::Rect static_anchor_rect(20, 20, 30, 30);
+ bubble_delegate->set_anchor_rect_for_test(static_anchor_rect);
+ EXPECT_EQ(static_anchor_rect.ToString(),
msw 2013/09/06 16:32:00 Doesn't Rect have an equality operator? Why do you
Mr4D (OOO till 08-26) 2013/09/06 17:57:31 Yes, it does - but when you get a failure it also
msw 2013/09/06 18:18:41 Moot, but EXPECT_EQ does actually output mismatchi
+ bubble_delegate->GetAnchorRect().ToString());
+ bubble_delegate->set_anchor_offset_for_test(gfx::Point(0, 0));
+ EXPECT_EQ(static_anchor_rect.ToString(),
+ bubble_delegate->GetAnchorRect().ToString());
+
+ // If an anchor view is provided, its coordinates should get returned.
+ gfx::Rect widget_bounds(
+ anchor_widget->GetContentsView()->GetBoundsInScreen());
+ bubble_delegate->set_anchor_view_for_test(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->set_anchor_offset_for_test(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/views/bubble/bubble_delegate.cc ('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