| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 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 | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 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 | 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 | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef CompositorAnimationsTestHelper_h | 25 #ifndef CompositorAnimationsTestHelper_h |
| 26 #define CompositorAnimationsTestHelper_h | 26 #define CompositorAnimationsTestHelper_h |
| 27 | 27 |
| 28 #include "core/animation/CompositorAnimations.h" | 28 #include "core/animation/CompositorAnimations.h" |
| 29 #include "platform/animation/CompositorAnimationPlayer.h" |
| 30 #include "platform/animation/CompositorAnimationTimeline.h" |
| 31 #include "platform/animation/CompositorFloatAnimationCurve.h" |
| 32 #include "platform/animation/CompositorFloatKeyframe.h" |
| 33 #include "platform/graphics/CompositorFactory.h" |
| 29 #include "platform/testing/TestingPlatformSupport.h" | 34 #include "platform/testing/TestingPlatformSupport.h" |
| 30 #include "public/platform/WebCompositorAnimationPlayer.h" | |
| 31 #include "public/platform/WebCompositorAnimationTimeline.h" | |
| 32 #include "public/platform/WebCompositorSupport.h" | 35 #include "public/platform/WebCompositorSupport.h" |
| 33 #include "public/platform/WebFloatAnimationCurve.h" | |
| 34 #include "public/platform/WebFloatKeyframe.h" | |
| 35 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
| 36 | 37 |
| 37 #include <gmock/gmock.h> | 38 #include <gmock/gmock.h> |
| 38 #include <gtest/gtest.h> | 39 #include <gtest/gtest.h> |
| 39 | 40 |
| 40 // Test helpers and mocks for Web* types | 41 // Test helpers and mocks for Web* types |
| 41 // ----------------------------------------------------------------------- | 42 // ----------------------------------------------------------------------- |
| 42 namespace blink { | 43 namespace blink { |
| 43 | 44 |
| 44 // WebFloatKeyframe is a plain struct, so we just create an == operator | 45 // CompositorFloatKeyframe is a plain struct, so we just create an == operator |
| 45 // for it. | 46 // for it. |
| 46 inline bool operator==(const WebFloatKeyframe& a, const WebFloatKeyframe& b) | 47 inline bool operator==(const CompositorFloatKeyframe& a, const CompositorFloatKe
yframe& b) |
| 47 { | 48 { |
| 48 return a.time == b.time && a.value == b.value; | 49 return a.time == b.time && a.value == b.value; |
| 49 } | 50 } |
| 50 | 51 |
| 51 inline void PrintTo(const WebFloatKeyframe& frame, ::std::ostream* os) | 52 inline void PrintTo(const CompositorFloatKeyframe& frame, ::std::ostream* os) |
| 52 { | 53 { |
| 53 *os << "WebFloatKeyframe@" << &frame << "(" << frame.time << ", " << frame.v
alue << ")"; | 54 *os << "CompositorFloatKeyframe@" << &frame << "(" << frame.time << ", " <<
frame.value << ")"; |
| 54 } | 55 } |
| 55 | 56 |
| 56 // ----------------------------------------------------------------------- | 57 // ----------------------------------------------------------------------- |
| 57 | 58 |
| 58 class WebCompositorAnimationMock : public WebCompositorAnimation { | 59 class WebCompositorAnimationMock : public CompositorAnimation { |
| 59 private: | 60 private: |
| 60 WebCompositorAnimation::TargetProperty m_property; | 61 CompositorAnimation::TargetProperty m_property; |
| 61 | 62 |
| 62 public: | 63 public: |
| 63 // Target Property is set through the constructor. | 64 // Target Property is set through the constructor. |
| 64 WebCompositorAnimationMock(WebCompositorAnimation::TargetProperty p) : m_pro
perty(p) { } | 65 WebCompositorAnimationMock(CompositorAnimation::TargetProperty p) : m_proper
ty(p) { } |
| 65 virtual WebCompositorAnimation::TargetProperty targetProperty() const { retu
rn m_property; } | 66 virtual CompositorAnimation::TargetProperty targetProperty() const { return
m_property; } |
| 66 | 67 |
| 67 MOCK_METHOD0(id, int()); | 68 MOCK_METHOD0(id, int()); |
| 68 MOCK_METHOD0(group, int()); | 69 MOCK_METHOD0(group, int()); |
| 69 | 70 |
| 70 MOCK_CONST_METHOD0(iterations, double()); | 71 MOCK_CONST_METHOD0(iterations, double()); |
| 71 MOCK_METHOD1(setIterations, void(double)); | 72 MOCK_METHOD1(setIterations, void(double)); |
| 72 | 73 |
| 73 MOCK_CONST_METHOD0(iterationStart, double()); | 74 MOCK_CONST_METHOD0(iterationStart, double()); |
| 74 MOCK_METHOD1(setIterationStart, void(double)); | 75 MOCK_METHOD1(setIterationStart, void(double)); |
| 75 | 76 |
| 76 MOCK_CONST_METHOD0(startTime, double()); | 77 MOCK_CONST_METHOD0(startTime, double()); |
| 77 MOCK_METHOD1(setStartTime, void(double)); | 78 MOCK_METHOD1(setStartTime, void(double)); |
| 78 | 79 |
| 79 MOCK_CONST_METHOD0(timeOffset, double()); | 80 MOCK_CONST_METHOD0(timeOffset, double()); |
| 80 MOCK_METHOD1(setTimeOffset, void(double)); | 81 MOCK_METHOD1(setTimeOffset, void(double)); |
| 81 | 82 |
| 82 MOCK_CONST_METHOD0(direction, Direction()); | 83 MOCK_CONST_METHOD0(direction, Direction()); |
| 83 MOCK_METHOD1(setDirection, void(Direction)); | 84 MOCK_METHOD1(setDirection, void(Direction)); |
| 84 | 85 |
| 85 MOCK_CONST_METHOD0(playbackRate, double()); | 86 MOCK_CONST_METHOD0(playbackRate, double()); |
| 86 MOCK_METHOD1(setPlaybackRate, void(double)); | 87 MOCK_METHOD1(setPlaybackRate, void(double)); |
| 87 | 88 |
| 88 MOCK_CONST_METHOD0(fillMode, FillMode()); | 89 MOCK_CONST_METHOD0(fillMode, FillMode()); |
| 89 MOCK_METHOD1(setFillMode, void(FillMode)); | 90 MOCK_METHOD1(setFillMode, void(FillMode)); |
| 90 | 91 |
| 91 MOCK_METHOD0(delete_, void()); | 92 MOCK_METHOD0(delete_, void()); |
| 92 ~WebCompositorAnimationMock() { delete_(); } | 93 ~WebCompositorAnimationMock() { delete_(); } |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 template<typename CurveType, WebCompositorAnimationCurve::AnimationCurveType Cur
veId, typename KeyframeType> | 96 template<typename CurveType, CompositorAnimationCurve::AnimationCurveType CurveI
d, typename KeyframeType> |
| 96 class WebCompositorAnimationCurveMock : public CurveType { | 97 class WebCompositorAnimationCurveMock : public CurveType { |
| 97 public: | 98 public: |
| 98 MOCK_METHOD1_T(add, void(const KeyframeType&)); | 99 MOCK_METHOD1_T(add, void(const KeyframeType&)); |
| 99 MOCK_METHOD2_T(add, void(const KeyframeType&, WebCompositorAnimationCurve::T
imingFunctionType)); | 100 MOCK_METHOD2_T(add, void(const KeyframeType&, CompositorAnimationCurve::Timi
ngFunctionType)); |
| 100 MOCK_METHOD5_T(add, void(const KeyframeType&, double, double, double, double
)); | 101 MOCK_METHOD5_T(add, void(const KeyframeType&, double, double, double, double
)); |
| 101 MOCK_METHOD3_T(add, void(const KeyframeType&, int steps, float stepsStartOff
set)); | 102 MOCK_METHOD3_T(add, void(const KeyframeType&, int steps, float stepsStartOff
set)); |
| 102 | 103 |
| 103 MOCK_METHOD0(setLinearTimingFunction, void()); | 104 MOCK_METHOD0(setLinearTimingFunction, void()); |
| 104 MOCK_METHOD4(setCubicBezierTimingFunction, void(double, double, double, doub
le)); | 105 MOCK_METHOD4(setCubicBezierTimingFunction, void(double, double, double, doub
le)); |
| 105 MOCK_METHOD1(setCubicBezierTimingFunction, void(WebCompositorAnimationCurve:
:TimingFunctionType)); | 106 MOCK_METHOD1(setCubicBezierTimingFunction, void(CompositorAnimationCurve::Ti
mingFunctionType)); |
| 106 MOCK_METHOD2(setStepsTimingFunction, void(int, float)); | 107 MOCK_METHOD2(setStepsTimingFunction, void(int, float)); |
| 107 | 108 |
| 108 MOCK_CONST_METHOD1_T(getValue, float(double)); // Only on WebFloatAnimationC
urve, but can't hurt to have here. | 109 MOCK_CONST_METHOD1_T(getValue, float(double)); // Only on CompositorFloatAni
mationCurve, but can't hurt to have here. |
| 109 | 110 |
| 110 virtual WebCompositorAnimationCurve::AnimationCurveType type() const { retur
n CurveId; } | 111 virtual CompositorAnimationCurve::AnimationCurveType type() const { return C
urveId; } |
| 111 | 112 |
| 112 MOCK_METHOD0(delete_, void()); | 113 MOCK_METHOD0(delete_, void()); |
| 113 ~WebCompositorAnimationCurveMock() { delete_(); } | 114 ~WebCompositorAnimationCurveMock() override { delete_(); } |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 using WebFloatAnimationCurveMock = WebCompositorAnimationCurveMock<WebFloatAnima
tionCurve, WebCompositorAnimationCurve::AnimationCurveTypeFloat, WebFloatKeyfram
e>; | 117 using WebFloatAnimationCurveMock = WebCompositorAnimationCurveMock<CompositorFlo
atAnimationCurve, CompositorAnimationCurve::AnimationCurveTypeFloat, CompositorF
loatKeyframe>; |
| 117 | 118 |
| 118 class WebCompositorAnimationTimelineMock : public WebCompositorAnimationTimeline
{ | 119 class WebCompositorAnimationTimelineMock : public CompositorAnimationTimeline { |
| 119 public: | 120 public: |
| 120 MOCK_METHOD1(playerAttached, void(const WebCompositorAnimationPlayerClient&)
); | 121 MOCK_METHOD1(playerAttached, void(const CompositorAnimationPlayerClient&)); |
| 121 MOCK_METHOD1(playerDestroyed, void(const WebCompositorAnimationPlayerClient&
)); | 122 MOCK_METHOD1(playerDestroyed, void(const CompositorAnimationPlayerClient&)); |
| 122 }; | |
| 123 | |
| 124 class WebCompositorAnimationPlayerMock : public WebCompositorAnimationPlayer { | |
| 125 public: | |
| 126 MOCK_METHOD1(setAnimationDelegate, void(WebCompositorAnimationDelegate*)); | |
| 127 | |
| 128 MOCK_METHOD1(attachLayer, void(WebLayer*)); | |
| 129 MOCK_METHOD0(detachLayer, void()); | |
| 130 MOCK_CONST_METHOD0(isLayerAttached, bool()); | |
| 131 | |
| 132 MOCK_METHOD1(addAnimation, void(WebCompositorAnimation*)); | |
| 133 MOCK_METHOD1(removeAnimation, void(int)); | |
| 134 MOCK_METHOD2(pauseAnimation, void(int, double)); | |
| 135 }; | 123 }; |
| 136 | 124 |
| 137 } // namespace blink | 125 } // namespace blink |
| 138 | 126 |
| 139 namespace blink { | 127 namespace blink { |
| 140 | 128 |
| 141 class AnimationCompositorAnimationsTestBase : public ::testing::Test { | 129 class AnimationCompositorAnimationsTestBase : public ::testing::Test { |
| 142 public: | 130 public: |
| 143 AnimationCompositorAnimationsTestBase() : m_proxyPlatform(&m_mockCompositor)
{ } | 131 class CompositorFactoryMock : public CompositorFactory { |
| 144 | |
| 145 class WebCompositorSupportMock : public WebCompositorSupport { | |
| 146 public: | 132 public: |
| 147 MOCK_METHOD4(createAnimation, WebCompositorAnimation*(const WebComposito
rAnimationCurve& curve, WebCompositorAnimation::TargetProperty target, int group
Id, int animationId)); | 133 MOCK_METHOD4(createAnimation, CompositorAnimation*(const CompositorAnima
tionCurve& curve, CompositorAnimation::TargetProperty target, int groupId, int a
nimationId)); |
| 148 MOCK_METHOD0(createFloatAnimationCurve, WebFloatAnimationCurve*()); | 134 MOCK_METHOD0(createFloatAnimationCurve, CompositorFloatAnimationCurve*()
); |
| 149 | 135 MOCK_METHOD0(createAnimationPlayer, CompositorAnimationPlayer*()); |
| 150 MOCK_METHOD0(createAnimationPlayer, WebCompositorAnimationPlayer*()); | 136 MOCK_METHOD0(createAnimationTimeline, CompositorAnimationTimeline*()); |
| 151 MOCK_METHOD0(createAnimationTimeline, WebCompositorAnimationTimeline*())
; | |
| 152 }; | 137 }; |
| 153 | 138 |
| 154 private: | 139 private: |
| 155 class PlatformProxy : public TestingPlatformSupport { | 140 TestingPlatformSupport m_proxyPlatform; |
| 156 public: | |
| 157 explicit PlatformProxy(WebCompositorSupportMock** compositor) : m_compos
itor(compositor) { } | |
| 158 private: | |
| 159 WebCompositorSupport* compositorSupport() override { return *m_composito
r; } | |
| 160 | |
| 161 WebCompositorSupportMock** m_compositor; | |
| 162 }; | |
| 163 | |
| 164 WebCompositorSupportMock* m_mockCompositor; | |
| 165 PlatformProxy m_proxyPlatform; | |
| 166 | 141 |
| 167 protected: | 142 protected: |
| 168 virtual void SetUp() | 143 void SetUp() override |
| 169 { | 144 { |
| 170 m_mockCompositor = 0; | |
| 171 Platform::initialize(&m_proxyPlatform); | 145 Platform::initialize(&m_proxyPlatform); |
| 172 } | 146 } |
| 173 | |
| 174 void setCompositorForTesting(WebCompositorSupportMock& mock) | |
| 175 { | |
| 176 ASSERT(!m_mockCompositor); | |
| 177 m_mockCompositor = &mock; | |
| 178 } | |
| 179 }; | 147 }; |
| 180 | 148 |
| 181 } // namespace blink | 149 } // namespace blink |
| 182 | 150 |
| 183 #endif | 151 #endif |
| OLD | NEW |