testing/web-platform/tests/trusted-types/Node-multiple-arguments.tentative.html
author Tom Schuster <evilpies@gmail.com>
Sun, 14 Jun 2020 18:59:08 +0000
changeset 535622 c68fe15a81fc2dc9fc5765f3be2573519c09b6c1
parent 531924 e07cf3d4936f99965d8d52afab0560b7cbfd7975
child 563289 76eee5d27dc9cd9ddf869cebd3a8c5bd1854a3d5
permissions -rw-r--r--
Bug 1644878 - Don't define Map/Set identical iterator methods in self-hosted JS. r=arai I think we were defining those methods in self-hosted JS, because that automatically gives us the property that they all have the same identity. This causes bad error messages. Instead redefine them in the finishInit ClassSpec hook. We still have the "wrong" methods in the 'methods' array so that JSXray tests continue to pass. Differential Revision: https://phabricator.services.mozilla.com/D79615

<!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>