summaryrefslogtreecommitdiffstats
path: root/cc/scrollbar_animation_controller_linear_fade_unittest.cc
blob: 28b26c20f01f7221982ea9a4df18fd9c267fea16 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2012 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 "cc/scrollbar_animation_controller_linear_fade.h"

#include "cc/scrollbar_layer_impl.h"
#include "cc/single_thread_proxy.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_web_scrollbar_theme_geometry.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

class ScrollbarAnimationControllerLinearFadeTest : public testing::Test {
public:
    ScrollbarAnimationControllerLinearFadeTest()
        : m_hostImpl(&m_proxy)
    {
    }

protected:
    virtual void SetUp()
    {
        m_scrollLayer = LayerImpl::create(m_hostImpl.activeTree(), 1);
        scoped_ptr<ScrollbarGeometryFixedThumb> geometry(ScrollbarGeometryFixedThumb::create(FakeWebScrollbarThemeGeometry::create(false)));
        m_scrollbarLayer = ScrollbarLayerImpl::create(m_hostImpl.activeTree(), 2, geometry.Pass());

        m_scrollLayer->setMaxScrollOffset(gfx::Vector2d(50, 50));
        m_scrollLayer->setBounds(gfx::Size(50, 50));
        m_scrollLayer->setHorizontalScrollbarLayer(m_scrollbarLayer.get());

        m_scrollbarController = ScrollbarAnimationControllerLinearFade::create(m_scrollLayer.get(), 2, 3);
    }

    FakeImplProxy m_proxy;
    FakeLayerTreeHostImpl m_hostImpl;
    scoped_ptr<ScrollbarAnimationControllerLinearFade> m_scrollbarController;
    scoped_ptr<LayerImpl> m_scrollLayer;
    scoped_ptr<ScrollbarLayerImpl> m_scrollbarLayer;

};

TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyHiddenInBegin)
{
    m_scrollbarController->animate(base::TimeTicks());
    EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());
}

TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScroll)
{
    base::TimeTicks time;
    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->didUpdateScrollOffset(time);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());
    m_scrollbarController->didUpdateScrollOffset(time);

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->didUpdateScrollOffset(time);
    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());
}

TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyForceAwakenByPinch)
{
    base::TimeTicks time;
    m_scrollbarController->didPinchGestureUpdate(time);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    m_scrollbarController->didUpdateScrollOffset(time);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->didPinchGestureEnd(time);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(2);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(2 / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(1 / 3.0f, m_scrollbarLayer->opacity());

    time += base::TimeDelta::FromSeconds(1);
    m_scrollbarController->animate(time);
    EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity());

}

}  // namespace
}  // namespace cc