https://github.com/web-platform-tests/wpt
Raw File
Tip revision: ab5780956dda798c97707e05fd2e58df7963b6d0 authored by Harald Alvestrand on 05 October 2018, 09:29:42 UTC
Revert "Implement DTMF [[ToneBuffer]] in the blink layer"
Tip revision: ab57809
block-string-assignment-to-Element-insertAdjacentHTML.tentative.html
<!DOCTYPE html>
<html>
<head>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="support/helper.sub.js"></script>

  <meta http-equiv="Content-Security-Policy" content="trusted-types *">
</head>
<body>
<div id="container"></div>
<script>
  var container = document.querySelector('#container');

  // Trusted HTML assignments do not throw.
  test(t => {
    let p = createHTML_policy(window, 1);
    let html = p.createHTML(INPUTS.HTML);

    var d = document.createElement('div');
    container.appendChild(d);

    d.insertAdjacentHTML('beforebegin', html);
    assert_equals(d.previousSibling.nodeType, Node.TEXT_NODE);
    assert_equals(d.previousSibling.data, RESULTS.HTML);

    d.insertAdjacentHTML('afterbegin', html);
    assert_equals(d.firstChild.nodeType, Node.TEXT_NODE);
    assert_equals(d.firstChild.data, RESULTS.HTML);

    d.insertAdjacentHTML('beforeend', html);
    assert_equals(d.lastChild.nodeType, Node.TEXT_NODE);
    assert_equals(d.lastChild.data, RESULTS.HTML);

    d.insertAdjacentHTML('afterend', html);
    assert_equals(d.nextSibling.nodeType, Node.TEXT_NODE);
    assert_equals(d.nextSibling.data, RESULTS.HTML);

    while (container.firstChild)
      container.firstChild.remove();
  }, "insertAdjacentHTML with html assigned via policy (successful HTML transformation).");

  // String assignments throw.
  test(t => {
    var d = document.createElement('div');
    container.appendChild(d);

    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('beforebegin', "<p>Fail</p>");
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('afterbegin', "<p>Fail</p>");
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('beforeend', "<p>Fail</p>");
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('afterend', "<p>Fail</p>");
    });

    assert_equals(d.previousSibling, null);
    assert_equals(d.firstChild, null);
    assert_equals(d.lastChild, null);
    assert_equals(d.nextSibling, null);

    while (container.firstChild)
      container.firstChild.remove();
  }, "`insertAdjacentHTML(string)` throws.");

  // Null assignment throws.
  test(t => {
    var d = document.createElement('div');
    container.appendChild(d);

    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('beforebegin', null);
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('afterbegin', null);
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('beforeend', null);
    });
    assert_throws(new TypeError(), _ => {
      d.insertAdjacentHTML('afterend', null);
    });

    assert_equals(d.previousSibling, null);
    assert_equals(d.firstChild, null);
    assert_equals(d.lastChild, null);
    assert_equals(d.nextSibling, null);
  }, "`insertAdjacentHTML(null)` throws.");
</script>
</body>
</html>
back to top