| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" | |
| 6 #include "base/message_loop.h" | |
| 7 #include "third_party/skia/include/core/SkColor.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "views/bubble/bubble_border.h" | |
| 10 #include "views/bubble/bubble_frame_view.h" | 5 #include "views/bubble/bubble_frame_view.h" |
| 11 #include "views/bubble/bubble_delegate.h" | 6 #include "views/bubble/bubble_delegate.h" |
| 12 #include "views/test/views_test_base.h" | 7 #include "views/test/views_test_base.h" |
| 13 #include "views/widget/widget.h" | 8 #include "views/widget/widget.h" |
| 14 #if !defined(OS_WIN) | 9 #if !defined(OS_WIN) |
| 15 #include "views/window/hit_test.h" | 10 #include "views/window/hit_test.h" |
| 16 #endif | 11 #endif |
| 17 | 12 |
| 18 namespace views { | 13 namespace views { |
| 19 | 14 |
| 20 namespace { | 15 namespace { |
| 21 | 16 |
| 22 typedef ViewsTestBase BubbleFrameViewBasicTest; | 17 typedef ViewsTestBase BubbleFrameViewBasicTest; |
| 23 | 18 |
| 24 gfx::Rect kBound = gfx::Rect(10, 10, 200, 200); | 19 const BubbleBorder::ArrowLocation kArrow = BubbleBorder::LEFT_BOTTOM; |
| 25 SkColor kBackgroundColor = SK_ColorRED; | 20 const gfx::Rect kRect(10, 10, 200, 200); |
| 26 BubbleBorder::ArrowLocation kArrow = BubbleBorder::LEFT_BOTTOM; | 21 const SkColor kBackgroundColor = SK_ColorRED; |
| 27 | 22 |
| 28 TEST_F(BubbleFrameViewBasicTest, GetBoundsForClientView) { | 23 TEST_F(BubbleFrameViewBasicTest, GetBoundsForClientView) { |
| 29 scoped_ptr<Widget> widget(new views::Widget()); | 24 BubbleFrameView frame(kArrow, kRect.size(), kBackgroundColor); |
| 30 views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE); | 25 EXPECT_EQ(frame.GetWindowBoundsForClientBounds(kRect).size(), frame.size()); |
| 31 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 26 BubbleBorder* bubble_border = static_cast<BubbleBorder*>(frame.border()); |
| 32 widget->Init(params); | 27 EXPECT_EQ(kArrow, bubble_border->arrow_location()); |
| 33 BubbleFrameView frame(widget.get(), kBound, kBackgroundColor, kArrow); | 28 EXPECT_EQ(kBackgroundColor, bubble_border->background_color()); |
| 34 EXPECT_EQ(kBound, frame.bounds()); | |
| 35 EXPECT_EQ(kArrow, | |
| 36 static_cast<BubbleBorder*>(frame.border())->arrow_location()); | |
| 37 EXPECT_EQ(kBackgroundColor, | |
| 38 static_cast<BubbleBorder*>(frame.border())->background_color()); | |
| 39 | 29 |
| 40 gfx::Insets expected_insets; | 30 gfx::Insets expected_insets(frame.GetInsets()); |
| 41 frame.border()->GetInsets(&expected_insets); | |
| 42 EXPECT_EQ(expected_insets.left(), frame.GetBoundsForClientView().x()); | 31 EXPECT_EQ(expected_insets.left(), frame.GetBoundsForClientView().x()); |
| 43 EXPECT_EQ(expected_insets.top(), frame.GetBoundsForClientView().y()); | 32 EXPECT_EQ(expected_insets.top(), frame.GetBoundsForClientView().y()); |
| 44 widget->CloseNow(); | |
| 45 widget.reset(NULL); | |
| 46 RunPendingMessages(); | |
| 47 } | 33 } |
| 48 | 34 |
| 49 class TestBubbleDelegate : public BubbleDelegateView { | |
| 50 public: | |
| 51 explicit TestBubbleDelegate(Widget *frame): BubbleDelegateView(frame) {} | |
| 52 SkColor GetFrameBackgroundColor() { return kBackgroundColor; } | |
| 53 gfx::Rect GetBounds() { return gfx::Rect(10, 10, 200, 200); } | |
| 54 BubbleBorder::ArrowLocation GetFrameArrowLocation() { return kArrow; } | |
| 55 View* GetContentsView() { return &view_; } | |
| 56 | |
| 57 View view_; | |
| 58 }; | |
| 59 | |
| 60 TEST_F(BubbleFrameViewBasicTest, NonClientHitTest) { | 35 TEST_F(BubbleFrameViewBasicTest, NonClientHitTest) { |
| 61 scoped_ptr<Widget> widget(new Widget()); | 36 BubbleDelegateView* delegate = new BubbleDelegateView(); |
| 62 views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE); | 37 scoped_ptr<Widget> widget( |
| 63 TestBubbleDelegate delegate(widget.get()); | 38 views::BubbleDelegateView::CreateBubble(delegate, NULL)); |
| 64 params.delegate = &delegate; | 39 widget->SetBounds(kRect); |
| 65 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 40 widget->Show(); |
| 66 widget->Init(params); | |
| 67 gfx::Point kPtInBound(100, 100); | 41 gfx::Point kPtInBound(100, 100); |
| 68 gfx::Point kPtOutsideBound(1000, 1000); | 42 gfx::Point kPtOutsideBound(1000, 1000); |
| 69 EXPECT_EQ(HTCLIENT, widget->non_client_view()->NonClientHitTest(kPtInBound)); | 43 EXPECT_EQ(HTCLIENT, widget->non_client_view()->NonClientHitTest(kPtInBound)); |
| 70 EXPECT_EQ(HTNOWHERE, | 44 EXPECT_EQ(HTNOWHERE, |
| 71 widget->non_client_view()->NonClientHitTest(kPtOutsideBound)); | 45 widget->non_client_view()->NonClientHitTest(kPtOutsideBound)); |
| 72 widget->CloseNow(); | 46 widget->CloseNow(); |
| 73 widget.reset(NULL); | 47 widget.reset(); |
| 74 RunPendingMessages(); | 48 RunPendingMessages(); |
| 75 } | 49 } |
| 76 | 50 |
| 77 } // namespace | 51 } // namespace |
| 52 |
| 78 } // namespace views | 53 } // namespace views |
| OLD | NEW |