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