2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
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 ANY
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 ON
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.
25 #ifndef CompositorAnimationsTestHelper_h
26 #define CompositorAnimationsTestHelper_h
28 #include "core/animation/CompositorAnimations.h"
29 #include "public/platform/Platform.h"
30 #include "public/platform/WebCompositorSupport.h"
31 #include "public/platform/WebFloatAnimationCurve.h"
32 #include "public/platform/WebFloatKeyframe.h"
33 #include "wtf/PassOwnPtr.h"
35 #include <gmock/gmock.h>
36 #include <gtest/gtest.h>
42 PassOwnPtr<T> CloneToPassOwnPtr(T& o)
44 return adoptPtr(new T(o));
47 } // namespace testing
50 // Test helpers and mocks for Web* types
51 // -----------------------------------------------------------------------
54 // WebFloatKeyframe is a plain struct, so we just create an == operator
56 inline bool operator==(const WebFloatKeyframe& a, const WebFloatKeyframe& b)
58 return a.time == b.time && a.value == b.value;
61 inline void PrintTo(const WebFloatKeyframe& frame, ::std::ostream* os)
63 *os << "WebFloatKeyframe@" << &frame << "(" << frame.time << ", " << frame.value << ")";
66 // -----------------------------------------------------------------------
68 class WebCompositorAnimationMock : public WebCompositorAnimation {
70 WebCompositorAnimation::TargetProperty m_property;
73 // Target Property is set through the constructor.
74 WebCompositorAnimationMock(WebCompositorAnimation::TargetProperty p) : m_property(p) { }
75 virtual WebCompositorAnimation::TargetProperty targetProperty() const { return m_property; };
77 MOCK_METHOD0(id, int());
79 MOCK_CONST_METHOD0(iterations, double());
80 MOCK_METHOD1(setIterations, void(double));
82 MOCK_CONST_METHOD0(iterationStart, double());
83 MOCK_METHOD1(setIterationStart, void(double));
85 MOCK_CONST_METHOD0(startTime, double());
86 MOCK_METHOD1(setStartTime, void(double));
88 MOCK_CONST_METHOD0(timeOffset, double());
89 MOCK_METHOD1(setTimeOffset, void(double));
91 MOCK_CONST_METHOD0(direction, Direction());
92 MOCK_METHOD1(setDirection, void(Direction));
94 MOCK_CONST_METHOD0(playbackRate, double());
95 MOCK_METHOD1(setPlaybackRate, void(double));
97 MOCK_CONST_METHOD0(fillMode, FillMode());
98 MOCK_METHOD1(setFillMode, void(FillMode));
100 MOCK_METHOD0(delete_, void());
101 ~WebCompositorAnimationMock() { delete_(); }
104 template<typename CurveType, WebCompositorAnimationCurve::AnimationCurveType CurveId, typename KeyframeType>
105 class WebCompositorAnimationCurveMock : public CurveType {
107 MOCK_METHOD1_T(add, void(const KeyframeType&));
108 MOCK_METHOD2_T(add, void(const KeyframeType&, WebCompositorAnimationCurve::TimingFunctionType));
109 MOCK_METHOD5_T(add, void(const KeyframeType&, double, double, double, double));
111 MOCK_CONST_METHOD1_T(getValue, float(double)); // Only on WebFloatAnimationCurve, but can't hurt to have here.
113 virtual WebCompositorAnimationCurve::AnimationCurveType type() const { return CurveId; };
115 MOCK_METHOD0(delete_, void());
116 ~WebCompositorAnimationCurveMock() { delete_(); }
119 typedef WebCompositorAnimationCurveMock<WebFloatAnimationCurve, WebCompositorAnimationCurve::AnimationCurveTypeFloat, WebFloatKeyframe> WebFloatAnimationCurveMock;
125 class AnimationCompositorAnimationsTestBase : public ::testing::Test {
127 AnimationCompositorAnimationsTestBase() : m_proxyPlatform(&m_mockCompositor) { };
129 class WebCompositorSupportMock : public WebCompositorSupport {
131 MOCK_METHOD3(createAnimation, WebCompositorAnimation*(const WebCompositorAnimationCurve& curve, WebCompositorAnimation::TargetProperty target, int animationId));
132 MOCK_METHOD0(createFloatAnimationCurve, WebFloatAnimationCurve*());
136 class PlatformProxy : public Platform {
138 PlatformProxy(WebCompositorSupportMock** compositor) : m_compositor(compositor) { }
140 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length) { ASSERT_NOT_REACHED(); }
142 WebCompositorSupportMock** m_compositor;
143 virtual WebCompositorSupport* compositorSupport() OVERRIDE { return *m_compositor; }
146 WebCompositorSupportMock* m_mockCompositor;
147 PlatformProxy m_proxyPlatform;
150 Platform* m_platform;
154 m_mockCompositor = 0;
155 m_platform = Platform::current();
156 Platform::initialize(&m_proxyPlatform);
159 virtual void TearDown()
161 Platform::initialize(m_platform);
164 void setCompositorForTesting(WebCompositorSupportMock& mock)
166 ASSERT(!m_mockCompositor);
167 m_mockCompositor = &mock;