tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

css-images.sub.html (4814B)


      1 <!DOCTYPE html>
      2 <!--
      3 [%provenance%]
      4 -->
      5 <html lang="en">
      6  <meta charset="utf-8">
      7  {%- if subtests|length > 10 %}
      8  <meta name="timeout" content="long">
      9  {%- endif %}
     10  <title>HTTP headers on request for CSS image-accepting properties</title>
     11  <script src="/resources/testharness.js"></script>
     12  <script src="/resources/testharnessreport.js"></script>
     13  <script src="/fetch/metadata/resources/helper.sub.js"></script>
     14  <body>
     15  <script>
     16  'use strict';
     17 
     18  /**
     19   * The subtests in this file use an iframe to induce requests for CSS
     20   * resources because an iframe's `onload` event is the most direct and
     21   * generic mechanism to detect loading of CSS resources. As an optimization,
     22   * the subtests share the same iframe and document.
     23   */
     24  const declarations = [];
     25  const iframe = document.createElement('iframe');
     26  const whenIframeReady = new Promise((resolve, reject) => {
     27    iframe.onload = resolve;
     28    iframe.onerror = reject;
     29  });
     30 
     31  {%- for subtest in subtests %}
     32 
     33  async_test((t) => {
     34    const key = '{{uuid()}}';
     35    const url = makeRequestURL(key, [% subtest.origins %]);
     36 
     37    declarations.push(`background-image: url("${url}");`);
     38 
     39    whenIframeReady
     40      .then(() => retrieve(key))
     41      .then((headers) => {
     42        {%- if subtest.expected == none %}
     43          assert_not_own_property(headers, '[%subtest.headerName%]');
     44        {%- else %}
     45          assert_own_property(headers, '[%subtest.headerName%]');
     46          assert_equals(headers['[%subtest.headerName%]'], '[%subtest.expected%]');
     47        {%- endif %}
     48        })
     49        .then(t.step_func_done(), (error) => t.unreached_func());
     50  }, 'background-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
     51 
     52  async_test((t) => {
     53    const key = '{{uuid()}}';
     54    const url = makeRequestURL(key, [% subtest.origins %]);
     55 
     56    declarations.push(`border-image: url("${url}");`);
     57 
     58    whenIframeReady
     59      .then(() => retrieve(key))
     60      .then((headers) => {
     61        {%- if subtest.expected == none %}
     62          assert_not_own_property(headers, '[%subtest.headerName%]');
     63        {%- else %}
     64          assert_own_property(headers, '[%subtest.headerName%]');
     65          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     66        {%- endif %}
     67        })
     68      .then(t.step_func_done(), t.unreached_func());
     69  }, 'border-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
     70 
     71  async_test((t) => {
     72    const key = '{{uuid()}}';
     73    const url = makeRequestURL(key, [% subtest.origins %]);
     74 
     75    declarations.push(`content: url("${url}");`);
     76 
     77    whenIframeReady
     78      .then(() => retrieve(key))
     79      .then((headers) => {
     80        {%- if subtest.expected == none %}
     81          assert_not_own_property(headers, '[%subtest.headerName%]');
     82        {%- else %}
     83          assert_own_property(headers, '[%subtest.headerName%]');
     84          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
     85        {%- endif %}
     86        })
     87      .then(t.step_func_done(), t.unreached_func());
     88  }, 'content [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
     89 
     90  async_test((t) => {
     91    const key = '{{uuid()}}';
     92    const url = makeRequestURL(key, [% subtest.origins %]);
     93 
     94    declarations.push(`cursor: url("${url}"), auto;`);
     95 
     96    whenIframeReady
     97      .then(() => retrieve(key))
     98      .then((headers) => {
     99        {%- if subtest.expected == none %}
    100          assert_not_own_property(headers, '[%subtest.headerName%]');
    101        {%- else %}
    102          assert_own_property(headers, '[%subtest.headerName%]');
    103          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
    104        {%- endif %}
    105        })
    106      .then(t.step_func_done(), t.unreached_func());
    107  }, 'cursor [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
    108 
    109  async_test((t) => {
    110    const key = '{{uuid()}}';
    111    const url = makeRequestURL(key, [% subtest.origins %]);
    112 
    113    declarations.push(`list-style-image: url("${url}");`);
    114 
    115    whenIframeReady
    116      .then(() => retrieve(key))
    117      .then((headers) => {
    118        {%- if subtest.expected == none %}
    119          assert_not_own_property(headers, '[%subtest.headerName%]');
    120        {%- else %}
    121          assert_own_property(headers, '[%subtest.headerName%]');
    122          assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']);
    123        {%- endif %}
    124        })
    125      .then(t.step_func_done(), t.unreached_func());
    126  }, 'list-style-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
    127 
    128  {%- endfor %}
    129 
    130  iframe.srcdoc = declarations.map((declaration, index) => `
    131    <style>.el${index} { ${declaration} }</style><div class="el${index}"></div>`
    132    ).join('');
    133  document.body.appendChild(iframe);
    134 
    135  </script>
    136  </body>
    137 </html>