OLD | NEW |
| (Empty) |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include "CCScrollbarAnimationControllerLinearFade.h" | |
8 | |
9 #include "CCScrollbarLayerImpl.h" | |
10 #include "CCSingleThreadProxy.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include <wtf/OwnPtr.h> | |
13 | |
14 using namespace cc; | |
15 | |
16 namespace { | |
17 | |
18 class CCScrollbarAnimationControllerLinearFadeTest : public testing::Test { | |
19 protected: | |
20 virtual void SetUp() | |
21 { | |
22 m_scrollLayer = CCLayerImpl::create(1); | |
23 m_scrollLayer->addChild(CCLayerImpl::create(2)); | |
24 m_contentLayer = m_scrollLayer->children()[0]; | |
25 m_scrollbarLayer = CCScrollbarLayerImpl::create(3); | |
26 | |
27 m_scrollLayer->setMaxScrollPosition(IntSize(50, 50)); | |
28 m_contentLayer->setBounds(IntSize(50, 50)); | |
29 | |
30 m_scrollbarController = CCScrollbarAnimationControllerLinearFade::create
(m_scrollLayer.get(), 2, 3); | |
31 m_scrollbarController->setHorizontalScrollbarLayer(m_scrollbarLayer.get(
)); | |
32 } | |
33 | |
34 DebugScopedSetImplThread implThread; | |
35 | |
36 OwnPtr<CCScrollbarAnimationControllerLinearFade> m_scrollbarController; | |
37 scoped_ptr<CCLayerImpl> m_scrollLayer; | |
38 CCLayerImpl* m_contentLayer; | |
39 scoped_ptr<CCScrollbarLayerImpl> m_scrollbarLayer; | |
40 | |
41 }; | |
42 | |
43 TEST_F(CCScrollbarAnimationControllerLinearFadeTest, verifyHiddenInBegin) | |
44 { | |
45 m_scrollbarController->animate(0); | |
46 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
47 m_scrollbarController->updateScrollOffsetAtTime(m_scrollLayer.get(), 0); | |
48 m_scrollbarController->animate(0); | |
49 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
50 } | |
51 | |
52 TEST_F(CCScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScroll) | |
53 { | |
54 m_scrollLayer->setScrollDelta(IntSize(1, 1)); | |
55 m_scrollbarController->updateScrollOffsetAtTime(m_scrollLayer.get(), 0); | |
56 m_scrollbarController->animate(0); | |
57 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
58 m_scrollbarController->animate(1); | |
59 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
60 m_scrollLayer->setScrollDelta(IntSize(2, 2)); | |
61 m_scrollbarController->updateScrollOffsetAtTime(m_scrollLayer.get(), 1); | |
62 m_scrollbarController->animate(2); | |
63 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
64 m_scrollbarController->animate(3); | |
65 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
66 m_scrollbarController->animate(4); | |
67 // Note that we use 3.0f to avoid "argument is truncated from 'double' to | |
68 // 'float'" warnings on Windows. | |
69 EXPECT_FLOAT_EQ(2 / 3.0f, m_scrollbarLayer->opacity()); | |
70 m_scrollbarController->animate(5); | |
71 EXPECT_FLOAT_EQ(1 / 3.0f, m_scrollbarLayer->opacity()); | |
72 m_scrollLayer->setScrollDelta(IntSize(3, 3)); | |
73 m_scrollbarController->updateScrollOffsetAtTime(m_scrollLayer.get(), 5); | |
74 m_scrollbarController->animate(6); | |
75 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
76 m_scrollbarController->animate(7); | |
77 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
78 m_scrollbarController->animate(8); | |
79 EXPECT_FLOAT_EQ(2 / 3.0f, m_scrollbarLayer->opacity()); | |
80 m_scrollbarController->animate(9); | |
81 EXPECT_FLOAT_EQ(1 / 3.0f, m_scrollbarLayer->opacity()); | |
82 m_scrollbarController->animate(10); | |
83 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
84 } | |
85 | |
86 TEST_F(CCScrollbarAnimationControllerLinearFadeTest, verifyForceAwakenByPinch) | |
87 { | |
88 m_scrollbarController->didPinchGestureBeginAtTime(0); | |
89 m_scrollbarController->didPinchGestureUpdateAtTime(0); | |
90 m_scrollbarController->animate(0); | |
91 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
92 m_scrollbarController->animate(1); | |
93 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
94 m_scrollLayer->setScrollDelta(IntSize(1, 1)); | |
95 m_scrollbarController->updateScrollOffsetAtTime(m_scrollLayer.get(), 1); | |
96 m_scrollbarController->animate(2); | |
97 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
98 m_scrollbarController->animate(3); | |
99 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
100 m_scrollbarController->animate(4); | |
101 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
102 m_scrollbarController->animate(5); | |
103 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
104 m_scrollbarController->animate(6); | |
105 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
106 m_scrollbarController->didPinchGestureEndAtTime(6); | |
107 m_scrollbarController->animate(7); | |
108 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
109 m_scrollbarController->animate(8); | |
110 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
111 m_scrollbarController->animate(9); | |
112 EXPECT_FLOAT_EQ(2 / 3.0f, m_scrollbarLayer->opacity()); | |
113 m_scrollbarController->animate(10); | |
114 EXPECT_FLOAT_EQ(1 / 3.0f, m_scrollbarLayer->opacity()); | |
115 m_scrollbarController->animate(11); | |
116 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
117 | |
118 } | |
119 | |
120 } | |
OLD | NEW |