tor-browser

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

helper_drag_click.html (2223B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <meta name="viewport" content="width=device-width; initial-scale=1.0">
      6  <title>Sanity mouse-drag click test</title>
      7  <script type="application/javascript" src="apz_test_native_event_utils.js"></script>
      8  <script type="application/javascript" src="apz_test_utils.js"></script>
      9  <script src="/tests/SimpleTest/paint_listener.js"></script>
     10  <script type="application/javascript">
     11 
     12 async function test() {
     13  let clickPromise = new Promise(resolve => {
     14    document.addEventListener("click", resolve);
     15  });
     16 
     17  // Ensure the pointer is inside the window
     18  await promiseNativeMouseEventWithAPZ({
     19    target: document.getElementById("b"),
     20    offsetX: 5,
     21    offsetY: 5,
     22    type: "mousemove",
     23  });
     24  // mouse down, move it around, and release it near where it went down. this
     25  // should generate a click at the release point
     26  await promiseNativeMouseEventWithAPZ({
     27    target: document.getElementById("b"),
     28    offsetX: 5,
     29    offsetY: 5,
     30    type: "mousedown",
     31  });
     32  await promiseNativeMouseEventWithAPZ({
     33    target: document.getElementById("b"),
     34    offsetX: 100,
     35    offsetY: 100,
     36    type: "mousemove",
     37  });
     38  await promiseNativeMouseEventWithAPZ({
     39    target: document.getElementById("b"),
     40    offsetX: 10,
     41    offsetY: 10,
     42    type: "mousemove",
     43  });
     44  await promiseNativeMouseEventWithAPZ({
     45    target: document.getElementById("b"),
     46    offsetX: 8,
     47    offsetY: 8,
     48    type: "mouseup",
     49  });
     50  dump("Finished synthesizing click with a drag in the middle\n");
     51 
     52  let e = await clickPromise;
     53  // The mouse down at (5, 5) should not have generated a click, but the up
     54  // at (8, 8) should have.
     55  is(e.target, document.getElementById("b"), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
     56  is(e.clientX, 8 + Math.floor(document.getElementById("b").getBoundingClientRect().left), "x-coord of click event looks sane");
     57  is(e.clientY, 8 + Math.floor(document.getElementById("b").getBoundingClientRect().top), "y-coord of click event looks sane");
     58 }
     59 
     60 waitUntilApzStable()
     61 .then(test)
     62 .then(subtestDone, subtestFailed);
     63 
     64  </script>
     65 </head>
     66 <body>
     67 <button id="b" style="width: 10px; height: 10px; padding: 0;"></button>
     68 </body>
     69 </html>