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

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

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

Powered by Google App Engine
This is Rietveld 408576698