summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/trusted-types/Node-multiple-arguments.tentative.html
blob: 64b04656d35ba922c528581975682fbd61b5e5a1 (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
<!DOCTYPE html>
<html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="support/helper.sub.js"></script>
</head>
<body>
<div id="container"></div>
<script>
  'use strict';
  const container = document.querySelector("#container");
  const policy = window.trustedTypes.createPolicy("policy", {
    createScript: t => t,
  });
  function stringify(arg) {
    return "textContent" in Object.getPrototypeOf(arg) ? arg.textContent : arg.toString()
  }

  // This test case mirrors the block-Node-multiple-arguments case except
  // that, because Trusted Types is not enabled, no exceptions should be
  // thrown anywhere.
  const targets = ["div", "script"];
  const all_args = [
    [ policy.createScript("'createScript';") ],
    [ policy.createScript("'createScript #1';"), policy.createScript("'#2;'") ],
    [ "'plain text';" ],
    [ "'plain text #1';", "'plain text #2';" ],
    [ document.createTextNode("'node';") ],
    [ document.createTextNode("'node #1';"),
      document.createTextNode("'node #2';") ],
    [ "'mixed';", document.createTextNode("'node';") ],
    [ "'mixed';", policy.createScript("'script';") ],
    [ document.createTextNode("'node';"),
      policy.createScript("'script';") ],
  ];

  for (const target of targets) {
    for (const args of all_args) {

      for (const setter of [container.replaceWith, container.after, container.before]) {
        test(t => {
          var outer = document.createElement(target);
          container.appendChild(outer);
          var inner = document.createElement("p");
          outer.appendChild(inner);
          setter.apply(inner, args);
          assert_equals(outer.textContent, args.map(stringify).join(""));

        }, `${setter.name}(${args.toString()}) on <${target}> should pass`);
      }

      for (const setter of [container.append, container.prepend]) {
        test(t => {
          let outer = document.createElement(target);
          container.appendChild(outer);
          setter.apply(outer, args);
          assert_equals(outer.textContent, args.map(stringify).join(""));
        }, `${setter.name}(${args.toString()}) on <${target}> should pass`);
      }

    }
  }
</script>
</body>
</html>