chromium/third_party/blink/web_tests/external/wpt/fetch/metadata/tools/templates/svg-image.sub.html

<!DOCTYPE html>
<!--
[%provenance%]
-->
<html lang="en">
  <meta charset="utf-8">
  {%- if subtests|length > 10 %}
  <meta name="timeout" content="long">
  {%- endif %}
  <title>HTTP headers on request for SVG "image" element source</title>
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
  <script src="/fetch/metadata/resources/helper.sub.js"></script>
  <body>
  <script>
  'use strict';

  const params = {
    body: `
      <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
        <rect fill="lime" width="123" height="123"/>
      </svg>
    `,
    mime: 'image/svg+xml'
  };

  function induceRequest(t, url, attributes) {
    const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
    svg.setAttributeNS(
      "http://www.w3.org/2000/xmlns/",
      "xmlns:xlink",
      "http://www.w3.org/1999/xlink"
    );
    const image = document.createElementNS("http://www.w3.org/2000/svg", "image");
    image.setAttribute("href", url);
    svg.appendChild(image);

    for (const [ name, value ] of Object.entries(attributes)) {
      image.setAttribute(name, value);
    }

    document.body.appendChild(svg);
    t.add_cleanup(() => svg.remove());

    return new Promise((resolve, reject) => {
      image.onload = resolve;
      image.onerror = reject;
    });
  }

  {%- for subtest in subtests %}

  promise_test((t) => {
    const key = '{{uuid()}}';

    return induceRequest(
        t,
        makeRequestURL(key, [% subtest.origins %], params),
        [%subtest.elementAttrs | default({}) | tojson%]
      )
      .then(() => retrieve(key))
      .then((headers) => {
        {%- if subtest.expected == none %}
          assert_not_own_property(headers, '[%subtest.headerName%]');
        {%- else %}
          assert_own_property(headers, '[%subtest.headerName%]');
          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
        {%- endif %}
      });
  }, '[%subtest.headerName%][%subtest.description | pad("start", " - ")%] [%subtest.elementAttrs | collection("attributes")%]');

  {%- endfor %}
  </script>
  </body>
</html>