https://github.com/web-platform-tests/wpt
Raw File
Tip revision: e7517084404fca126c4f89eb69217206689adf17 authored by jgraham on 20 December 2018, 17:24:15 UTC
Update range-percent-intrinsic-size-1.html
Tip revision: e751708
block-string-assignment-to-Location-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="trusted-types *">
</head>
<body>
<script>
  // TrustedURL assignments do not throw.
  test(t => {
    let p = createURL_policy(window, 1);
    let url = p.createURL(location.href + "#xxx");
    location.href = url;
    assert_equals("" + url, location.href, "location href");
  }, "location.href assigned via policy (successful URL transformation).");

  // String assignments throw.
  test(t => {
    let href = location.href;
    assert_throws(new TypeError(), _ => {
      location.href = 'A string';
    });
    assert_equals(location.href, href);
  }, "`location.href = string` throws");

  // Null assignment throws.
  test(t => {
    let href = location.href;
    assert_throws(new TypeError(), _ => {
      location.href = null;
    });
    assert_equals(location.href, href);
  }, "`location.href = null` throws");

  // Create default policy. Applies to all subsequent tests.
  let p = window.TrustedTypes.createPolicy("default",
      { createURL: createLocationURLJS }, true);

  // After default policy creation string assignment implicitly calls createURL.
  test(t => {
    location.href = "xxxx";
    assert_true(location.href.endsWith("#xxxx"));
  }, "`location.href = string` via default policy (successful URL transformation).");

  // After default policy creation null assignment implicitly calls createURL.
  test(t => {
    location.href = null;
    assert_true(location.href.endsWith("#null"));
  }, "`location.href = null` assigned via default policy does not throw.");
</script>
back to top