tor-browser

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

browser_animation_logic_mutations.js (3119B)


      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 mutations:
      7 // * add animation
      8 // * remove animation
      9 // * modify animation
     10 
     11 add_task(async function () {
     12  await addTab(URL_ROOT + "doc_simple_animation.html");
     13  await removeAnimatedElementsExcept([
     14    ".compositor-all",
     15    ".compositor-notall",
     16    ".no-compositor",
     17    ".still",
     18  ]);
     19  const { animationInspector, inspector, panel } =
     20    await openAnimationInspector();
     21 
     22  info("Checking the mutation for add an animation");
     23  const originalAnimationCount = animationInspector.state.animations.length;
     24  await setClassAttribute(animationInspector, ".still", "ball no-compositor");
     25  await waitUntil(
     26    () =>
     27      animationInspector.state.animations.length === originalAnimationCount + 1
     28  );
     29  ok(true, "Count of animation should be plus one to original count");
     30 
     31  info(
     32    "Checking added animation existence even the animation name is duplicated"
     33  );
     34  is(
     35    getAnimationNameCount(panel, "no-compositor"),
     36    2,
     37    "Count of animation should be plus one to original count"
     38  );
     39 
     40  info("Checking the mutation for remove an animation");
     41  await setClassAttribute(
     42    animationInspector,
     43    ".compositor-notall",
     44    "ball still"
     45  );
     46  await waitUntil(
     47    () => animationInspector.state.animations.length === originalAnimationCount
     48  );
     49  ok(
     50    true,
     51    "Count of animation should be same to original count since we remove an animation"
     52  );
     53 
     54  info("Checking the mutation for modify an animation");
     55  await selectNode(".compositor-all", inspector);
     56  await setStyle(
     57    animationInspector,
     58    ".compositor-all",
     59    "animationDuration",
     60    "100s"
     61  );
     62  await setStyle(
     63    animationInspector,
     64    ".compositor-all",
     65    "animationIterationCount",
     66    1
     67  );
     68  const summaryGraphPathEl = getSummaryGraphPathElement(
     69    panel,
     70    "compositor-all"
     71  );
     72  await waitUntil(() => summaryGraphPathEl.viewBox.baseVal.width === 100000);
     73  ok(
     74    true,
     75    "Width of summary graph path should be 100000 " +
     76      "after modifing the duration and iteration count"
     77  );
     78  await setStyle(
     79    animationInspector,
     80    ".compositor-all",
     81    "animationDelay",
     82    "100s"
     83  );
     84  await waitUntil(() => summaryGraphPathEl.viewBox.baseVal.width === 200000);
     85  ok(
     86    true,
     87    "Width of summary graph path should be 200000 after modifing the delay"
     88  );
     89  ok(
     90    summaryGraphPathEl.parentElement.querySelector(".animation-delay-sign"),
     91    "Delay sign element shoud exist"
     92  );
     93 });
     94 
     95 function getAnimationNameCount(panel, animationName) {
     96  return [...panel.querySelectorAll(".animation-name")].reduce(
     97    (count, element) =>
     98      element.textContent === animationName ? count + 1 : count,
     99    0
    100  );
    101 }
    102 
    103 function getSummaryGraphPathElement(panel, animationName) {
    104  for (const animationNameEl of panel.querySelectorAll(".animation-name")) {
    105    if (animationNameEl.textContent === animationName) {
    106      return animationNameEl
    107        .closest(".animation-summary-graph")
    108        .querySelector(".animation-summary-graph-path");
    109    }
    110  }
    111 
    112  return null;
    113 }