| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 */ | |
| 24 | |
| 25 #ifndef SKY_ENGINE_CORE_ANIMATION_COMPOSITORANIMATIONSTESTHELPER_H_ | |
| 26 #define SKY_ENGINE_CORE_ANIMATION_COMPOSITORANIMATIONSTESTHELPER_H_ | |
| 27 | |
| 28 #include "sky/engine/core/animation/CompositorAnimations.h" | |
| 29 #include "sky/engine/public/platform/Platform.h" | |
| 30 #include "sky/engine/public/platform/WebCompositorSupport.h" | |
| 31 #include "sky/engine/public/platform/WebFloatAnimationCurve.h" | |
| 32 #include "sky/engine/public/platform/WebFloatKeyframe.h" | |
| 33 #include "sky/engine/wtf/PassOwnPtr.h" | |
| 34 | |
| 35 #include <gmock/gmock.h> | |
| 36 #include <gtest/gtest.h> | |
| 37 | |
| 38 | |
| 39 namespace testing { | |
| 40 | |
| 41 template<typename T> | |
| 42 PassOwnPtr<T> CloneToPassOwnPtr(T& o) | |
| 43 { | |
| 44 return adoptPtr(new T(o)); | |
| 45 } | |
| 46 | |
| 47 } // namespace testing | |
| 48 | |
| 49 | |
| 50 // Test helpers and mocks for Web* types | |
| 51 // ----------------------------------------------------------------------- | |
| 52 namespace blink { | |
| 53 | |
| 54 // WebFloatKeyframe is a plain struct, so we just create an == operator | |
| 55 // for it. | |
| 56 inline bool operator==(const WebFloatKeyframe& a, const WebFloatKeyframe& b) | |
| 57 { | |
| 58 return a.time == b.time && a.value == b.value; | |
| 59 } | |
| 60 | |
| 61 inline void PrintTo(const WebFloatKeyframe& frame, ::std::ostream* os) | |
| 62 { | |
| 63 *os << "WebFloatKeyframe@" << &frame << "(" << frame.time << ", " << frame.v
alue << ")"; | |
| 64 } | |
| 65 | |
| 66 // ----------------------------------------------------------------------- | |
| 67 | |
| 68 class WebCompositorAnimationMock : public WebCompositorAnimation { | |
| 69 private: | |
| 70 WebCompositorAnimation::TargetProperty m_property; | |
| 71 | |
| 72 public: | |
| 73 // Target Property is set through the constructor. | |
| 74 WebCompositorAnimationMock(WebCompositorAnimation::TargetProperty p) : m_pro
perty(p) { } | |
| 75 virtual WebCompositorAnimation::TargetProperty targetProperty() const { retu
rn m_property; }; | |
| 76 | |
| 77 MOCK_METHOD0(id, int()); | |
| 78 | |
| 79 MOCK_CONST_METHOD0(iterations, double()); | |
| 80 MOCK_METHOD1(setIterations, void(double)); | |
| 81 | |
| 82 MOCK_CONST_METHOD0(startTime, double()); | |
| 83 MOCK_METHOD1(setStartTime, void(double)); | |
| 84 | |
| 85 MOCK_CONST_METHOD0(timeOffset, double()); | |
| 86 MOCK_METHOD1(setTimeOffset, void(double)); | |
| 87 | |
| 88 MOCK_CONST_METHOD0(alternatesDirection, bool()); | |
| 89 MOCK_METHOD1(setAlternatesDirection, void(bool)); | |
| 90 | |
| 91 MOCK_METHOD0(delete_, void()); | |
| 92 ~WebCompositorAnimationMock() { delete_(); } | |
| 93 }; | |
| 94 | |
| 95 template<typename CurveType, WebCompositorAnimationCurve::AnimationCurveType Cur
veId, typename KeyframeType> | |
| 96 class WebCompositorAnimationCurveMock : public CurveType { | |
| 97 public: | |
| 98 MOCK_METHOD1_T(add, void(const KeyframeType&)); | |
| 99 MOCK_METHOD2_T(add, void(const KeyframeType&, WebCompositorAnimationCurve::T
imingFunctionType)); | |
| 100 MOCK_METHOD5_T(add, void(const KeyframeType&, double, double, double, double
)); | |
| 101 | |
| 102 MOCK_CONST_METHOD1_T(getValue, float(double)); // Only on WebFloatAnimationC
urve, but can't hurt to have here. | |
| 103 | |
| 104 virtual WebCompositorAnimationCurve::AnimationCurveType type() const { retur
n CurveId; }; | |
| 105 | |
| 106 MOCK_METHOD0(delete_, void()); | |
| 107 ~WebCompositorAnimationCurveMock() { delete_(); } | |
| 108 }; | |
| 109 | |
| 110 typedef WebCompositorAnimationCurveMock<WebFloatAnimationCurve, WebCompositorAni
mationCurve::AnimationCurveTypeFloat, WebFloatKeyframe> WebFloatAnimationCurveMo
ck; | |
| 111 | |
| 112 } // namespace blink | |
| 113 | |
| 114 namespace blink { | |
| 115 | |
| 116 class AnimationCompositorAnimationsTestBase : public ::testing::Test { | |
| 117 public: | |
| 118 AnimationCompositorAnimationsTestBase() : m_proxyPlatform(&m_mockCompositor)
{ }; | |
| 119 | |
| 120 class WebCompositorSupportMock : public WebCompositorSupport { | |
| 121 public: | |
| 122 MOCK_METHOD3(createAnimation, WebCompositorAnimation*(const WebComposito
rAnimationCurve& curve, WebCompositorAnimation::TargetProperty target, int anima
tionId)); | |
| 123 MOCK_METHOD0(createFloatAnimationCurve, WebFloatAnimationCurve*()); | |
| 124 }; | |
| 125 | |
| 126 private: | |
| 127 class PlatformProxy : public Platform { | |
| 128 public: | |
| 129 PlatformProxy(WebCompositorSupportMock** compositor) : m_compositor(comp
ositor) { } | |
| 130 private: | |
| 131 WebCompositorSupportMock** m_compositor; | |
| 132 virtual WebCompositorSupport* compositorSupport() override { return *m_c
ompositor; } | |
| 133 }; | |
| 134 | |
| 135 WebCompositorSupportMock* m_mockCompositor; | |
| 136 PlatformProxy m_proxyPlatform; | |
| 137 | |
| 138 protected: | |
| 139 Platform* m_platform; | |
| 140 | |
| 141 virtual void SetUp() | |
| 142 { | |
| 143 m_mockCompositor = 0; | |
| 144 m_platform = Platform::current(); | |
| 145 Platform::initialize(&m_proxyPlatform); | |
| 146 } | |
| 147 | |
| 148 virtual void TearDown() | |
| 149 { | |
| 150 Platform::initialize(m_platform); | |
| 151 } | |
| 152 | |
| 153 void setCompositorForTesting(WebCompositorSupportMock& mock) | |
| 154 { | |
| 155 ASSERT(!m_mockCompositor); | |
| 156 m_mockCompositor = &mock; | |
| 157 } | |
| 158 }; | |
| 159 | |
| 160 } | |
| 161 | |
| 162 #endif // SKY_ENGINE_CORE_ANIMATION_COMPOSITORANIMATIONSTESTHELPER_H_ | |
| OLD | NEW |