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

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

Issue 22320003: Cleanup Views bubble tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Views bubble tests. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/bubble/bubble_delegate_unittest.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"
6 #include "ui/gfx/insets.h" 5 #include "ui/gfx/insets.h"
7 #include "ui/views/bubble/bubble_border.h" 6 #include "ui/views/bubble/bubble_border.h"
8 #include "ui/views/bubble/bubble_delegate.h"
9 #include "ui/views/bubble/bubble_frame_view.h" 7 #include "ui/views/bubble/bubble_frame_view.h"
10 #include "ui/views/test/views_test_base.h" 8 #include "ui/views/test/views_test_base.h"
11 #include "ui/views/widget/widget.h" 9 #include "ui/views/widget/widget.h"
12 10
13 namespace views { 11 namespace views {
14 12
15 typedef ViewsTestBase BubbleFrameViewTest; 13 typedef ViewsTestBase BubbleFrameViewTest;
16 14
17 namespace { 15 namespace {
18 16
19 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT; 17 const BubbleBorder::Arrow kArrow = BubbleBorder::TOP_LEFT;
20 const SkColor kColor = SK_ColorRED; 18 const SkColor kColor = SK_ColorRED;
21 const int kMargin = 6; 19 const int kMargin = 6;
22 20
23 class TestBubbleDelegateView : public BubbleDelegateView {
24 public:
25 explicit TestBubbleDelegateView(View* anchor_view)
26 : BubbleDelegateView(anchor_view, kArrow) {}
27 virtual ~TestBubbleDelegateView() {}
28
29 // BubbleDelegateView overrides:
30 virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(200, 200); }
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(TestBubbleDelegateView);
34 };
35
36 class TestBubbleFrameView : public BubbleFrameView { 21 class TestBubbleFrameView : public BubbleFrameView {
37 public: 22 public:
38 TestBubbleFrameView() 23 TestBubbleFrameView()
39 : BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)), 24 : BubbleFrameView(gfx::Insets(kMargin, kMargin, kMargin, kMargin)),
40 monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) { 25 monitor_bounds_(gfx::Rect(0, 0, 1000, 1000)) {
41 SetBubbleBorder(new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor)); 26 SetBubbleBorder(new BubbleBorder(kArrow, BubbleBorder::NO_SHADOW, kColor));
42 } 27 }
43 virtual ~TestBubbleFrameView() {} 28 virtual ~TestBubbleFrameView() {}
44 29
45 // BubbleDelegateView overrides: 30 // BubbleFrameView overrides:
46 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE { 31 virtual gfx::Rect GetMonitorBounds(const gfx::Rect& rect) OVERRIDE {
47 return monitor_bounds_; 32 return monitor_bounds_;
48 } 33 }
49 34
50 private: 35 private:
51 gfx::Rect monitor_bounds_; 36 gfx::Rect monitor_bounds_;
52 37
53 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView); 38 DISALLOW_COPY_AND_ASSIGN(TestBubbleFrameView);
54 }; 39 };
55 40
56 } // namespace 41 } // namespace
57 42
58 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) { 43 TEST_F(BubbleFrameViewTest, GetBoundsForClientView) {
59 TestBubbleFrameView frame; 44 TestBubbleFrameView frame;
60 EXPECT_EQ(kArrow, frame.bubble_border()->arrow()); 45 EXPECT_EQ(kArrow, frame.bubble_border()->arrow());
61 EXPECT_EQ(kColor, frame.bubble_border()->background_color()); 46 EXPECT_EQ(kColor, frame.bubble_border()->background_color());
62 47
63 int margin_x = frame.content_margins().left(); 48 int margin_x = frame.content_margins().left();
64 int margin_y = frame.content_margins().top(); 49 int margin_y = frame.content_margins().top();
65 gfx::Insets insets = frame.bubble_border()->GetInsets(); 50 gfx::Insets insets = frame.bubble_border()->GetInsets();
66 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x()); 51 EXPECT_EQ(insets.left() + margin_x, frame.GetBoundsForClientView().x());
67 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y()); 52 EXPECT_EQ(insets.top() + margin_y, frame.GetBoundsForClientView().y());
68 } 53 }
69 54
70 TEST_F(BubbleFrameViewTest, NonClientHitTest) {
71 // Create the anchor view, its parent widget is needed on Aura.
72 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
73 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
74 scoped_ptr<Widget> anchor_widget(new Widget);
75 anchor_widget->Init(params);
76 anchor_widget->Show();
77
78 TestBubbleDelegateView* bubble =
79 new TestBubbleDelegateView(anchor_widget->GetContentsView());
80 BubbleDelegateView::CreateBubble(bubble);
81 BubbleFrameView* frame = bubble->GetBubbleFrameView();
82 const int border = frame->bubble_border()->GetBorderThickness();
83
84 struct {
85 const int point;
86 const int hit;
87 } cases[] = {
88 { border, HTNOWHERE },
89 { border + 5, HTNOWHERE },
90 { border + 6, HTCLIENT },
91 { border + 50, HTCLIENT },
92 { 1000, HTNOWHERE },
93 };
94
95 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
96 gfx::Point point(cases[i].point, cases[i].point);
97 EXPECT_EQ(cases[i].hit, frame->NonClientHitTest(point))
98 << " with border: " << border << ", at point " << cases[i].point;
99 }
100 }
101
102 // Tests that the arrow is mirrored as needed to better fit the screen. 55 // Tests that the arrow is mirrored as needed to better fit the screen.
103 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) { 56 TEST_F(BubbleFrameViewTest, GetUpdatedWindowBounds) {
104 TestBubbleFrameView frame; 57 TestBubbleFrameView frame;
105 gfx::Rect window_bounds; 58 gfx::Rect window_bounds;
106 59
107 gfx::Insets insets = frame.bubble_border()->GetInsets(); 60 gfx::Insets insets = frame.bubble_border()->GetInsets();
108 int xposition = 95 - insets.width(); 61 int xposition = 95 - insets.width();
109 62
110 // Test that the info bubble displays normally when it fits. 63 // Test that the info bubble displays normally when it fits.
111 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT); 64 frame.bubble_border()->set_arrow(BubbleBorder::TOP_LEFT);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 gfx::Rect(900, 900, 50, 50), // |anchor_rect| 342 gfx::Rect(900, 900, 50, 50), // |anchor_rect|
390 gfx::Size(500, 500), // |client_size| 343 gfx::Size(500, 500), // |client_size|
391 true); // |adjust_if_offscreen| 344 true); // |adjust_if_offscreen|
392 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow()); 345 EXPECT_EQ(BubbleBorder::RIGHT_CENTER, frame.bubble_border()->arrow());
393 EXPECT_EQ(window_bounds.bottom(), 1000); 346 EXPECT_EQ(window_bounds.bottom(), 1000);
394 EXPECT_EQ(window_bounds.y() + 347 EXPECT_EQ(window_bounds.y() +
395 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925); 348 frame.bubble_border()->GetArrowOffset(window_bounds.size()), 925);
396 } 349 }
397 350
398 } // namespace views 351 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_delegate_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698