tor-browser

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

browser_markup_dragdrop_draggable.js (2141B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test which nodes are consider draggable by the markup-view.
      6 
      7 const TEST_URL = URL_ROOT + "doc_markup_dragdrop.html";
      8 
      9 // Test cases should be objects with the following properties:
     10 // - node {String|Function} A CSS selector that uniquely identifies the node to
     11 //   be tested. Or a generator function called in a Task that should return the
     12 //   corresponding MarkupContainer object to be tested.
     13 // - draggable {Boolean} Whether or not the node should be draggable.
     14 const TEST_DATA = [
     15  { node: "head", draggable: false },
     16  { node: "body", draggable: false },
     17  { node: "html", draggable: false },
     18  { node: "style", draggable: true },
     19  { node: "a", draggable: true },
     20  { node: "p", draggable: true },
     21  { node: "input", draggable: true },
     22  { node: "div", draggable: true },
     23  {
     24    async node(inspector) {
     25      const parentFront = await getNodeFront("#before", inspector);
     26      const { nodes } = await inspector.walker.children(parentFront);
     27      // Getting the comment node.
     28      return getContainerForNodeFront(nodes[1], inspector);
     29    },
     30    draggable: true,
     31  },
     32  {
     33    async node(inspector) {
     34      const parentFront = await getNodeFront("#test", inspector);
     35      const { nodes } = await inspector.walker.children(parentFront);
     36      // Getting the ::before pseudo element.
     37      return getContainerForNodeFront(nodes[0], inspector);
     38    },
     39    draggable: false,
     40  },
     41 ];
     42 
     43 add_task(async function () {
     44  const { inspector } = await openInspectorForURL(TEST_URL);
     45  await inspector.markup.expandAll();
     46 
     47  for (const { node, draggable } of TEST_DATA) {
     48    let container;
     49    let name;
     50    if (typeof node === "string") {
     51      container = await getContainerForSelector(node, inspector);
     52      name = node;
     53    } else {
     54      container = await node(inspector);
     55      name = container.toString();
     56    }
     57 
     58    const status = draggable ? "draggable" : "not draggable";
     59    info(`Testing ${name}, expecting it to be ${status}`);
     60    is(container.isDraggable(), draggable, `The node is ${status}`);
     61  }
     62 });