Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
            
- /trusted-types/Node-multiple-arguments.html - WPT Dashboard Interop Dashboard
 
 
<!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>