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

Side by Side Diff: ui/views/bubble/bubble_frame_view_unittest.cc

Issue 10808066: Fix position of web notification bubble and arrow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 4 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 unified diff | Download patch
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/base/hit_test.h" 5 #include "ui/base/hit_test.h"
6 #include "ui/gfx/insets.h" 6 #include "ui/gfx/insets.h"
7 #include "ui/views/bubble/bubble_border.h" 7 #include "ui/views/bubble/bubble_border.h"
8 #include "ui/views/bubble/bubble_delegate.h" 8 #include "ui/views/bubble/bubble_delegate.h"
9 #include "ui/views/bubble/bubble_frame_view.h" 9 #include "ui/views/bubble/bubble_frame_view.h"
10 #include "ui/views/test/views_test_base.h" 10 #include "ui/views/test/views_test_base.h"
(...skipping 26 matching lines...) Expand all
37 SizedBubbleDelegateView::SizedBubbleDelegateView() {} 37 SizedBubbleDelegateView::SizedBubbleDelegateView() {}
38 38
39 SizedBubbleDelegateView::~SizedBubbleDelegateView() {} 39 SizedBubbleDelegateView::~SizedBubbleDelegateView() {}
40 40
41 gfx::Size SizedBubbleDelegateView::GetPreferredSize() { 41 gfx::Size SizedBubbleDelegateView::GetPreferredSize() {
42 return gfx::Size(kBubbleWidth, kBubbleHeight); 42 return gfx::Size(kBubbleWidth, kBubbleHeight);
43 } 43 }
44 44
45 class TestBubbleFrameView : public BubbleFrameView { 45 class TestBubbleFrameView : public BubbleFrameView {
46 public: 46 public:
47 explicit TestBubbleFrameView(const gfx::Rect& bounds); 47 TestBubbleFrameView();
48 virtual ~TestBubbleFrameView(); 48 virtual ~TestBubbleFrameView();
49 49
50 protected: 50 protected:
51 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE; 51 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE;
52 52
53 private: 53 private:
54 gfx::Rect monitor_bounds_; 54 gfx::Rect monitor_bounds_;
55 55
56 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); 56 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
57 }; 57 };
58 58
59 TestBubbleFrameView::TestBubbleFrameView(const gfx::Rect& bounds) 59 TestBubbleFrameView::TestBubbleFrameView()
60 : BubbleFrameView(kArrow, kBackgroundColor, 60 : BubbleFrameView(gfx::Insets(kDefaultMargin,
61 gfx::Insets(kDefaultMargin, 61 kDefaultMargin,
62 kDefaultMargin, 62 kDefaultMargin,
63 kDefaultMargin, 63 kDefaultMargin),
64 kDefaultMargin)), 64 new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW)),
65 monitor_bounds_(bounds) { 65 monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
66 bubble_border()->set_background_color(kBackgroundColor);
66 } 67 }
67 68
68 TestBubbleFrameView::~TestBubbleFrameView() {} 69 TestBubbleFrameView::~TestBubbleFrameView() {}
69 70
70 gfx::Rect TestBubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) { 71 gfx::Rect TestBubbleFrameView::GetMonitorBounds(const gfx::Rect& rect) {
71 return monitor_bounds_; 72 return monitor_bounds_;
72 } 73 }
73 74
74 } // namespace 75 } // namespace
75 76
76 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { 77 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
77 BubbleFrameView frame( 78 TestBubbleFrameView frame;
78 kArrow,
79 kBackgroundColor,
80 gfx::Insets(kDefaultMargin, kDefaultMargin, kDefaultMargin,
81 kDefaultMargin));
82 EXPECT_EQ(kArrow, frame.bubble_border()->arrow_location()); 79 EXPECT_EQ(kArrow, frame.bubble_border()->arrow_location());
83 EXPECT_EQ(kBackgroundColor, frame.bubble_border()->background_color()); 80 EXPECT_EQ(kBackgroundColor, frame.bubble_border()->background_color());
84 81
85 int margin_x = frame.content_margins().left(); 82 int margin_x = frame.content_margins().left();
86 int margin_y = frame.content_margins().top(); 83 int margin_y = frame.content_margins().top();
87 gfx::Insets insets; 84 gfx::Insets insets;
88 frame.bubble_border()->GetInsets(&insets); 85 frame.bubble_border()->GetInsets(&insets);
89 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); 86 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x());
90 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); 87 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y());
91 } 88 }
92 89
93 TEST_F(BubbleFrameViewTest, NonClientHitTest) { 90 TEST_F(BubbleFrameViewTest, NonClientHitTest) {
94 BubbleDelegateView* delegate = new SizedBubbleDelegateView(); 91 BubbleDelegateView* delegate = new SizedBubbleDelegateView();
95 Widget* widget(BubbleDelegateView::CreateBubble(delegate)); 92 Widget* widget(BubbleDelegateView::CreateBubble(delegate));
96 delegate->Show(); 93 delegate->Show();
97 gfx::Point kPtInBound(100, 100); 94 gfx::Point kPtInBound(100, 100);
98 gfx::Point kPtOutsideBound(1000, 1000); 95 gfx::Point kPtOutsideBound(1000, 1000);
99 BubbleFrameView* bubble_frame_view = delegate->GetBubbleFrameView(); 96 BubbleFrameView* bubble_frame_view = delegate->GetBubbleFrameView();
100 EXPECT_EQ(HTCLIENT, bubble_frame_view->NonClientHitTest(kPtInBound)); 97 EXPECT_EQ(HTCLIENT, bubble_frame_view->NonClientHitTest(kPtInBound));
101 EXPECT_EQ(HTNOWHERE, bubble_frame_view->NonClientHitTest(kPtOutsideBound)); 98 EXPECT_EQ(HTNOWHERE, bubble_frame_view->NonClientHitTest(kPtOutsideBound));
102 widget->CloseNow(); 99 widget->CloseNow();
103 RunPendingMessages(); 100 RunPendingMessages();
104 } 101 }
105 102
106 // Tests that the arrow is mirrored as needed to better fit the screen. 103 // Tests that the arrow is mirrored as needed to better fit the screen.
107 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { 104 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) {
108 TestBubbleFrameView frame(gfx::Rect(0, 0, 1000, 1000)); 105 TestBubbleFrameView frame;
109 gfx::Rect window_bounds; 106 gfx::Rect window_bounds;
110 107
111 gfx::Insets insets; 108 gfx::Insets insets;
112 frame.bubble_border()->GetInsets(&insets); 109 frame.bubble_border()->GetInsets(&insets);
113 int xposition = 95 - insets.width(); 110 int xposition = 95 - insets.width();
114 111
115 // Test that the info bubble displays normally when it fits. 112 // Test that the info bubble displays normally when it fits.
116 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_LEFT); 113 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_LEFT);
117 window_bounds = frame.GetUpdatedWindowBounds( 114 window_bounds = frame.GetUpdatedWindowBounds(
118 gfx::Rect(100, 100, 50, 50), // |anchor_rect| 115 gfx::Rect(100, 100, 50, 50), // |anchor_rect|
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow_location()); 208 EXPECT_EQ(BubbleBorder::BOTTOM_LEFT, frame.bubble_border()->arrow_location());
212 // The window should be right aligned with the anchor_rect. 209 // The window should be right aligned with the anchor_rect.
213 EXPECT_LT(window_bounds.x(), 900 + 50 - 500); 210 EXPECT_LT(window_bounds.x(), 900 + 50 - 500);
214 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate 211 EXPECT_LT(window_bounds.y(), 900 - 500 - 15); // -15 to roughly compensate
215 // for arrow height. 212 // for arrow height.
216 } 213 }
217 214
218 // Tests that the arrow is not moved when the info-bubble does not fit the 215 // Tests that the arrow is not moved when the info-bubble does not fit the
219 // screen but moving it would make matter worse. 216 // screen but moving it would make matter worse.
220 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsMirroringFails) { 217 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsMirroringFails) {
221 TestBubbleFrameView frame(gfx::Rect(0, 0, 1000, 1000)); 218 TestBubbleFrameView frame;
222 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_LEFT); 219 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_LEFT);
223 gfx::Rect window_bounds = frame.GetUpdatedWindowBounds( 220 gfx::Rect window_bounds = frame.GetUpdatedWindowBounds(
224 gfx::Rect(400, 100, 50, 50), // |anchor_rect| 221 gfx::Rect(400, 100, 50, 50), // |anchor_rect|
225 gfx::Size(500, 700), // |client_size| 222 gfx::Size(500, 700), // |client_size|
226 true); // |try_mirroring_arrow| 223 true); // |try_mirroring_arrow|
227 EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location()); 224 EXPECT_EQ(BubbleBorder::TOP_LEFT, frame.bubble_border()->arrow_location());
228 } 225 }
229 226
230 // Test that the arrow will not be mirrored when |try_mirroring_arrow| is false. 227 // Test that the arrow will not be mirrored when |try_mirroring_arrow| is false.
231 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsDontTryMirror) { 228 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBoundsDontTryMirror) {
232 TestBubbleFrameView frame(gfx::Rect(0, 0, 1000, 1000)); 229 TestBubbleFrameView frame;
233 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_RIGHT); 230 frame.bubble_border()->set_arrow_location(BubbleBorder::TOP_RIGHT);
234 gfx::Rect window_bounds = frame.GetUpdatedWindowBounds( 231 gfx::Rect window_bounds = frame.GetUpdatedWindowBounds(
235 gfx::Rect(100, 900, 50, 50), // |anchor_rect| 232 gfx::Rect(100, 900, 50, 50), // |anchor_rect|
236 gfx::Size(500, 500), // |client_size| 233 gfx::Size(500, 500), // |client_size|
237 false); // |try_mirroring_arrow| 234 false); // |try_mirroring_arrow|
238 EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow_location()); 235 EXPECT_EQ(BubbleBorder::TOP_RIGHT, frame.bubble_border()->arrow_location());
239 // The coordinates should be pointing to anchor_rect from TOP_RIGHT. 236 // The coordinates should be pointing to anchor_rect from TOP_RIGHT.
240 EXPECT_LT(window_bounds.x(), 100 + 50 - 500); 237 EXPECT_LT(window_bounds.x(), 100 + 50 - 500);
241 EXPECT_GT(window_bounds.y(), 900 + 50 - 10); // -10 to roughly compensate for 238 EXPECT_GT(window_bounds.y(), 900 + 50 - 10); // -10 to roughly compensate for
242 // arrow overlap. 239 // arrow overlap.
243 } 240 }
244 241
245 } // namespace views 242 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_frame_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698