https://github.com/web-platform-tests/wpt
Raw File
Tip revision: 948619e9aa2e43a6ca81d3bfc78669a721207523 authored by Philip Jägenstedt on 12 November 2018, 21:22:18 UTC
Find manifest for download by tags instead of commits
Tip revision: 948619e
block-string-assignment-to-Location-assign.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.assign(url);
    assert_equals("" + url, location.href, "location href");
  }, "location.assign via policy (successful URL transformation).");

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

  // Null assignment throws.
  test(t => {
    assert_throws(new TypeError(), _ => {
      location.assign(null);
    });
  }, "`location.assign = 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.assign("abcdefg");
    assert_true(location.href.endsWith("#abcdefg"));
  }, "`location.assign = string` via default policy (successful URL transformation).");

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