tor-browser

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

browser_widget_animation.js (2498B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 gReduceMotionOverride = false;
      7 
      8 function promiseWidgetAnimationOut(aNode) {
      9  let animationNode = aNode;
     10  if (
     11    animationNode.tagName != "toolbaritem" &&
     12    animationNode.tagName != "toolbarbutton"
     13  ) {
     14    animationNode = animationNode.closest("toolbaritem");
     15  }
     16  if (animationNode.parentNode.id.startsWith("wrapper-")) {
     17    animationNode = animationNode.parentNode;
     18  }
     19  return new Promise(resolve => {
     20    animationNode.addEventListener(
     21      "animationend",
     22      function cleanupWidgetAnimationOut(e) {
     23        if (
     24          e.animationName == "widget-animate-out" &&
     25          e.target.id == animationNode.id
     26        ) {
     27          animationNode.removeEventListener(
     28            "animationend",
     29            cleanupWidgetAnimationOut
     30          );
     31          ok(true, "The widget`s animationend should have happened");
     32          resolve();
     33        }
     34      }
     35    );
     36  });
     37 }
     38 
     39 function promiseOverflowAnimationEnd() {
     40  return new Promise(resolve => {
     41    let overflowButton = document.getElementById("nav-bar-overflow-button");
     42    overflowButton.addEventListener(
     43      "animationend",
     44      function cleanupOverflowAnimationOut(event) {
     45        if (event.animationName == "overflow-animation") {
     46          overflowButton.removeEventListener(
     47            "animationend",
     48            cleanupOverflowAnimationOut
     49          );
     50          ok(
     51            true,
     52            "The overflow button`s animationend event should have happened"
     53          );
     54          resolve();
     55        }
     56      }
     57    );
     58  });
     59 }
     60 
     61 // Right-click on the stop/reload button, use the context menu to move it to the overflow menu.
     62 // The button should animate out, and the overflow menu should animate upon adding.
     63 add_task(async function () {
     64  let stopReloadButton = document.getElementById("stop-reload-button");
     65  let contextMenu = document.getElementById("toolbar-context-menu");
     66  let shownPromise = popupShown(contextMenu);
     67  EventUtils.synthesizeMouseAtCenter(stopReloadButton, {
     68    type: "contextmenu",
     69    button: 2,
     70  });
     71  await shownPromise;
     72 
     73  contextMenu.activateItem(
     74    contextMenu.querySelector(".customize-context-moveToPanel")
     75  );
     76 
     77  await Promise.all([
     78    promiseWidgetAnimationOut(stopReloadButton),
     79    promiseOverflowAnimationEnd(),
     80  ]);
     81  ok(true, "The widget and overflow animations should have both happened.");
     82 });
     83 
     84 registerCleanupFunction(CustomizableUI.reset);