summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/dom/parts/dom-parts-valid-node-types.tentative.html
blob: f9ed167e605ad1e2b6b1d198d1ce44906765604c (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
<!DOCTYPE html>
<title>DOM Parts: Valid node types for constructors</title>
<meta name="author" href="mailto:masonf@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/domparts-utils.js"></script>

<body>
<template foo></template>
<script>
  const root = document.getPartRoot();
  const xml = new DOMParser().parseFromString("<xml></xml>", "application/xml");
  const cdata = xml.createCDATASection('cdata');
  document.body.appendChild(cdata);
  const pi = document.createProcessingInstruction('processing','instruction');
  document.body.appendChild(pi);
  const invalidNodes = {
    document: document.documentElement,
    documentType: document.doctype,
    attributeNode: document.querySelector('[foo]').attributes[0],
    cdataSection: cdata,
    processingInstruction: pi,
    documentFragment: document.querySelector('[foo]').content,
  };

  const types = Object.keys(invalidNodes);
  for(let i=0;i<types.length;++i) {
    const type = types[i];
    const obj = invalidNodes[types[i]];
    const otherObj = invalidNodes[types[(i+1) % types.length]];
    test((t) => {
      assert_throws_dom("INVALID_NODE_TYPE_ERR", () => {
        new NodePart(root, obj, {});
      });
      assert_throws_dom("INVALID_NODE_TYPE_ERR", () => {
        new ChildNodePart(root, obj, otherObj, {});
      });
      assert_throws_dom("INVALID_NODE_TYPE_ERR", () => {
        new ChildNodePart(root, otherObj, obj, {});
      });
    },`Invalid node types (${type})`);
  }

  test((t) => {
    try {
      const cnp = new ChildNodePart(root, invalidNodes.documentType, invalidNodes.document, {});
      cnp.clone();
    } catch {};
    try {
      const np = new NodePart(root, invalidNodes.documentType, {});
      np.clone();
    } catch {};
    // This test passes if it does not crash.
  },'Crash test');
</script>