servo/tests/wpt/web-platform-tests/web-animations
2018-06-04 22:45:46 -04:00
..
animation-model Update web-platform-tests to revision ee82278e15570e573d87fb80179ff8231b6db61a 2018-06-03 22:45:23 -04:00
interfaces Update web-platform-tests to revision 81962ac8802223d038b188b6f9cb88a0a9c5beee 2018-05-18 23:55:46 -04:00
resources Update web-platform-tests to revision e87f38097902e16348d4e17f4fe3bc2d0112bff1 2018-03-17 23:34:27 -04:00
timing-model Update web-platform-tests to revision dc60bfc45b49e3a5e653320e65b0fd447676b836 2018-06-04 22:45:46 -04:00
OWNERS Update web-platform-tests to revision 95aad3bd9b82b5c65d84d53517b65ba084de9394 2016-02-12 09:41:14 +01:00
README.md Update web-platform-tests to revision 10168e9a5d44efbc6e7d416d1d454eb9c9f1396c 2018-01-31 12:24:47 -05:00
testcommon.js Update web-platform-tests to revision 155daf0c385420faf208b8bd5e319e244ec7f9cc 2018-05-28 11:37:21 -04:00

Web Animations Test Suite

Specification: https://drafts.csswg.org/web-animations/

Guidelines for writing tests

  • Try to follow the spec outline where possible.

    For example, if you want to test setting the start time, you might be tempted to put all the tests in:

    /web-animations/interfaces/Animation/startTime.html

    However, in the spec most of the logic is in the “Set the animation start time“ procedure in the “Timing model” section.

    Instead, try something like:

    • /web-animations/timing-model/animations/set-the-animation-start-time.html
      Tests all the branches and inputs to the procedure as defined in the spec (using the Animation.startTime API).
    • /web-animations/interfaces/Animation/startTime.html
      Tests API-layer specific issues like mapping unresolved values to null, etc.

    On that note, two levels of subdirectories is enough even if the spec has deeper nesting.

    Note that most of the existing tests in the suite don't do this well yet. That's the direction we're heading, however.

  • Test the spec.

    • If the spec defines a timing calculation that is directly reflected in the iteration progress (i.e. anim.effect.getComputedTiming().progress), test that instead of calling getComputedStyle(elem).marginLeft.

    • Likewise, don't add needless tests for anim.playbackState. The playback state is a calculated value based on other values. It's rarely necessary to test directly unless you need, for example, to check that a pending task is scheduled (which isn't observable elsewhere other than waiting for the corresponding promise to complete).

  • Try to keep tests as simple and focused as possible.

    e.g.

    test(t => {
      const animation = createDiv(t).animate(null);
      assert_class_string(animation, 'Animation', 'Returned object is an Animation');
    }, 'Element.animate() creates an Animation object');
    
    test(t => {
      assert_throws({ name: 'TypeError' }, () => {
        createDiv(t).animate(null, -1);
      });
    }, 'Setting a negative duration throws a TypeError');
    
    promise_test(t => {
      const animation = createDiv(t).animate(null, 100 * MS_PER_SEC);
      return animation.ready.then(() => {
        assert_greater_than(animation.startTime, 0, 'startTime when running');
      });
    }, 'startTime is resolved when running');
    

    If you're generating complex test loops and factoring out utility functions that affect the logic of the test (other than, say, simple assertion utility functions), you're probably doing it wrong.

    It should be possible to understand exactly what the test is doing at a glance without having to scroll up and down the test file and refer to other files.

    See Justin Searls' presentation, “How to stop hating your tests” for some tips on making your tests simpler.

  • Assume tests will run on under-performing hardware where the time between animation frames might run into 10s of seconds. As a result, animations that are expected to still be running during the test should be at least 100s in length.

  • Avoid using GLOBAL_CONSTS that make the test harder to read. It's fine to repeat the the same parameter values like 100 * MS_PER_SEC over and over again since it makes it easy to read and debug a test in isolation. Remember, even if we do need to make all tests take, say 200s each, text editors are very good at search and replace.

  • Use the assert_times_equal assertion for comparing times returned from the API. This asserts that the time values are equal using a tolerance based on the precision recommended in the spec. This tolerance is applied to both of the values being compared. That is, it effectively allows double the epsilon that is used when comparing with an absolute value.

    For comparing a time value returned from the API to an absolute value, use assert_time_equals_literal. This tests that the actual value is equal to the expected value within the precision recommended in the spec.

    Both assert_times_equal and assert_time_equals_literal are defined in a way that implementations can override them to meet their own precision requirements.

  • There are quite a few bad tests in the repository. We're learning as we go. Don't just copy them blindly—please fix them!