151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)/*
251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Copyright (C) 2012 Google Inc. All rights reserved.
351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *
451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * modification, are permitted provided that the following conditions
651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * are met:
751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
1051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
1151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *     documentation and/or other materials provided with the distribution.
1251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) *
1351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
1451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
1751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) */
2451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
2551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#ifndef CompositorAnimationsTestHelper_h
2651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#define CompositorAnimationsTestHelper_h
2751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
2851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/animation/CompositorAnimations.h"
2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/Platform.h"
3051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebCompositorSupport.h"
3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebFloatAnimationCurve.h"
3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebFloatKeyframe.h"
3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "wtf/PassOwnPtr.h"
3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include <gmock/gmock.h>
3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include <gtest/gtest.h>
3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace testing {
4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
4151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)template<typename T>
4251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PassOwnPtr<T> CloneToPassOwnPtr(T& o)
4351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    return adoptPtr(new T(o));
4551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
4651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
4751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace testing
4851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
4951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
509e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)// Test helpers and mocks for Web* types
5151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// -----------------------------------------------------------------------
5251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink {
5351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
549e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)// WebFloatKeyframe is a plain struct, so we just create an == operator
5551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// for it.
5651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline bool operator==(const WebFloatKeyframe& a, const WebFloatKeyframe& b)
5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
5851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    return a.time == b.time && a.value == b.value;
5951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
6151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)inline void PrintTo(const WebFloatKeyframe& frame, ::std::ostream* os)
6251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles){
6351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    *os << "WebFloatKeyframe@" << &frame << "(" << frame.time << ", " << frame.value << ")";
6451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
6651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)// -----------------------------------------------------------------------
6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
689e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)class WebCompositorAnimationMock : public WebCompositorAnimation {
6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)private:
709e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    WebCompositorAnimation::TargetProperty m_property;
7151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
7351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // Target Property is set through the constructor.
749e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    WebCompositorAnimationMock(WebCompositorAnimation::TargetProperty p) : m_property(p) { }
759e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    virtual WebCompositorAnimation::TargetProperty targetProperty() const { return m_property; };
7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD0(id, int());
7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
799e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    MOCK_CONST_METHOD0(iterations, double());
809e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    MOCK_METHOD1(setIterations, void(double));
8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
827242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_CONST_METHOD0(iterationStart, double());
837242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_METHOD1(setIterationStart, void(double));
847242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_CONST_METHOD0(startTime, double());
8651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD1(setStartTime, void(double));
8751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
8851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_CONST_METHOD0(timeOffset, double());
8951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD1(setTimeOffset, void(double));
9051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_CONST_METHOD0(direction, Direction());
927242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_METHOD1(setDirection, void(Direction));
937242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
947242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_CONST_METHOD0(playbackRate, double());
957242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_METHOD1(setPlaybackRate, void(double));
967242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
977242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_CONST_METHOD0(fillMode, FillMode());
987242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    MOCK_METHOD1(setFillMode, void(FillMode));
9951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
10051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD0(delete_, void());
1019e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    ~WebCompositorAnimationMock() { delete_(); }
10251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
10351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1049e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)template<typename CurveType, WebCompositorAnimationCurve::AnimationCurveType CurveId, typename KeyframeType>
1059e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)class WebCompositorAnimationCurveMock : public CurveType {
10651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
10751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD1_T(add, void(const KeyframeType&));
1089e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    MOCK_METHOD2_T(add, void(const KeyframeType&, WebCompositorAnimationCurve::TimingFunctionType));
10951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD5_T(add, void(const KeyframeType&, double, double, double, double));
11051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_CONST_METHOD1_T(getValue, float(double)); // Only on WebFloatAnimationCurve, but can't hurt to have here.
11251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1139e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    virtual WebCompositorAnimationCurve::AnimationCurveType type() const { return CurveId; };
11451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
11551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    MOCK_METHOD0(delete_, void());
1169e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    ~WebCompositorAnimationCurveMock() { delete_(); }
11751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
11851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1199e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)typedef WebCompositorAnimationCurveMock<WebFloatAnimationCurve, WebCompositorAnimationCurve::AnimationCurveTypeFloat, WebFloatKeyframe> WebFloatAnimationCurveMock;
12051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
12151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink
12251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
123c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
12451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
12551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class AnimationCompositorAnimationsTestBase : public ::testing::Test {
12651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)public:
12751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    AnimationCompositorAnimationsTestBase() : m_proxyPlatform(&m_mockCompositor) { };
12851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
1299e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    class WebCompositorSupportMock : public WebCompositorSupport {
13051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    public:
1319e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        MOCK_METHOD3(createAnimation, WebCompositorAnimation*(const WebCompositorAnimationCurve& curve, WebCompositorAnimation::TargetProperty target, int animationId));
1329e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        MOCK_METHOD0(createFloatAnimationCurve, WebFloatAnimationCurve*());
13351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
13451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
13551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)private:
1369e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    class PlatformProxy : public Platform {
13751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    public:
13851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        PlatformProxy(WebCompositorSupportMock** compositor) : m_compositor(compositor) { }
13951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
14051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length) { ASSERT_NOT_REACHED(); }
14151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    private:
14251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        WebCompositorSupportMock** m_compositor;
1439e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        virtual WebCompositorSupport* compositorSupport() OVERRIDE { return *m_compositor; }
14451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    };
14551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    WebCompositorSupportMock* m_mockCompositor;
14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    PlatformProxy m_proxyPlatform;
14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)protected:
1509e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)    Platform* m_platform;
15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void SetUp()
15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {
15451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        m_mockCompositor = 0;
1559e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        m_platform = Platform::current();
1569e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        Platform::initialize(&m_proxyPlatform);
15751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
15851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
15951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    virtual void TearDown()
16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {
1619e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)        Platform::initialize(m_platform);
16251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
16351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
16451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    void setCompositorForTesting(WebCompositorSupportMock& mock)
16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    {
16651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        ASSERT(!m_mockCompositor);
16751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)        m_mockCompositor = &mock;
16851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    }
16951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)};
17051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
17151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)}
17251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)
17351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#endif
174