tor-browser

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

browser_rules_cycle-angle.js (3615B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test cycling angle units in the rule view.
      7 
      8 const TEST_URI = `
      9  <style type="text/css">
     10    .turn {
     11      filter: hue-rotate(1turn);
     12    }
     13    .deg {
     14      filter: hue-rotate(180deg);
     15    }
     16  </style>
     17  <body><div class=turn>Test turn</div><div class=deg>Test deg</div>cycling angle units in the rule view!</body>
     18 `;
     19 
     20 add_task(async function () {
     21  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
     22  const { inspector, view } = await openRuleView();
     23  await checkAngleCycling(inspector, view);
     24  await checkAngleCyclingPersist(inspector, view);
     25 });
     26 
     27 async function checkAngleCycling(inspector, view) {
     28  await selectNode(".turn", inspector);
     29 
     30  const container = (
     31    await getRuleViewProperty(view, ".turn", "filter", { wait: true })
     32  ).valueSpan;
     33  const valueNode = container.querySelector(".ruleview-angle");
     34  const win = view.styleWindow;
     35 
     36  // turn
     37  is(valueNode.textContent, "1turn", "Angle displayed as a turn value.");
     38 
     39  const tests = [
     40    {
     41      value: "360deg",
     42      comment: "Angle displayed as a degree value.",
     43    },
     44    {
     45      value: `${Math.round(Math.PI * 2 * 10000) / 10000}rad`,
     46      comment: "Angle displayed as a radian value.",
     47    },
     48    {
     49      value: "400grad",
     50      comment: "Angle displayed as a gradian value.",
     51    },
     52    {
     53      value: "1turn",
     54      comment: "Angle displayed as a turn value again.",
     55    },
     56  ];
     57 
     58  for (const test of tests) {
     59    await checkSwatchShiftClick(container, win, test.value, test.comment);
     60  }
     61 }
     62 
     63 async function checkAngleCyclingPersist(inspector, view) {
     64  await selectNode(".deg", inspector);
     65  let container = (
     66    await getRuleViewProperty(view, ".deg", "filter", { wait: true })
     67  ).valueSpan;
     68  let valueNode = container.querySelector(".ruleview-angle");
     69  const win = view.styleWindow;
     70 
     71  is(valueNode.textContent, "180deg", "Angle displayed as a degree value.");
     72 
     73  await checkSwatchShiftClick(
     74    container,
     75    win,
     76    `${Math.round(Math.PI * 10000) / 10000}rad`,
     77    "Angle displayed as a radian value."
     78  );
     79 
     80  // Select the .turn div and reselect the .deg div to see
     81  // if the new angle unit persisted
     82  await selectNode(".turn", inspector);
     83  await selectNode(".deg", inspector);
     84 
     85  // We have to query for the container and the swatch because
     86  // they've been re-generated
     87  container = (
     88    await getRuleViewProperty(view, ".deg", "filter", { wait: true })
     89  ).valueSpan;
     90  valueNode = container.querySelector(".ruleview-angle");
     91  is(
     92    valueNode.textContent,
     93    `${Math.round(Math.PI * 10000) / 10000}rad`,
     94    "Angle still displayed as a radian value."
     95  );
     96 }
     97 
     98 async function checkSwatchShiftClick(container, win, expectedValue, comment) {
     99  // Wait for 500ms before attempting a click to workaround frequent
    100  // intermittents.
    101  //
    102  // See intermittent bug at https://bugzilla.mozilla.org/show_bug.cgi?id=1721938
    103  // See potentially related bugs:
    104  // - browserLoaded + synthesizeMouse timeouts https://bugzilla.mozilla.org/show_bug.cgi?id=1727749
    105  // - mochitest general synthesize events issue https://bugzilla.mozilla.org/show_bug.cgi?id=1720248
    106  await wait(500);
    107 
    108  const swatch = container.querySelector(".inspector-angleswatch");
    109  const valueNode = container.querySelector(".ruleview-angle");
    110 
    111  const onUnitChange = once(swatch, "unit-change");
    112  EventUtils.synthesizeMouseAtCenter(
    113    swatch,
    114    {
    115      type: "mousedown",
    116      shiftKey: true,
    117    },
    118    win
    119  );
    120  await onUnitChange;
    121  is(valueNode.textContent, expectedValue, comment);
    122 }