tor-browser

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

browser_animation_playPauseIframe.js (2025B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Check that the AnimationsActor can pause/play all animations even those
      7 // within iframes.
      8 
      9 const URL = MAIN_DOMAIN + "animation.html";
     10 
     11 // Import inspector's shared head.
     12 Services.scriptloader.loadSubScript(
     13  "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js",
     14  this
     15 );
     16 
     17 add_task(async function () {
     18  info("Creating a test document with 2 iframes containing animated nodes");
     19 
     20  const { inspector, target } = await initAnimationsFrontForUrl(
     21    "data:text/html;charset=utf-8," +
     22      "<iframe id='i1' src='" +
     23      URL +
     24      "'></iframe>" +
     25      "<iframe id='i2' src='" +
     26      URL +
     27      "'></iframe>"
     28  );
     29 
     30  info("Getting the 2 iframe container nodes and animated nodes in them");
     31  const nodeInFrame1 = await getNodeFrontInFrames(
     32    ["#i1", ".simple-animation"],
     33    inspector
     34  );
     35  const nodeInFrame2 = await getNodeFrontInFrames(
     36    ["#i2", ".simple-animation"],
     37    inspector
     38  );
     39 
     40  info("Pause all animations in the test document");
     41  await toggleAndCheckStates(nodeInFrame1, "paused");
     42  await toggleAndCheckStates(nodeInFrame2, "paused");
     43 
     44  info("Play all animations in the test document");
     45  await toggleAndCheckStates(nodeInFrame1, "running");
     46  await toggleAndCheckStates(nodeInFrame2, "running");
     47 
     48  await target.destroy();
     49  gBrowser.removeCurrentTab();
     50 });
     51 
     52 async function toggleAndCheckStates(nodeFront, playState) {
     53  const animations = await nodeFront.targetFront.getFront("animations");
     54  const [player] = await animations.getAnimationPlayersForNode(nodeFront);
     55 
     56  if (playState === "paused") {
     57    await animations.pauseSome([player]);
     58  } else {
     59    await animations.playSome([player]);
     60  }
     61 
     62  info("Getting the AnimationPlayerFront for the test node");
     63  await player.ready;
     64  const state = await player.getCurrentState();
     65  is(
     66    state.playState,
     67    playState,
     68    "The playState of the test node is " + playState
     69  );
     70 }