Skip to content

Commit

Permalink
Add allow-discrete to non-interpolable WPTs
Browse files Browse the repository at this point in the history
This patch changes the test runner for animation tests in WPT to
additionally test transition-behavior:allow-discrete for any property
that we are running a non-interpolable or non-animatable test on.

Change-Id: I7e13600c0182ab5e4839fea4e32e759673abe84e
  • Loading branch information
josepharhar authored and chromium-wpt-export-bot committed Nov 9, 2023
1 parent 8c023c3 commit 7bef3ea
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions css/support/interpolation-testcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,59 @@
},
};

var cssTransitionsInterpolationAllowDiscrete = {
name: 'CSS Transitions with transition-behavior:allow-discrete',
isSupported: function() {return true;},
supportsProperty: function() {return true;},
supportsValue: function() {return true;},
setup: function(property, from, target) {
target.style.setProperty(property, isNeutralKeyframe(from) ? '' : from);
},
nonInterpolationExpectations: function(from, to) {
return expectFlip(from, to, 0.5);
},
notAnimatableExpectations: function(from, to, underlying) {
return expectFlip(from, to, -Infinity);
},
interpolate: function(property, from, to, at, target, behavior) {
// Force a style recalc on target to set the 'from' value.
getComputedStyle(target).getPropertyValue(property);
target.style.transitionDuration = '100s';
target.style.transitionDelay = '-50s';
target.style.transitionTimingFunction = createEasing(at);
target.style.transitionProperty = property;
target.style.transitionBehavior = 'allow-discrete';
target.style.setProperty(property, isNeutralKeyframe(to) ? '' : to);
},
};

var cssTransitionAllInterpolationAllowDiscrete = {
name: 'CSS Transitions with transition-property:all and transition-behavor:allow-discrete',
isSupported: function() {return true;},
// The 'all' value doesn't cover custom properties.
supportsProperty: function(property) {return property.indexOf('--') !== 0;},
supportsValue: function() {return true;},
setup: function(property, from, target) {
target.style.setProperty(property, isNeutralKeyframe(from) ? '' : from);
},
nonInterpolationExpectations: function(from, to) {
return expectFlip(from, to, 0.5);
},
notAnimatableExpectations: function(from, to, underlying) {
return expectFlip(from, to, -Infinity);
},
interpolate: function(property, from, to, at, target, behavior) {
// Force a style recalc on target to set the 'from' value.
getComputedStyle(target).getPropertyValue(property);
target.style.transitionDuration = '100s';
target.style.transitionDelay = '-50s';
target.style.transitionTimingFunction = createEasing(at);
target.style.transitionProperty = 'all';
target.style.transitionBehavior = 'allow-discrete';
target.style.setProperty(property, isNeutralKeyframe(to) ? '' : to);
},
};

var webAnimationsInterpolation = {
name: 'Web Animations',
isSupported: function() {return 'animate' in Element.prototype;},
Expand Down Expand Up @@ -435,13 +488,19 @@
function test_not_animatable(options) {
test_interpolation(options, expectNotAnimatable);
}
function create_tests() {
function create_tests(addAllowDiscreteTests) {
var interpolationMethods = [
cssTransitionsInterpolation,
cssTransitionAllInterpolation,
cssAnimationsInterpolation,
webAnimationsInterpolation,
];
if (addAllowDiscreteTests) {
interpolationMethods = [
cssTransitionsInterpolationAllowDiscrete,
cssTransitionAllInterpolationAllowDiscrete,
].concat(interpolationMethods);
}
var container = createElement(document.body);
var targets = createTestTargets(interpolationMethods, interpolationTests, compositionTests, container);
// Separate interpolation and measurement into different phases to avoid O(n^2) of the number of targets.
Expand All @@ -456,7 +515,7 @@

function test_interpolation(options, expectations) {
interpolationTests.push({options, expectations});
create_tests();
create_tests(expectations === expectNoInterpolation || expectations === expectNotAnimatable);
interpolationTests = [];
}
function test_composition(options, expectations) {
Expand Down

0 comments on commit 7bef3ea

Please sign in to comment.