testing/web-platform/tests/trusted-types/Node-multiple-arguments.tentative.https.html
author Mike West <mkwst@chromium.org>
Mon, 09 Mar 2020 21:45:23 +0000
changeset 518170 2e776909647f66798268ab95ae758ffc11374eaf
parent 499174 testing/web-platform/tests/trusted-types/Node-multiple-arguments.tentative.html@bd827ed61b7b932e2c31c6e4c03fa186b199594f
permissions -rw-r--r--
Bug 1620783 [wpt PR 22131] - [TrustedTypes] Lock the API to secure contexts., a=testonly Automatic update from web-platform-tests [TrustedTypes] Lock the API to secure contexts. This addresses only the IDL changes. We'll need to decide how the CSP integration ought to work (e.g. whether `require-sri-for` has any impact on non-secure pages) in the next CL. Bug: 1059554 Change-Id: Ie67a3cc1dbaac1e52e2d63bed45b43eb2ffa020b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093214 Commit-Queue: Mike West <mkwst@chromium.org> Reviewed-by: Yifan Luo <lyf@chromium.org> Cr-Commit-Position: refs/heads/master@{#748064} -- wpt-commits: a0e6371ffdbe6666278bc6c00160c34326c14790 wpt-pr: 22131

<!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>
  const container = document.querySelector("#container");
  const policy = window.trustedTypes.createPolicy("policy", {
    createScript: t => t,
  });
  function stringify(arg) {
    return "textContent" in arg.__proto__ ? 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 anyhwere.
  const targets = ["div", "script"];
  const all_args = [
    [ policy.createScript("'createScript';") ],
    [ policy.createScript("'cresteScript #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 (target of targets) {
    for (args of all_args) {

      for (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 (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>