tor-browser

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

browser_eyedropper.js (2130B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that the eyedropper follows the mouse in RDM. See Bug 1932143.
      6 
      7 const TEST_URL =
      8  "data:text/html;charset=utf-8,<meta name='viewport' content='width=device-width' /><iframe></iframe>";
      9 
     10 addRDMTask(TEST_URL, async function ({ ui }) {
     11  info(
     12    "Test that the eyedropper follows the mouse in RDM without touch simulation"
     13  );
     14 
     15  const { inspector, highlighterTestFront } = await openInspector();
     16  await openEyeDropper(inspector, highlighterTestFront);
     17 
     18  await checkEyeDropperFollowsMouse(ui, highlighterTestFront);
     19 });
     20 
     21 addRDMTask(TEST_URL, async function ({ ui }) {
     22  info(
     23    "Test that the eyedropper follows the mouse in RDM with touch simulation"
     24  );
     25 
     26  reloadOnTouchChange(true);
     27  await toggleTouchSimulation(ui);
     28 
     29  const { inspector, highlighterTestFront } = await openInspector();
     30  await openEyeDropper(inspector, highlighterTestFront);
     31 
     32  await checkEyeDropperFollowsMouse(ui, highlighterTestFront);
     33 });
     34 
     35 async function openEyeDropper(inspector, highlighterTestFront) {
     36  info("Opening the eyedropper");
     37  const toggleButton = inspector.panelDoc.querySelector(
     38    "#inspector-eyedropper-toggle"
     39  );
     40  toggleButton.click();
     41  await TestUtils.waitForCondition(() =>
     42    highlighterTestFront.isEyeDropperVisible()
     43  );
     44 }
     45 
     46 async function checkEyeDropperFollowsMouse(ui, highlighterTestFront) {
     47  for (const [x, y] of [
     48    [40, 60],
     49    [100, 80],
     50  ]) {
     51    await moveMouse(ui, x, y);
     52    await checkEyeDropperPosition(highlighterTestFront, x, y);
     53  }
     54 }
     55 
     56 async function moveMouse(ui, x, y) {
     57  info(`Moving mouse to (${x}, ${y})`);
     58  await BrowserTestUtils.synthesizeMouse(
     59    "html",
     60    x,
     61    y,
     62    { type: "mousemove", isSynthesized: false },
     63    ui.getViewportBrowser()
     64  );
     65 }
     66 
     67 async function checkEyeDropperPosition(highlighterTestFront, x, y) {
     68  const style = await highlighterTestFront.getEyeDropperElementAttribute(
     69    "eye-dropper-root",
     70    "style"
     71  );
     72  is(
     73    style,
     74    `top:${y}px;left:${x}px;`,
     75    `Eyedropper is at the expected position (${x}, ${y})`
     76  );
     77 }