| 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/message_loop.h" | |
| 6 #include "third_party/skia/include/core/SkColor.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #include "ui/base/animation/slide_animation.h" | |
| 9 #include "views/bubble/bubble_border.h" | |
| 10 #include "views/bubble/bubble_delegate.h" | 5 #include "views/bubble/bubble_delegate.h" |
| 11 #include "views/bubble/bubble_view.h" | |
| 12 #include "views/test/views_test_base.h" | 6 #include "views/test/views_test_base.h" |
| 13 #include "views/widget/widget.h" | 7 #include "views/widget/widget.h" |
| 14 | 8 |
| 15 namespace views { | 9 namespace views { |
| 16 | 10 |
| 17 namespace { | 11 namespace { |
| 18 | 12 |
| 19 typedef ViewsTestBase BubbleViewBasicTest; | 13 typedef ViewsTestBase BubbleViewBasicTest; |
| 20 typedef ViewsTestBase BubbleViewTest; | |
| 21 | |
| 22 class TestBubbleDelegate : public BubbleDelegateView { | |
| 23 public: | |
| 24 explicit TestBubbleDelegate(Widget *frame): BubbleDelegateView(frame) {} | |
| 25 SkColor GetFrameBackgroundColor() { return SK_ColorGREEN; } | |
| 26 gfx::Rect GetBounds() { return gfx::Rect(10, 10, 200, 200); } | |
| 27 BubbleBorder::ArrowLocation GetFrameArrowLocation() { | |
| 28 return BubbleBorder::LEFT_BOTTOM; | |
| 29 } | |
| 30 View* GetContentsView() { return &view_; } | |
| 31 | |
| 32 View view_; | |
| 33 }; | |
| 34 | |
| 35 class TestAnimationDelegate : public ui::AnimationDelegate { | |
| 36 public: | |
| 37 TestAnimationDelegate():animation_progressed_(0), animation_ended_(0) {} | |
| 38 void AnimationProgressed(const ui::Animation* animation) { | |
| 39 ++animation_progressed_; | |
| 40 } | |
| 41 void AnimationEnded(const ui::Animation* animation) { | |
| 42 ++animation_ended_; | |
| 43 } | |
| 44 int animation_progressed_; | |
| 45 int animation_ended_; | |
| 46 }; | |
| 47 | |
| 48 | 14 |
| 49 TEST_F(BubbleViewBasicTest, CreateArrowBubble) { | 15 TEST_F(BubbleViewBasicTest, CreateArrowBubble) { |
| 50 scoped_ptr<Widget> bubble_widget(new Widget()); | 16 BubbleDelegateView* bubble_delegate = new BubbleDelegateView(); |
| 51 Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE); | 17 scoped_ptr<Widget> bubble_widget( |
| 52 TestBubbleDelegate delegate(bubble_widget.get()); | 18 views::BubbleDelegateView::CreateBubble(bubble_delegate, NULL)); |
| 53 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 54 params.delegate = &delegate; | |
| 55 bubble_widget->Init(params); | |
| 56 | 19 |
| 57 BubbleBorder* border = | 20 BubbleBorder* border = static_cast<BubbleBorder*>( |
| 58 static_cast<BubbleBorder*>(bubble_widget->non_client_view() | 21 bubble_widget->non_client_view()->frame_view()->border()); |
| 59 ->frame_view()->border()); | 22 EXPECT_EQ(bubble_delegate->GetArrowLocation(), border->arrow_location()); |
| 60 EXPECT_EQ(delegate.GetFrameArrowLocation(), border->arrow_location()); | |
| 61 bubble_widget->CloseNow(); | 23 bubble_widget->CloseNow(); |
| 62 bubble_widget.reset(NULL); | 24 bubble_widget.reset(); |
| 63 RunPendingMessages(); | 25 RunPendingMessages(); |
| 64 } | 26 } |
| 65 | 27 |
| 66 } // namespace | 28 } // namespace |
| 67 | 29 |
| 68 TEST_F(BubbleViewTest, FadeAnimation) { | |
| 69 scoped_ptr<Widget> bubble_widget(new Widget()); | |
| 70 Widget::InitParams params(Widget::InitParams::TYPE_BUBBLE); | |
| 71 TestBubbleDelegate delegate(bubble_widget.get()); | |
| 72 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 73 params.delegate = &delegate; | |
| 74 bubble_widget->Init(params); | |
| 75 bubble_widget->Show(); | |
| 76 BubbleView* bubble_view = bubble_widget->client_view()->AsBubbleView(); | |
| 77 TestAnimationDelegate test_animation_delegate; | |
| 78 bubble_view->set_animation_delegate(&test_animation_delegate); | |
| 79 bubble_view->StartFade(); | |
| 80 | |
| 81 bubble_view->AnimationProgressed(bubble_view->fade_animation_.get()); | |
| 82 bubble_view->AnimationEnded(bubble_view->fade_animation_.get()); | |
| 83 | |
| 84 EXPECT_LT(0, test_animation_delegate.animation_progressed_); | |
| 85 EXPECT_EQ(1, test_animation_delegate.animation_ended_); | |
| 86 bubble_widget->CloseNow(); | |
| 87 bubble_widget.reset(NULL); | |
| 88 RunPendingMessages(); | |
| 89 } | |
| 90 | |
| 91 } // namespace views | 30 } // namespace views |
| OLD | NEW |