Commit 8cb075ef authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Deduplicate helper class SampleInterpolation in unit tests

Both InterpolableValueTest and InterpolationEffectTest use an
identical class for value testing. These classes collided in jumbo
builds where they were compiled in the same translation unit.

This patch moves the class to AnimationTestHelper.h and changes its
name to be more descriptive now when it isn't as close to where it
is used anymore.

Also changing the name of the kDuration constant that interfered
with blink::kDuration.

R=fs@opera.com

Change-Id: Ic90cec2972f5464d7932b2ba91994273968e87c4
Reviewed-on: https://chromium-review.googlesource.com/574489Reviewed-by: default avatarFredrik Söderquist <fs@opera.com>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#487067}
parent 1223c51e
......@@ -5,6 +5,8 @@
#ifndef AnimationTestHelper_h
#define AnimationTestHelper_h
#include "core/animation/InterpolableValue.h"
#include "core/animation/LegacyStyleInterpolation.h"
#include "platform/wtf/text/StringView.h"
#include "platform/wtf/text/WTFString.h"
#include "v8/include/v8.h"
......@@ -20,6 +22,23 @@ void SetV8ObjectPropertyAsNumber(v8::Isolate*,
const StringView& name,
double value);
class SampleTestInterpolation : public LegacyStyleInterpolation {
public:
static PassRefPtr<LegacyStyleInterpolation> Create(
std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end) {
return AdoptRef(
new SampleTestInterpolation(std::move(start), std::move(end)));
}
private:
SampleTestInterpolation(std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end)
: LegacyStyleInterpolation(std::move(start),
std::move(end),
CSSPropertyBackgroundColor) {}
};
} // namespace blink
#endif // AnimationTestHelper_h
......@@ -2,34 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "core/animation/AnimationTestHelper.h"
#include "core/animation/InterpolableValue.h"
#include "core/animation/LegacyStyleInterpolation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <memory>
namespace blink {
namespace {
class SampleInterpolation : public LegacyStyleInterpolation {
public:
static PassRefPtr<LegacyStyleInterpolation> Create(
std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end) {
return AdoptRef(new SampleInterpolation(std::move(start), std::move(end)));
}
private:
SampleInterpolation(std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end)
: LegacyStyleInterpolation(std::move(start),
std::move(end),
CSSPropertyBackgroundColor) {}
};
} // namespace
class AnimationInterpolableValueTest : public ::testing::Test {
protected:
InterpolableValue* InterpolationValue(
......@@ -38,7 +18,7 @@ class AnimationInterpolableValueTest : public ::testing::Test {
}
double InterpolateNumbers(double a, double b, double progress) {
RefPtr<LegacyStyleInterpolation> i = SampleInterpolation::Create(
RefPtr<LegacyStyleInterpolation> i = SampleTestInterpolation::Create(
InterpolableNumber::Create(a), InterpolableNumber::Create(b));
i->Interpolate(0, progress);
return ToInterpolableNumber(InterpolationValue(*i.Get()))->Value();
......@@ -55,7 +35,7 @@ class AnimationInterpolableValueTest : public ::testing::Test {
std::unique_ptr<InterpolableList> list_b,
double progress) {
RefPtr<LegacyStyleInterpolation> i =
SampleInterpolation::Create(std::move(list_a), std::move(list_b));
SampleTestInterpolation::Create(std::move(list_a), std::move(list_b));
i->Interpolate(0, progress);
return i;
}
......
......@@ -2,33 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "core/animation/AnimationTestHelper.h"
#include "core/animation/InterpolationEffect.h"
#include "core/animation/LegacyStyleInterpolation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <memory>
namespace blink {
namespace {
class SampleInterpolation : public LegacyStyleInterpolation {
public:
static PassRefPtr<LegacyStyleInterpolation> Create(
std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end) {
return AdoptRef(new SampleInterpolation(std::move(start), std::move(end)));
}
private:
SampleInterpolation(std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end)
: LegacyStyleInterpolation(std::move(start),
std::move(end),
CSSPropertyBackgroundColor) {}
};
const double kDuration = 1.0;
const double kInterpolationTestDuration = 1.0;
} // namespace
......@@ -49,31 +33,31 @@ class AnimationInterpolationEffectTest : public ::testing::Test {
TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) {
InterpolationEffect interpolation_effect;
interpolation_effect.AddInterpolation(
SampleInterpolation::Create(InterpolableNumber::Create(0),
InterpolableNumber::Create(10)),
SampleTestInterpolation::Create(InterpolableNumber::Create(0),
InterpolableNumber::Create(10)),
RefPtr<TimingFunction>(), 0, 1, -1, 2);
Vector<RefPtr<Interpolation>> active_interpolations;
interpolation_effect.GetActiveInterpolations(-2, kDuration,
interpolation_effect.GetActiveInterpolations(-2, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(0ul, active_interpolations.size());
interpolation_effect.GetActiveInterpolations(-0.5, kDuration,
interpolation_effect.GetActiveInterpolations(-0.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_EQ(-5, GetInterpolableNumber(active_interpolations.at(0)));
interpolation_effect.GetActiveInterpolations(0.5, kDuration,
interpolation_effect.GetActiveInterpolations(0.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_FLOAT_EQ(5, GetInterpolableNumber(active_interpolations.at(0)));
interpolation_effect.GetActiveInterpolations(1.5, kDuration,
interpolation_effect.GetActiveInterpolations(1.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_FLOAT_EQ(15, GetInterpolableNumber(active_interpolations.at(0)));
interpolation_effect.GetActiveInterpolations(3, kDuration,
interpolation_effect.GetActiveInterpolations(3, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(0ul, active_interpolations.size());
}
......@@ -81,56 +65,56 @@ TEST_F(AnimationInterpolationEffectTest, SingleInterpolation) {
TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations) {
InterpolationEffect interpolation_effect;
interpolation_effect.AddInterpolation(
SampleInterpolation::Create(InterpolableNumber::Create(10),
InterpolableNumber::Create(15)),
SampleTestInterpolation::Create(InterpolableNumber::Create(10),
InterpolableNumber::Create(15)),
RefPtr<TimingFunction>(), 1, 2, 1, 3);
interpolation_effect.AddInterpolation(
SampleInterpolation::Create(InterpolableNumber::Create(0),
InterpolableNumber::Create(1)),
SampleTestInterpolation::Create(InterpolableNumber::Create(0),
InterpolableNumber::Create(1)),
LinearTimingFunction::Shared(), 0, 1, 0, 1);
interpolation_effect.AddInterpolation(
SampleInterpolation::Create(InterpolableNumber::Create(1),
InterpolableNumber::Create(6)),
SampleTestInterpolation::Create(InterpolableNumber::Create(1),
InterpolableNumber::Create(6)),
CubicBezierTimingFunction::Preset(
CubicBezierTimingFunction::EaseType::EASE),
0.5, 1.5, 0.5, 1.5);
Vector<RefPtr<Interpolation>> active_interpolations;
interpolation_effect.GetActiveInterpolations(-0.5, kDuration,
interpolation_effect.GetActiveInterpolations(-0.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(0ul, active_interpolations.size());
interpolation_effect.GetActiveInterpolations(0, kDuration,
interpolation_effect.GetActiveInterpolations(0, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_FLOAT_EQ(0, GetInterpolableNumber(active_interpolations.at(0)));
interpolation_effect.GetActiveInterpolations(0.5, kDuration,
interpolation_effect.GetActiveInterpolations(0.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(2ul, active_interpolations.size());
EXPECT_FLOAT_EQ(0.5f, GetInterpolableNumber(active_interpolations.at(0)));
EXPECT_FLOAT_EQ(1, GetInterpolableNumber(active_interpolations.at(1)));
interpolation_effect.GetActiveInterpolations(1, kDuration,
interpolation_effect.GetActiveInterpolations(1, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(2ul, active_interpolations.size());
EXPECT_FLOAT_EQ(10, GetInterpolableNumber(active_interpolations.at(0)));
EXPECT_FLOAT_EQ(5.0282884f,
GetInterpolableNumber(active_interpolations.at(1)));
interpolation_effect.GetActiveInterpolations(1, kDuration * 1000,
active_interpolations);
interpolation_effect.GetActiveInterpolations(
1, kInterpolationTestDuration * 1000, active_interpolations);
EXPECT_EQ(2ul, active_interpolations.size());
EXPECT_FLOAT_EQ(10, GetInterpolableNumber(active_interpolations.at(0)));
EXPECT_FLOAT_EQ(5.0120168f,
GetInterpolableNumber(active_interpolations.at(1)));
interpolation_effect.GetActiveInterpolations(1.5, kDuration,
interpolation_effect.GetActiveInterpolations(1.5, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_FLOAT_EQ(12.5f, GetInterpolableNumber(active_interpolations.at(0)));
interpolation_effect.GetActiveInterpolations(2, kDuration,
interpolation_effect.GetActiveInterpolations(2, kInterpolationTestDuration,
active_interpolations);
EXPECT_EQ(1ul, active_interpolations.size());
EXPECT_FLOAT_EQ(15, GetInterpolableNumber(active_interpolations.at(0)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment