https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 8409a38ef8d57d6fdad447adef206f17d1ecf9fb authored by James Graham on 14 August 2018, 18:17:53 UTC
WIP
Tip revision: 8409a38
block-string-assignment-to-HTMLLinkElement-href.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="require-trusted-types">
</head>
<body>
<script>
  //helper function for the tests
  function testHref(str, url) {
    var link = document.createElement('link');
    link.href = url;
    assert_equals(link.href, str);
  }

  //URL assignments do not throw.
  test(t => {
    testHref(URLS.safe, TrustedURL.create(URLS.safe));
  }, "link.href = URLS.safe, TrustedURL.create");

  test(t => {
    testHref(URLS.safe, TrustedURL.unsafelyCreate(URLS.safe));
  }, "link.href = URLS.safe, TrustedURL.unsafelyCreate");

  // String assignments throw.
  test(t => {
    var link = document.createElement('link');
    assert_throws(new TypeError(), _ => {
      link.href = "A string";
    });
  }, "`link.href = string` throws");

  //Null assignment throws.
  test(t => {
    var link = document.createElement('link');
    assert_throws(new TypeError(), _ => {
      link.href = null;
    });
  }, "`link.href = null` throws");
</script>
back to top