tor-browser

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

browser_animation_current-time-label.js (2429B)


      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 CurrentTimeLabel component:
      7 // * element existence
      8 // * label content at plural timing
      9 
     10 add_task(async function () {
     11  await addTab(URL_ROOT + "doc_multi_timings.html");
     12  await removeAnimatedElementsExcept([".keyframes-easing-step"]);
     13  const { animationInspector, panel } = await openAnimationInspector();
     14 
     15  info("Checking current time label existence");
     16  const labelEl = panel.querySelector(".current-time-label");
     17  ok(labelEl, "current time label should exist");
     18 
     19  info("Checking current time label content");
     20  const duration = animationInspector.state.timeScale.getDuration();
     21  clickOnCurrentTimeScrubberController(animationInspector, panel, 0.5);
     22  await waitUntilAnimationsPlayState(animationInspector, "paused");
     23  await waitUntilCurrentTimeChangedAt(animationInspector, duration * 0.5);
     24  const targetAnimation = animationInspector.state.animations[0];
     25  assertLabelContent(labelEl, targetAnimation.state.currentTime);
     26 
     27  clickOnCurrentTimeScrubberController(animationInspector, panel, 0.2);
     28  await waitUntilCurrentTimeChangedAt(animationInspector, duration * 0.2);
     29  assertLabelContent(labelEl, targetAnimation.state.currentTime);
     30 
     31  info("Checking current time label content during running");
     32  // Resume
     33  clickOnPauseResumeButton(animationInspector, panel);
     34  const previousContent = labelEl.textContent;
     35 
     36  info("Wait until the time label changes");
     37  await waitFor(() => labelEl.textContent != previousContent);
     38  isnot(
     39    previousContent,
     40    labelEl.textContent,
     41    "Current time label should change"
     42  );
     43 });
     44 
     45 function assertLabelContent(labelEl, time) {
     46  const expected = formatStopwatchTime(time);
     47  is(labelEl.textContent, expected, `Content of label should be ${expected}`);
     48 }
     49 
     50 function formatStopwatchTime(time) {
     51  // Format falsy values as 0
     52  if (!time) {
     53    return "00:00.000";
     54  }
     55 
     56  let milliseconds = parseInt(time % 1000, 10);
     57  let seconds = parseInt((time / 1000) % 60, 10);
     58  let minutes = parseInt(time / (1000 * 60), 10);
     59 
     60  const pad = (nb, max) => {
     61    if (nb < max) {
     62      return new Array((max + "").length - (nb + "").length + 1).join("0") + nb;
     63    }
     64 
     65    return nb;
     66  };
     67 
     68  minutes = pad(minutes, 10);
     69  seconds = pad(seconds, 10);
     70  milliseconds = pad(milliseconds, 100);
     71 
     72  return `${minutes}:${seconds}.${milliseconds}`;
     73 }