tor-browser

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

007.html (5084B)


      1 <!DOCTYPE html>
      2 <title>drag &amp; drop - microdata with multiply named item as property</title>
      3 <style>
      4  body > div {
      5    height: 200px;
      6    width: 200px;
      7    background-color: orange;
      8    position: absolute;
      9    top: 8px;
     10    left: 8px;
     11  }
     12  body > div * {
     13    display: none;
     14  }
     15  body > div + div {
     16    background-color: navy;
     17    left: 250px;
     18  }
     19  body > div + div + div {
     20    background-color: fuchsia;
     21    left: 500px;
     22  }
     23  p:first-of-type {
     24    margin-top: 220px;
     25  }
     26 </style>
     27 
     28 <script>
     29 
     30 function makeEl(eltype,props,contents) {
     31  var elem = document.createElement(eltype);
     32  for( var i in props ) {
     33    if( props.hasOwnProperty(i) ) {
     34      elem.setAttribute(i,props[i]);
     35    }
     36  }
     37  if( contents ) {
     38    elem.innerHTML = contents;
     39  }
     40  return elem;
     41 }
     42 
     43 var orange, fails = [], doneonce = false;
     44 window.onload = function() {
     45  orange = document.getElementsByTagName('div')[0];
     46 
     47  orange.appendChild( makeEl('div',{itemprop:'foo bar',itemscope:'itemscope'},'') );
     48  orange.lastChild.appendChild( makeEl('div',{itemprop:'baz'},'test') );
     49 
     50  orange.ondragstart = function(e) {
     51    e.dataTransfer.effectAllowed = 'copy';
     52    e.dataTransfer.setData('Text', 'dummy text');
     53    var err;
     54    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     55      fails[fails.length] = e.type + ' ' + err;
     56    }
     57  };
     58  orange.nextSibling.ondragenter = orange.nextSibling.ondragleave = orange.nextSibling.ondragover =
     59  orange.ondrag = orange.ondragend = function(e) {
     60    if( e.type == 'dragover' || e.type == 'dragenter' ) {
     61      e.preventDefault();
     62      e.dataTransfer.dropEffect = 'copy';
     63    }
     64    if( e.dataTransfer.getData('application/microdata+json') ) {
     65      fails[fails.length] = e.type + ' unexpectedly had microdata (security restriction)';
     66    }
     67  };
     68  orange.nextSibling.ondrop = function(e) {
     69    var err;
     70    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     71      fails[fails.length] = e.type + ' ' + err;
     72    }
     73    if( e.type != 'drop' ) { return; }
     74    if( doneonce ) { return; }
     75    doneonce = true;
     76    setTimeout(function () {
     77      document.getElementsByTagName('p')[0].innerHTML = fails.length ? ( 'FAIL: ' + fails.join('<br>') ) : 'PASS';
     78      fails = [];
     79    }, 200 );
     80  };
     81 
     82 };
     83 function checkprops(md) {
     84  var i;
     85  if( !md ) { return 'no microdata'; }
     86  md = JSON.parse(md);
     87  if( !md.items ) { return 'no items'; }
     88  if( md.items.length != 1 ) { return md.items.length+' items instead of 1'; }
     89  if( !md.items[0].properties ) { return 'no properties'; }
     90  if( !md.items[0].properties.foo ) { return 'no properties.foo'; }
     91  if( !md.items[0].properties.bar ) { return 'no properties.bar'; }
     92  if( md.items[0].properties.baz ) { return 'properties.baz should not exist'; }
     93  if( md.items[0].properties.foo.length != 1 ) { return 'properties.foo length '+md.items[0].properties.foo.length+' instead of 1'; }
     94  if( md.items[0].properties.bar.length != 1 ) { return 'properties.bar length '+md.items[0].properties.bar.length+' instead of 1'; }
     95 
     96  if( !md.items[0].properties.foo[0] ) { return 'properties.foo[1] <i>'+md.items[0].properties.foo[0]+'</i> instead of <i>{properties:{baz:[test]}}</i>'; }
     97  if( !md.items[0].properties.foo[0].properties ) { return 'properties.foo[0].properties <i>'+md.items[0].properties.foo[0].properties+'</i> instead of <i>{baz:[test]}</i>'; }
     98  if( !md.items[0].properties.foo[0].properties.baz ) { return 'properties.foo[0].properties.baz <i>'+md.items[0].properties.foo[0].properties.baz+'</i> instead of <i>[test]</i>'; }
     99  if( !md.items[0].properties.foo[0].properties.baz.length ) { return 'properties.foo[0].properties.baz.length <i>'+md.items[0].properties.foo[0].properties.baz.length+'</i> instead of 1'; }
    100  if( md.items[0].properties.foo[0].properties.baz[0] != 'test') { return 'properties.foo[0].properties.baz[0] <i>'+md.items[0].properties.foo[0].properties.baz[0]+'</i> instead of <i>test</i>'; }
    101 
    102  if( !md.items[0].properties.bar[0] ) { return 'properties.bar[1] <i>'+md.items[0].properties.bar[0]+'</i> instead of <i>{properties:{baz:[test]}}</i>'; }
    103  if( !md.items[0].properties.bar[0].properties ) { return 'properties.bar[0].properties <i>'+md.items[0].properties.bar[0].properties+'</i> instead of <i>{baz:[test]}</i>'; }
    104  if( !md.items[0].properties.bar[0].properties.baz ) { return 'properties.bar[0].properties.baz <i>'+md.items[0].properties.bar[0].properties.baz+'</i> instead of <i>[test]</i>'; }
    105  if( !md.items[0].properties.bar[0].properties.baz.length ) { return 'properties.bar[0].properties.baz.length <i>'+md.items[0].properties.bar[0].properties.baz.length+'</i> instead of 1'; }
    106  if( md.items[0].properties.bar[0].properties.baz[0] != 'test') { return 'properties.bar[0].properties.baz[0] <i>'+md.items[0].properties.bar[0].properties.baz[0]+'</i> instead of <i>test</i>'; }
    107 
    108  return '';
    109 }
    110 
    111 </script>
    112 
    113 <div draggable='true' itemscope></div><div></div><div></div>
    114 
    115 <p>Use your pointing device to drag the orange box to the pink box, then back to the blue box, and release it.</p>
    116 <noscript><p>Enable JavaScript and reload</p></noscript>