| 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 "cc/scrollbar_animation_controller_linear_fade.h" | |
| 6 | |
| 7 #include "cc/scrollbar_layer_impl.h" | |
| 8 #include "cc/single_thread_proxy.h" | |
| 9 #include "cc/test/fake_impl_proxy.h" | |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 11 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 namespace { | |
| 16 | |
| 17 class ScrollbarAnimationControllerLinearFadeTest : public testing::Test { | |
| 18 public: | |
| 19 ScrollbarAnimationControllerLinearFadeTest() | |
| 20 : m_hostImpl(&m_proxy) | |
| 21 { | |
| 22 } | |
| 23 | |
| 24 protected: | |
| 25 virtual void SetUp() | |
| 26 { | |
| 27 m_scrollLayer = LayerImpl::Create(m_hostImpl.active_tree(), 1); | |
| 28 scoped_ptr<ScrollbarGeometryFixedThumb> geometry(ScrollbarGeometryFixedT
humb::create(FakeWebScrollbarThemeGeometry::create(false))); | |
| 29 m_scrollbarLayer = ScrollbarLayerImpl::Create(m_hostImpl.active_tree(),
2, geometry.Pass()); | |
| 30 | |
| 31 m_scrollLayer->SetMaxScrollOffset(gfx::Vector2d(50, 50)); | |
| 32 m_scrollLayer->SetBounds(gfx::Size(50, 50)); | |
| 33 m_scrollLayer->SetHorizontalScrollbarLayer(m_scrollbarLayer.get()); | |
| 34 | |
| 35 m_scrollbarController = ScrollbarAnimationControllerLinearFade::create(m
_scrollLayer.get(), base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSecond
s(3)); | |
| 36 } | |
| 37 | |
| 38 FakeImplProxy m_proxy; | |
| 39 FakeLayerTreeHostImpl m_hostImpl; | |
| 40 scoped_ptr<ScrollbarAnimationControllerLinearFade> m_scrollbarController; | |
| 41 scoped_ptr<LayerImpl> m_scrollLayer; | |
| 42 scoped_ptr<ScrollbarLayerImpl> m_scrollbarLayer; | |
| 43 | |
| 44 }; | |
| 45 | |
| 46 TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyHiddenInBegin) | |
| 47 { | |
| 48 m_scrollbarController->animate(base::TimeTicks()); | |
| 49 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
| 50 } | |
| 51 | |
| 52 TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByScrollGesture) | |
| 53 { | |
| 54 base::TimeTicks time; | |
| 55 time += base::TimeDelta::FromSeconds(1); | |
| 56 m_scrollbarController->didScrollGestureBegin(); | |
| 57 EXPECT_TRUE(m_scrollbarController->isScrollGestureInProgress()); | |
| 58 EXPECT_FALSE(m_scrollbarController->isAnimating()); | |
| 59 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 60 | |
| 61 time += base::TimeDelta::FromSeconds(100); | |
| 62 m_scrollbarController->animate(time); | |
| 63 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 64 m_scrollbarController->didScrollGestureEnd(time); | |
| 65 | |
| 66 EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress()); | |
| 67 EXPECT_TRUE(m_scrollbarController->isAnimating()); | |
| 68 EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds()); | |
| 69 | |
| 70 time += base::TimeDelta::FromSeconds(1); | |
| 71 m_scrollbarController->animate(time); | |
| 72 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 73 | |
| 74 time += base::TimeDelta::FromSeconds(1); | |
| 75 m_scrollbarController->animate(time); | |
| 76 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 77 | |
| 78 time += base::TimeDelta::FromSeconds(1); | |
| 79 m_scrollbarController->animate(time); | |
| 80 EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 81 | |
| 82 time += base::TimeDelta::FromSeconds(1); | |
| 83 m_scrollbarController->animate(time); | |
| 84 EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 85 | |
| 86 time += base::TimeDelta::FromSeconds(1); | |
| 87 | |
| 88 m_scrollbarController->didScrollGestureBegin(); | |
| 89 m_scrollbarController->didScrollGestureEnd(time); | |
| 90 | |
| 91 time += base::TimeDelta::FromSeconds(1); | |
| 92 m_scrollbarController->animate(time); | |
| 93 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 94 | |
| 95 time += base::TimeDelta::FromSeconds(1); | |
| 96 m_scrollbarController->animate(time); | |
| 97 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 98 | |
| 99 time += base::TimeDelta::FromSeconds(1); | |
| 100 m_scrollbarController->animate(time); | |
| 101 EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 102 | |
| 103 time += base::TimeDelta::FromSeconds(1); | |
| 104 m_scrollbarController->animate(time); | |
| 105 EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 106 | |
| 107 time += base::TimeDelta::FromSeconds(1); | |
| 108 m_scrollbarController->animate(time); | |
| 109 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
| 110 } | |
| 111 | |
| 112 TEST_F(ScrollbarAnimationControllerLinearFadeTest, verifyAwakenByProgrammaticScr
oll) | |
| 113 { | |
| 114 base::TimeTicks time; | |
| 115 time += base::TimeDelta::FromSeconds(1); | |
| 116 m_scrollbarController->didProgrammaticallyUpdateScroll(time); | |
| 117 EXPECT_FALSE(m_scrollbarController->isScrollGestureInProgress()); | |
| 118 EXPECT_TRUE(m_scrollbarController->isAnimating()); | |
| 119 EXPECT_EQ(2, m_scrollbarController->delayBeforeStart(time).InSeconds()); | |
| 120 m_scrollbarController->animate(time); | |
| 121 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 122 | |
| 123 time += base::TimeDelta::FromSeconds(1); | |
| 124 m_scrollbarController->animate(time); | |
| 125 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 126 m_scrollbarController->didProgrammaticallyUpdateScroll(time); | |
| 127 | |
| 128 time += base::TimeDelta::FromSeconds(1); | |
| 129 m_scrollbarController->animate(time); | |
| 130 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 131 | |
| 132 time += base::TimeDelta::FromSeconds(1); | |
| 133 m_scrollbarController->animate(time); | |
| 134 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 135 | |
| 136 time += base::TimeDelta::FromSeconds(1); | |
| 137 m_scrollbarController->animate(time); | |
| 138 EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 139 | |
| 140 time += base::TimeDelta::FromSeconds(1); | |
| 141 m_scrollbarController->animate(time); | |
| 142 EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 143 | |
| 144 time += base::TimeDelta::FromSeconds(1); | |
| 145 m_scrollbarController->didProgrammaticallyUpdateScroll(time); | |
| 146 time += base::TimeDelta::FromSeconds(1); | |
| 147 m_scrollbarController->animate(time); | |
| 148 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 149 | |
| 150 time += base::TimeDelta::FromSeconds(1); | |
| 151 m_scrollbarController->animate(time); | |
| 152 EXPECT_FLOAT_EQ(1, m_scrollbarLayer->opacity()); | |
| 153 | |
| 154 time += base::TimeDelta::FromSeconds(1); | |
| 155 m_scrollbarController->animate(time); | |
| 156 EXPECT_FLOAT_EQ(2.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 157 | |
| 158 time += base::TimeDelta::FromSeconds(1); | |
| 159 m_scrollbarController->animate(time); | |
| 160 EXPECT_FLOAT_EQ(1.0f / 3.0f, m_scrollbarLayer->opacity()); | |
| 161 | |
| 162 time += base::TimeDelta::FromSeconds(1); | |
| 163 m_scrollbarController->animate(time); | |
| 164 EXPECT_FLOAT_EQ(0, m_scrollbarLayer->opacity()); | |
| 165 } | |
| 166 | |
| 167 } // namespace | |
| 168 } // namespace cc | |
| OLD | NEW |