tor-browser

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

use-load-error-events.tentative.html (4698B)


      1 <!doctype html>
      2 <title>'load' and 'error' events for SVG &lt;use></title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/rendering-utils.js"></script>
      6 <svg>
      7  <defs>
      8    <rect id="local" width="100" height="100" fill="blue"/>
      9  </defs>
     10 </svg>
     11 <script>
     12  function newUseElement() {
     13    return document.createElementNS('http://www.w3.org/2000/svg', 'use');
     14  }
     15  function makeWatcher(root, eventType, url) {
     16    return new Promise(resolve => {
     17      const watcher = newUseElement();
     18      watcher.addEventListener(eventType, resolve);
     19      watcher.setAttribute('href', url);
     20      root.appendChild(watcher);
     21    });
     22  }
     23  function expectEvents(t, element, event) {
     24    return new EventWatcher(t, element, ['load', 'error']).wait_for(event);
     25  }
     26  const DATA_URL_PAYLOAD =
     27      '<svg xmlns="http://www.w3.org/2000/svg"><rect id="green" fill="lime" width="100" height="50"/></svg>';
     28  const cookie = Date.now();
     29  let counter = 0;
     30  function makeCookie(index) {
     31    return `${cookie}-${index}`;
     32  }
     33  function getUrl(type) {
     34    const cookie = makeCookie(counter++);
     35    switch (type) {
     36    case 'existing':
     37      return `/images/colors.svg?${cookie}#green`;
     38    case 'existing-data':
     39      return `data:image/svg+xml,${DATA_URL_PAYLOAD}#green`;
     40    case 'non-existing':
     41      return `/images/this-file-should-not-exist.svg?${cookie}#green`;
     42    case 'broken':
     43      return `/images/fail.gif?${cookie}#green`;
     44    }
     45  }
     46 
     47  promise_test(t => {
     48    const svg = document.querySelector('svg');
     49    const use = newUseElement();
     50    expectEvents(t, use, []);
     51    svg.appendChild(use).setAttribute('href', '#local');
     52    return waitForAtLeastOneFrame();
     53  }, document.title + ', local reference, existing');
     54 
     55  promise_test(t => {
     56    const svg = document.querySelector('svg');
     57    const use = newUseElement();
     58    expectEvents(t, use, []);
     59    svg.appendChild(use).setAttribute('href', '#local_not_there');
     60    return waitForAtLeastOneFrame();
     61  }, document.title + ', local reference, non-existing');
     62 
     63  promise_test(t => {
     64    const svg = document.querySelector('svg');
     65    const use = newUseElement();
     66    const watcher = expectEvents(t, use, ['load']);
     67    const url = getUrl('existing');
     68    svg.appendChild(use).setAttribute('href', url);
     69    return watcher;
     70  }, document.title + ', external reference, existing');
     71 
     72  promise_test(t => {
     73    const svg = document.querySelector('svg');
     74    const use = newUseElement();
     75    const watcher = expectEvents(t, use, ['error']);
     76    const url = getUrl('existing-data');
     77    svg.appendChild(use).setAttribute('href', url);
     78    return watcher;
     79  }, document.title + ', external data: URL reference, existing');
     80 
     81  promise_test(t => {
     82    const svg = document.querySelector('svg');
     83    const use = newUseElement();
     84    const watcher = expectEvents(t, use, ['error']);
     85    const url = getUrl('non-existing');
     86    svg.appendChild(use).setAttribute('href', url);
     87    return watcher;
     88  }, document.title + ', external reference, non-existing');
     89 
     90  promise_test(t => {
     91    const svg = document.querySelector('svg');
     92    const use = newUseElement();
     93    const watcher = expectEvents(t, use, ['error']);
     94    const url = getUrl('broken');
     95    svg.appendChild(use).setAttribute('href', url);
     96    return watcher;
     97  }, document.title + ', external reference, existing, parse error');
     98 
     99  promise_test(t => {
    100    const svg = document.querySelector('svg');
    101    const use = newUseElement();
    102    expectEvents(t, use, []);
    103    const url = getUrl('existing');
    104    svg.appendChild(use).setAttribute('href', url);
    105    t.step_timeout(() => use.setAttribute('href', '#local'));
    106    return makeWatcher(svg, 'load', url);
    107  }, document.title + ', external reference, existing, changed to local reference while loading');
    108 
    109  promise_test(t => {
    110    const svg = document.querySelector('svg');
    111    const use = newUseElement();
    112    expectEvents(t, use, []);
    113    const url = getUrl('existing-data');
    114    svg.appendChild(use).setAttribute('href', url);
    115    t.step_timeout(() => use.setAttribute('href', '#local'));
    116    return makeWatcher(svg, 'error', url);
    117  }, document.title + ', external data: URL reference, existing, changed to local reference while loading');
    118 
    119  promise_test(t => {
    120    const svg = document.querySelector('svg');
    121    const use = newUseElement();
    122    expectEvents(t, use, []);
    123    const url = getUrl('non-existing');
    124    svg.appendChild(use).setAttribute('href', url);
    125    t.step_timeout(() => use.setAttribute('href', '#local'));
    126    return makeWatcher(svg, 'error', url);
    127  }, document.title + ', external reference, non-existing, changed to local reference while loading');
    128 </script>