tor-browser

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

xlink-href-compat.html (8560B)


      1 <!DOCTYPE html>
      2 <title>XLink 'href' backwards compatibility</title>
      3 <link rel="help" href="https://svgwg.org/svg2-draft/linking.html#XLinkRefAttrs">
      4 <link rel="help" href="https://svgwg.org/svg2-draft/linking.html#linkRefAttrs">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script>
      8 const svgNs = 'http://www.w3.org/2000/svg';
      9 const xlinkNs = 'http://www.w3.org/1999/xlink';
     10 
     11 test(function() {
     12    const element = document.createElementNS(svgNs, 'a');
     13    element.setAttributeNS(null, 'href', 'foo');
     14    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
     15    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" does not exist');
     16    assert_equals(element.href.baseVal, 'foo');
     17 
     18    element.href.baseVal = 'bar';
     19    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" still does not exist');
     20    assert_true(element.hasAttributeNS(null, 'href'), '"href" still exists');
     21    assert_equals(element.getAttributeNS(null, 'href'), 'bar');
     22 }, document.title+', IDL href backed by "href" after setAttribute(href).');
     23 
     24 test(function() {
     25    const element = document.createElementNS(svgNs, 'a');
     26    element.setAttributeNS(xlinkNs, 'href', 'foo');
     27    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
     28    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
     29    assert_equals(element.href.baseVal, 'foo');
     30 
     31    element.href.baseVal = 'bar';
     32    assert_false(element.hasAttributeNS(null, 'href'), '"href" still does not exist');
     33    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" still exists');
     34    assert_equals(element.getAttributeNS(xlinkNs, 'href'), 'bar');
     35 }, document.title+', IDL href backed by "xlink:href" after setAttribute(xlink:href).');
     36 
     37 test(function() {
     38    const element = document.createElementNS(svgNs, 'a');
     39    element.href.baseVal = 'foo';
     40    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" does not exist');
     41    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
     42    assert_equals(element.href.baseVal, 'foo');
     43 }, document.title+', IDL href backed by "href" after baseVal setter.');
     44 
     45 test(function() {
     46    const element = document.createElementNS(svgNs, 'a');
     47    element.href.baseVal = 'foo';
     48    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" does not exist');
     49    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
     50    assert_equals(element.href.baseVal, 'foo');
     51 
     52    element.setAttributeNS(xlinkNs, 'href', 'bar');
     53    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
     54    assert_true(element.hasAttributeNS(null, 'href'), '"href" still exists');
     55    assert_equals(element.href.baseVal, 'foo', 'baseVal still reflects "href"');
     56    assert_equals(element.getAttributeNS(xlinkNs, 'href'), 'bar');
     57 }, document.title+', IDL href reflects "href"; setAttribute(xlink:href) does not override baseVal setter.');
     58 
     59 test(function() {
     60    const element = document.createElementNS(svgNs, 'a');
     61    element.setAttributeNS(xlinkNs, 'href', 'baz');
     62    element.href.baseVal = 'foo';
     63    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
     64    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
     65    assert_equals(element.href.baseVal, 'foo');
     66    assert_equals(element.getAttributeNS(xlinkNs, 'href'), 'foo');
     67 
     68    element.setAttributeNS(null, 'href', 'bar');
     69    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" still exists');
     70    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
     71    assert_equals(element.href.baseVal, 'bar', 'baseVal prefers "href" to "xlink:href"');
     72    assert_equals(element.getAttributeNS(xlinkNs, 'href'), 'foo');
     73    assert_equals(element.getAttributeNS(null, 'href'), 'bar');
     74 }, document.title+', IDL href prefers "href" over "xlink:href" after setAttribute(href) overrides.');
     75 
     76 test(function() {
     77    const element = document.createElementNS(svgNs, 'a');
     78    element.setAttributeNS(xlinkNs, 'href', 'foo');
     79    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
     80    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
     81    assert_equals(element.href.baseVal, 'foo');
     82    assert_equals(element.getAttributeNS(xlinkNs, 'href'), 'foo');
     83 
     84    element.setAttributeNS(xlinkNs, 'xlink:href', 'bar');
     85    assert_equals(element.href.baseVal, 'bar');
     86 }, document.title+', IDL href reflects "xlink:href"; setAttribute(xlink:href) w/ NS-prefix.');
     87 
     88 test(function() {
     89    const element = document.createElementNS(svgNs, 'a');
     90    element.setAttributeNS(null, 'href', 'foo');
     91    element.setAttributeNS(xlinkNs, 'href', 'bar');
     92    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
     93    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
     94    assert_equals(element.href.baseVal, 'foo', 'baseVal reflects "href"');
     95 
     96    element.removeAttributeNS(null, 'href');
     97    assert_false(element.hasAttributeNS(null, 'href'), '"href" no longer exist');
     98    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" still exist');
     99    assert_equals(element.href.baseVal, 'bar', 'baseVal reflects "xlink:href"');
    100 }, document.title+', IDL href reflects "xlink:href" after removeAttribute(href).');
    101 
    102 test(function() {
    103    const element = document.createElementNS(svgNs, 'a');
    104    element.setAttributeNS(null, 'href', 'foo');
    105    element.setAttributeNS(xlinkNs, 'href', 'bar');
    106    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
    107    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
    108    assert_equals(element.href.baseVal, 'foo', 'baseVal reflects "href"');
    109 
    110    element.removeAttributeNS(xlinkNs, 'href');
    111    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" no longer exist');
    112    assert_true(element.hasAttributeNS(null, 'href'), '"href" still exist');
    113    assert_equals(element.href.baseVal, 'foo', 'baseVal reflects "href"');
    114 }, document.title+', IDL href reflects "xlink:href"; removeAttribute(xlink:href) has no effect.');
    115 
    116 test(function() {
    117    const element = document.createElementNS(svgNs, 'a');
    118    element.setAttributeNS(xlinkNs, 'href', 'bar');
    119    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
    120    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
    121    assert_equals(element.href.baseVal, 'bar', 'baseVal reflects "xlink:href"');
    122 
    123    element.removeAttributeNS(xlinkNs, 'href');
    124    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" no longer exist');
    125    assert_equals(element.href.baseVal, '');
    126 }, document.title+', IDL href reflects "xlink:href"; removeAttribute(xlink:href) resets to default.');
    127 
    128 test(function() {
    129    const element = document.createElementNS(svgNs, 'a');
    130    element.setAttributeNS(xlinkNs, 'xlink:href', 'bar');
    131    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
    132    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
    133    assert_equals(element.href.baseVal, 'bar', 'baseVal reflects "xlink:href"');
    134 
    135    element.removeAttributeNS(xlinkNs, 'href');
    136    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" no longer exist');
    137    assert_equals(element.href.baseVal, '');
    138 }, document.title+', IDL href reflects "xlink:href"; removeAttribute(xlink:href) w/o NS-prefix resets to default.');
    139 
    140 test(function() {
    141    const element = document.createElementNS(svgNs, 'a');
    142    element.setAttributeNS(xlinkNs, 'xlink:href', 'bar');
    143    assert_false(element.hasAttributeNS(null, 'href'), '"href" does not exist');
    144    assert_true(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" exists');
    145    assert_equals(element.href.baseVal, 'bar', 'baseVal reflects "xlink:href"');
    146    assert_equals(element.href.animVal, 'bar', 'animVal reflects "xlink:href"');
    147 }, document.title+', href.animVal reflects "xlink:href" when it is set.');
    148 
    149 test(function() {
    150    const element = document.createElementNS(svgNs, 'a');
    151    element.setAttributeNS(null, 'href', 'bar');
    152    assert_true(element.hasAttributeNS(null, 'href'), '"href" exists');
    153    assert_false(element.hasAttributeNS(xlinkNs, 'href'), '"xlink:href" does not exist');
    154    assert_equals(element.href.baseVal, 'bar', 'baseVal reflects "href"');
    155    assert_equals(element.href.animVal, 'bar', 'animVal reflects "href"');
    156 }, document.title+', href.animVal reflects "href" when it is set.');
    157 </script>