Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp

Issue 2236193002: WIP: Implement CSS transitions on top of InterpolationTypes instead of AnimatableValues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_environmentStyle
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp
diff --git a/third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp b/third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp
index 3b965884f9458c60ebc71a368f6bb7dc3b7738ec..67a76e6f7d81d38c9936709205f756e325d4c64e 100644
--- a/third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp
+++ b/third_party/WebKit/Source/core/animation/InterpolableValueTest.cpp
@@ -11,60 +11,29 @@
namespace blink {
-namespace {
-
-class SampleInterpolation : public Interpolation {
-public:
- static PassRefPtr<Interpolation> create(std::unique_ptr<InterpolableValue> start, std::unique_ptr<InterpolableValue> end)
- {
- return adoptRef(new SampleInterpolation(std::move(start), std::move(end)));
- }
-
- PropertyHandle getProperty() const override
- {
- return PropertyHandle(CSSPropertyBackgroundColor);
- }
-private:
- SampleInterpolation(std::unique_ptr<InterpolableValue> start, std::unique_ptr<InterpolableValue> end)
- : Interpolation(std::move(start), std::move(end))
- {
- }
-};
-
-} // namespace
-
class AnimationInterpolableValueTest : public ::testing::Test {
protected:
- InterpolableValue* interpolationValue(Interpolation& interpolation)
+ std::unique_ptr<InterpolableValue> interpolate(std::unique_ptr<InterpolableValue> a, std::unique_ptr<InterpolableValue> b, double progress)
{
- return interpolation.getCachedValueForTesting();
+ std::unique_ptr<InterpolableValue> result = a->clone();
+ a->interpolate(*b, progress, *result);
+ return result;
}
double interpolateNumbers(double a, double b, double progress)
{
- RefPtr<Interpolation> i = SampleInterpolation::create(InterpolableNumber::create(a), InterpolableNumber::create(b));
- i->interpolate(0, progress);
- return toInterpolableNumber(interpolationValue(*i.get()))->value();
+ return toInterpolableNumber(*interpolate(InterpolableNumber::create(a), InterpolableNumber::create(b), progress)).value();
}
bool interpolateBools(bool a, bool b, double progress)
{
- RefPtr<Interpolation> i = SampleInterpolation::create(InterpolableBool::create(a), InterpolableBool::create(b));
- i->interpolate(0, progress);
- return toInterpolableBool(interpolationValue(*i.get()))->value();
+ return toInterpolableBool(*interpolate(InterpolableBool::create(a), InterpolableBool::create(b), progress)).value();
}
void scaleAndAdd(InterpolableValue& base, double scale, const InterpolableValue& add)
{
base.scaleAndAdd(scale, add);
}
-
- PassRefPtr<Interpolation> interpolateLists(std::unique_ptr<InterpolableList> listA, std::unique_ptr<InterpolableList> listB, double progress)
- {
- RefPtr<Interpolation> i = SampleInterpolation::create(std::move(listA), std::move(listB));
- i->interpolate(0, progress);
- return i;
- }
};
TEST_F(AnimationInterpolableValueTest, InterpolateNumbers)
@@ -99,11 +68,11 @@ TEST_F(AnimationInterpolableValueTest, SimpleList)
listB->set(1, InterpolableNumber::create(-200));
listB->set(2, InterpolableNumber::create(300));
- RefPtr<Interpolation> i = interpolateLists(std::move(listA), std::move(listB), 0.3);
- InterpolableList* outList = toInterpolableList(interpolationValue(*i.get()));
- EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList->get(0))->value());
- EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList->get(1))->value());
- EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList->get(2))->value());
+ std::unique_ptr<InterpolableValue> out = interpolate(std::move(listA), std::move(listB), 0.3);
+ const InterpolableList& outList = toInterpolableList(*out);
+ EXPECT_FLOAT_EQ(30, toInterpolableNumber(outList.get(0))->value());
+ EXPECT_FLOAT_EQ(-30.6f, toInterpolableNumber(outList.get(1))->value());
+ EXPECT_FLOAT_EQ(104.35f, toInterpolableNumber(outList.get(2))->value());
}
TEST_F(AnimationInterpolableValueTest, NestedList)
@@ -122,11 +91,11 @@ TEST_F(AnimationInterpolableValueTest, NestedList)
listB->set(1, std::move(subListB));
listB->set(2, InterpolableBool::create(true));
- RefPtr<Interpolation> i = interpolateLists(std::move(listA), std::move(listB), 0.5);
- InterpolableList* outList = toInterpolableList(interpolationValue(*i.get()));
- EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList->get(0))->value());
- EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList->get(1))->get(0))->value());
- EXPECT_TRUE(toInterpolableBool(outList->get(2))->value());
+ std::unique_ptr<InterpolableValue> out = interpolate(std::move(listA), std::move(listB), 0.5);
+ const InterpolableList& outList = toInterpolableList(*out);
+ EXPECT_FLOAT_EQ(50, toInterpolableNumber(outList.get(0))->value());
+ EXPECT_FLOAT_EQ(75, toInterpolableNumber(toInterpolableList(outList.get(1))->get(0))->value());
+ EXPECT_TRUE(toInterpolableBool(outList.get(2))->value());
}
TEST_F(AnimationInterpolableValueTest, ScaleAndAddNumbers)
« no previous file with comments | « third_party/WebKit/Source/core/animation/InterpolableValue.h ('k') | third_party/WebKit/Source/core/animation/Interpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698