summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_dragdrop_before_marker_pseudo.js
blob: 7cca09ce94e16d472129b270d21c424778b8950a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test drag and dropping a node before a ::marker pseudo.

const TEST_URL = URL_ROOT + "doc_markup_dragdrop.html";

add_task(async function () {
  const { inspector } = await openInspectorForURL(TEST_URL);

  info("Expand #list node");
  const parentFront = await getNodeFront("#list", inspector);
  await inspector.markup.expandNode(parentFront.parentNode());
  await inspector.markup.expandNode(parentFront);
  await waitForMultipleChildrenUpdates(inspector);

  info("Scroll #list into view");
  const parentContainer = await getContainerForNodeFront(
    parentFront,
    inspector
  );
  parentContainer.elt.scrollIntoView(true);

  info("Test placing an element before a ::marker psuedo");
  await moveElementBeforeMarker("#last-list-child", parentFront, inspector);
  const childNodes = await getChildrenOf(parentFront, inspector);
  is(
    childNodes[0],
    "_moz_generated_content_marker",
    "::marker is still the first child of #list"
  );
  is(
    childNodes[1],
    "last-list-child",
    "#last-list-child is now the second child of #list"
  );
  is(
    childNodes[2],
    "first-list-child",
    "#first-list-child is now the last child of #list"
  );
});

async function moveElementBeforeMarker(selector, parentFront, inspector) {
  info(`Placing ${selector} before its parent's ::marker`);

  const container = await getContainerForSelector(selector, inspector);
  const parentContainer = await getContainerForNodeFront(
    parentFront,
    inspector
  );
  const offsetY =
    parentContainer.tagLine.offsetTop +
    parentContainer.tagLine.offsetHeight -
    container.tagLine.offsetTop;

  const onMutated = inspector.once("markupmutation");
  const uiUpdate = inspector.once("inspector-updated");

  await simulateNodeDragAndDrop(inspector, selector, 0, offsetY);

  const mutations = await onMutated;
  await uiUpdate;

  is(mutations.length, 2, "2 mutations were received");
}

async function getChildrenOf(parentFront, { walker }) {
  const { nodes } = await walker.children(parentFront);
  return nodes.map(node => {
    if (node.isMarkerPseudoElement) {
      return node.displayName;
    }
    return node.id;
  });
}