tor-browser

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

browser_markup_dragdrop_distance.js (1883B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that nodes don't start dragging before the mouse has moved by at least
      7 // the minimum vertical distance defined in markup-view.js by
      8 // DRAG_DROP_MIN_INITIAL_DISTANCE.
      9 
     10 const TEST_URL = URL_ROOT + "doc_markup_dragdrop.html";
     11 const TEST_NODE = "#test";
     12 
     13 // Keep this in sync with DRAG_DROP_MIN_INITIAL_DISTANCE in markup-view.js
     14 const MIN_DISTANCE = 10;
     15 
     16 add_task(async function () {
     17  const { inspector } = await openInspectorForURL(TEST_URL);
     18 
     19  info("Drag the test node by half of the minimum distance");
     20  await simulateNodeDrag(inspector, TEST_NODE, 0, MIN_DISTANCE / 2);
     21  await checkIsDragging(inspector, TEST_NODE, false);
     22 
     23  info("Drag the test node by exactly the minimum distance");
     24  await simulateNodeDrag(inspector, TEST_NODE, 0, MIN_DISTANCE);
     25  await checkIsDragging(inspector, TEST_NODE, true);
     26  inspector.markup.cancelDragging();
     27 
     28  info("Drag the test node by more than the minimum distance");
     29  await simulateNodeDrag(inspector, TEST_NODE, 0, MIN_DISTANCE * 2);
     30  await checkIsDragging(inspector, TEST_NODE, true);
     31  inspector.markup.cancelDragging();
     32 
     33  info("Drag the test node by minus the minimum distance");
     34  await simulateNodeDrag(inspector, TEST_NODE, 0, MIN_DISTANCE * -1);
     35  await checkIsDragging(inspector, TEST_NODE, true);
     36  inspector.markup.cancelDragging();
     37 });
     38 
     39 async function checkIsDragging(inspector, selector, isDragging) {
     40  const container = await getContainerForSelector(selector, inspector);
     41  if (isDragging) {
     42    ok(container.isDragging, "The container is being dragged");
     43    ok(inspector.markup.isDragging, "And the markup-view knows it");
     44  } else {
     45    ok(!container.isDragging, "The container hasn't been marked as dragging");
     46    ok(!inspector.markup.isDragging, "And the markup-view either");
     47  }
     48 }