tor-browser

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

browser_animation_timing_negative-playback-rate_summary-graph.js (5554B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test for following summary graph with the animation which is negative playback rate.
      7 // * Tooltips
      8 // * Graph path
      9 // * Delay sign
     10 // * End delay sign
     11 
     12 const TEST_DATA = [
     13  {
     14    targetSelector: ".normal",
     15    expectedPathList: [
     16      {
     17        selector: ".animation-iteration-path",
     18        path: [
     19          { x: 0, y: 100 },
     20          { x: 50000, y: 50 },
     21          { x: 100000, y: 0 },
     22        ],
     23      },
     24    ],
     25    expectedTooltip: "Playback rate: -1",
     26    expectedViewboxWidth: 200000,
     27  },
     28  {
     29    targetSelector: ".normal-playbackrate-2",
     30    expectedPathList: [
     31      {
     32        selector: ".animation-iteration-path",
     33        path: [
     34          { x: 0, y: 100 },
     35          { x: 50000, y: 50 },
     36          { x: 100000, y: 0 },
     37        ],
     38      },
     39    ],
     40    expectedTooltip: "Playback rate: -2",
     41    expectedViewboxWidth: 400000,
     42  },
     43  {
     44    targetSelector: ".positive-delay",
     45    expectedSignList: [
     46      {
     47        selector: ".animation-end-delay-sign",
     48        sign: {
     49          marginInlineStart: "75%",
     50          width: "25%",
     51        },
     52      },
     53    ],
     54    expectedPathList: [
     55      {
     56        selector: ".animation-iteration-path",
     57        path: [
     58          { x: 0, y: 100 },
     59          { x: 50000, y: 50 },
     60          { x: 100000, y: 0 },
     61        ],
     62      },
     63    ],
     64    expectedTooltip: "Playback rate: -1",
     65  },
     66  {
     67    targetSelector: ".negative-delay",
     68    expectedSignList: [
     69      {
     70        selector: ".animation-end-delay-sign",
     71        sign: {
     72          marginInlineStart: "50%",
     73          width: "25%",
     74        },
     75      },
     76    ],
     77    expectedPathList: [
     78      {
     79        selector: ".animation-iteration-path",
     80        path: [
     81          { x: 0, y: 100 },
     82          { x: 50000, y: 50 },
     83          { x: 50000, y: 0 },
     84        ],
     85      },
     86      {
     87        selector: ".animation-negative-delay-path path",
     88        path: [
     89          { x: 50000, y: 50 },
     90          { x: 100000, y: 0 },
     91        ],
     92      },
     93    ],
     94    expectedTooltip: "Playback rate: -1",
     95  },
     96  {
     97    targetSelector: ".positive-end-delay",
     98    expectedSignList: [
     99      {
    100        selector: ".animation-delay-sign",
    101        sign: {
    102          isFilled: true,
    103          marginInlineStart: "25%",
    104          width: "25%",
    105        },
    106      },
    107    ],
    108    expectedPathList: [
    109      {
    110        selector: ".animation-iteration-path",
    111        path: [
    112          { x: 50000, y: 100 },
    113          { x: 100000, y: 50 },
    114          { x: 150000, y: 0 },
    115        ],
    116      },
    117    ],
    118    expectedTooltip: "Playback rate: -1",
    119  },
    120  {
    121    targetSelector: ".negative-end-delay",
    122    expectedSignList: [
    123      {
    124        selector: ".animation-delay-sign",
    125        sign: {
    126          isFilled: true,
    127          marginInlineStart: "0%",
    128          width: "25%",
    129        },
    130      },
    131    ],
    132    expectedPathList: [
    133      {
    134        selector: ".animation-iteration-path",
    135        path: [
    136          { x: 0, y: 50 },
    137          { x: 50000, y: 0 },
    138        ],
    139      },
    140      {
    141        selector: ".animation-negative-end-delay-path path",
    142        path: [
    143          { x: -50000, y: 100 },
    144          { x: 0, y: 0 },
    145        ],
    146      },
    147    ],
    148    expectedTooltip: "Playback rate: -1",
    149  },
    150 ];
    151 
    152 add_task(async function () {
    153  await addTab(URL_ROOT + "doc_negative_playback_rate.html");
    154  const { panel } = await openAnimationInspector();
    155 
    156  for (const testData of TEST_DATA) {
    157    const {
    158      targetSelector,
    159      expectedPathList,
    160      expectedSignList,
    161      expectedTooltip,
    162      expectedViewboxWidth,
    163    } = testData;
    164 
    165    const animationItemEl = await findAnimationItemByTargetSelector(
    166      panel,
    167      targetSelector
    168    );
    169    const summaryGraphEl = animationItemEl.querySelector(
    170      ".animation-summary-graph"
    171    );
    172 
    173    info(`Check tooltip for the animation of ${targetSelector}`);
    174    assertTooltip(summaryGraphEl, expectedTooltip);
    175 
    176    if (expectedPathList) {
    177      for (const { selector, path } of expectedPathList) {
    178        info(`Check path for ${selector}`);
    179        assertPath(summaryGraphEl, selector, path);
    180      }
    181    }
    182 
    183    if (expectedSignList) {
    184      for (const { selector, sign } of expectedSignList) {
    185        info(`Check sign for ${selector}`);
    186        assertSign(summaryGraphEl, selector, sign);
    187      }
    188    }
    189 
    190    if (expectedViewboxWidth) {
    191      info("Check width of viewbox of SVG");
    192      const svgEl = summaryGraphEl.querySelector(
    193        ".animation-summary-graph-path"
    194      );
    195      is(
    196        svgEl.viewBox.baseVal.width,
    197        expectedViewboxWidth,
    198        `width of viewbox should be ${expectedViewboxWidth}`
    199      );
    200    }
    201  }
    202 });
    203 
    204 function assertPath(summaryGraphEl, pathSelector, expectedPath) {
    205  const pathEl = summaryGraphEl.querySelector(pathSelector);
    206  assertPathSegments(pathEl, true, expectedPath);
    207 }
    208 
    209 function assertSign(summaryGraphEl, selector, expectedSign) {
    210  const signEl = summaryGraphEl.querySelector(selector);
    211 
    212  is(
    213    signEl.style.marginInlineStart,
    214    expectedSign.marginInlineStart,
    215    `marginInlineStart position should be ${expectedSign.marginInlineStart}`
    216  );
    217  is(
    218    signEl.style.width,
    219    expectedSign.width,
    220    `Width should be ${expectedSign.width}`
    221  );
    222  is(
    223    signEl.classList.contains("fill"),
    224    expectedSign.isFilled || false,
    225    "signEl should be correct"
    226  );
    227 }
    228 
    229 function assertTooltip(summaryGraphEl, expectedTooltip) {
    230  const tooltip = summaryGraphEl.getAttribute("title");
    231  ok(
    232    tooltip.includes(expectedTooltip),
    233    `Tooltip should include '${expectedTooltip}'`
    234  );
    235 }