summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_template.js
blob: 8516d59346a10df6e1c40e71cbb276864f37e68e (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test the markup view displaying the content of a <template> tag.

add_task(async function () {
  const TEST_URL =
    `data:text/html;charset=utf-8,` +
    encodeURIComponent(`
    <div id="root">
      <template>
        <p>template content</p>
      </template>

      <div id="template-container" style="border: 1px solid black"></div>
    </div>
    <script>
      "use strict";

      const template = document.querySelector("template");
      const clone = document.importNode(template.content, true);
      document.querySelector("#template-container").appendChild(clone);
    </script>`);

  const EXPECTED_TREE = `
    root
      template
        #document-fragment
          p
      template-container
        p`;

  const { inspector } = await openInspectorForURL(TEST_URL);
  const { markup } = inspector;

  await assertMarkupViewAsTree(EXPECTED_TREE, "#root", inspector);

  info("Select the p element under the template .");
  const templateFront = await getNodeFront("template", inspector);
  const templateContainer = markup.getContainer(templateFront);
  const documentFragmentContainer = templateContainer.getChildContainers()[0];
  const pContainer = documentFragmentContainer.getChildContainers()[0];

  await selectNode(pContainer.node, inspector, "no-reason", false);

  const ruleView = inspector.getPanel("ruleview").view;
  // We only display the style attribute.
  is(
    ruleView.element.querySelectorAll(".ruleview-rule").length,
    1,
    "No rules are displayed for this p element"
  );
});