tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_animation_name.js (2805B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that AnimationPlayerActor.getName returns the right name depending on
      6 // the type of an animation and the various properties available on it.
      7 
      8 const {
      9  AnimationPlayerActor,
     10 } = require("resource://devtools/server/actors/animation.js");
     11 
     12 function run_test() {
     13  // Mock a window with just the properties the AnimationPlayerActor uses.
     14  const window = {};
     15  window.MutationObserver = class {
     16    constructor() {
     17      this.observe = () => {};
     18    }
     19  };
     20  window.Animation = class {
     21    constructor() {
     22      this.effect = { target: getMockNode() };
     23    }
     24 
     25    static isInstance(instance) {
     26      return instance instanceof this;
     27    }
     28  };
     29 
     30  window.CSSAnimation = class extends window.Animation {};
     31  window.CSSTransition = class extends window.Animation {};
     32 
     33  // Helper to get a mock DOM node.
     34  function getMockNode() {
     35    return {
     36      ownerDocument: {
     37        defaultView: window,
     38      },
     39    };
     40  }
     41 
     42  // Objects in this array should contain the following properties:
     43  // - desc {String} For logging
     44  // - animation {Object} An animation object instantiated from one of the mock
     45  //   window animation constructors.
     46  // - props {Objet} Properties of this object will be added to the animation
     47  //   object.
     48  // - expectedName {String} The expected name returned by
     49  //   AnimationPlayerActor.getName.
     50  const TEST_DATA = [
     51    {
     52      desc: "Animation with an id",
     53      animation: new window.Animation(),
     54      props: { id: "animation-id" },
     55      expectedName: "animation-id",
     56    },
     57    {
     58      desc: "Animation without an id",
     59      animation: new window.Animation(),
     60      props: {},
     61      expectedName: "",
     62    },
     63    {
     64      desc: "CSSTransition with an id",
     65      animation: new window.CSSTransition(),
     66      props: { id: "transition-with-id", transitionProperty: "width" },
     67      expectedName: "transition-with-id",
     68    },
     69    {
     70      desc: "CSSAnimation with an id",
     71      animation: new window.CSSAnimation(),
     72      props: { id: "animation-with-id", animationName: "move" },
     73      expectedName: "animation-with-id",
     74    },
     75    {
     76      desc: "CSSTransition without an id",
     77      animation: new window.CSSTransition(),
     78      props: { transitionProperty: "width" },
     79      expectedName: "width",
     80    },
     81    {
     82      desc: "CSSAnimation without an id",
     83      animation: new window.CSSAnimation(),
     84      props: { animationName: "move" },
     85      expectedName: "move",
     86    },
     87  ];
     88 
     89  for (const { desc, animation, props, expectedName } of TEST_DATA) {
     90    info(desc);
     91    for (const key in props) {
     92      animation[key] = props[key];
     93    }
     94    const actor = new AnimationPlayerActor({}, animation);
     95    Assert.equal(actor.getName(), expectedName);
     96  }
     97 }