tor-browser

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

browser_animation_logic_avoid-updating-during-hiding.js (3116B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Animation inspector should not update when hidden.
      7 // Test for followings:
      8 // * whether the UIs update after selecting another inspector
      9 // * whether the UIs update after selecting another tool
     10 // * whether the UIs update after selecting animation inspector again
     11 
     12 add_task(async function () {
     13  info(
     14    "Switch to 2 pane inspector to see if the animation only refreshes when visible"
     15  );
     16  await pushPref("devtools.inspector.three-pane-enabled", false);
     17  await addTab(URL_ROOT + "doc_custom_playback_rate.html");
     18  const { animationInspector, inspector, panel } =
     19    await openAnimationInspector();
     20 
     21  info("Checking the UIs update after selecting another inspector");
     22  await selectNode("head", inspector);
     23  inspector.sidebar.select("ruleview");
     24  await selectNode("div", inspector);
     25  await waitUntil(() => !animationInspector.state.animations.length);
     26  ok(true, "Should not update after selecting another inspector");
     27 
     28  await selectAnimationInspector(inspector);
     29  await waitUntil(() => animationInspector.state.animations.length);
     30  ok(true, "Should update after selecting animation inspector");
     31 
     32  await assertCurrentTimeUpdated(animationInspector, panel, true);
     33  inspector.sidebar.select("ruleview");
     34  is(
     35    animationInspector.state.animations.length,
     36    1,
     37    "Should not update after selecting another inspector again"
     38  );
     39  await assertCurrentTimeUpdated(animationInspector, panel, false);
     40 
     41  info("Checking the UIs update after selecting another tool");
     42  await selectAnimationInspector(inspector);
     43  await selectNode("head", inspector);
     44  await waitUntil(() => !animationInspector.state.animations.length);
     45  await inspector.toolbox.selectTool("webconsole");
     46  await selectNode("div", inspector);
     47  is(
     48    animationInspector.state.animations.length,
     49    0,
     50    "Should not update after selecting another tool"
     51  );
     52  await selectAnimationInspector(inspector);
     53  await waitUntil(() => animationInspector.state.animations.length);
     54  is(
     55    animationInspector.state.animations.length,
     56    1,
     57    "Should update after selecting animation inspector"
     58  );
     59  await assertCurrentTimeUpdated(animationInspector, panel, true);
     60  await inspector.toolbox.selectTool("webconsole");
     61  await waitUntil(() => animationInspector.state.animations.length);
     62  is(
     63    animationInspector.state.animations.length,
     64    1,
     65    "Should not update after selecting another tool again"
     66  );
     67  await assertCurrentTimeUpdated(animationInspector, panel, false);
     68 });
     69 
     70 async function assertCurrentTimeUpdated(
     71  animationInspector,
     72  panel,
     73  shouldRunning
     74 ) {
     75  let count = 0;
     76 
     77  const listener = () => {
     78    count++;
     79  };
     80 
     81  animationInspector.addAnimationsCurrentTimeListener(listener);
     82  await new Promise(resolve =>
     83    panel.ownerGlobal.requestAnimationFrame(resolve)
     84  );
     85  animationInspector.removeAnimationsCurrentTimeListener(listener);
     86 
     87  if (shouldRunning) {
     88    isnot(count, 0, "Should forward current time");
     89  } else {
     90    is(count, 0, "Should not forward current time");
     91  }
     92 }