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