tor-browser

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

005.html (4357B)


      1 <!DOCTYPE html>
      2 <title>drag &amp; drop - microdata with nested item as non-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',itemscope:'itemscope'},'') );
     48  orange.appendChild( makeEl('div',{itemscope:'itemscope'},'') );
     49  orange.lastChild.appendChild( makeEl('div',{itemprop:'bar'},'test') );
     50  orange.appendChild( makeEl('div',{itemprop:'bar',itemscope:'itemscope'},'') );
     51 
     52  orange.ondragstart = function(e) {
     53    e.dataTransfer.effectAllowed = 'copy';
     54    e.dataTransfer.setData('Text', 'dummy text');
     55    var err;
     56    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     57      fails[fails.length] = e.type + ' ' + err;
     58    }
     59  };
     60  orange.nextSibling.ondragenter = orange.nextSibling.ondragleave = orange.nextSibling.ondragover =
     61  orange.ondrag = orange.ondragend = function(e) {
     62    if( e.type == 'dragover' || e.type == 'dragenter' ) {
     63      e.preventDefault();
     64      e.dataTransfer.dropEffect = 'copy';
     65    }
     66    if( e.dataTransfer.getData('application/microdata+json') ) {
     67      fails[fails.length] = e.type + ' unexpectedly had microdata (security restriction)';
     68    }
     69  };
     70  orange.nextSibling.ondrop = function(e) {
     71    var err;
     72    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
     73      fails[fails.length] = e.type + ' ' + err;
     74    }
     75    if( e.type != 'drop' ) { return; }
     76    if( doneonce ) { return; }
     77    doneonce = true;
     78    setTimeout(function () {
     79      document.getElementsByTagName('p')[0].innerHTML = fails.length ? ( 'FAIL: ' + fails.join('<br>') ) : 'PASS';
     80      fails = [];
     81    }, 200 );
     82  };
     83 
     84 };
     85 function checkprops(md) {
     86  // http://dev.w3.org/html5/md/#drag-and-drop
     87  //"The user agent must take the list of dragged nodes and extract the microdata from those nodes into a JSON form"
     88  // http://dev.w3.org/html5/spec/dnd.html#drag-and-drop-processing-model
     89  //"the list of dragged nodes contains only the source node, if any."
     90  //nested items should only be in the items list if they are in a dragged *selection*
     91  var i;
     92  if( !md ) { return 'no microdata'; }
     93  md = JSON.parse(md);
     94  if( !md.items ) { return 'no items'; }
     95  if( md.items.length != 1 ) { return md.items.length+' items instead of 1'; }
     96  if( !md.items[0].properties ) { return 'no properties'; }
     97  if( !md.items[0].properties.foo ) { return 'no properties.foo'; }
     98  if( !md.items[0].properties.bar ) { return 'no properties.bar'; }
     99  if( md.items[0].properties.foo.length != 1 ) { return 'properties.foo length '+md.items[0].properties.foo.length+' instead of 1'; }
    100  if( md.items[0].properties.bar.length != 1 ) { return 'properties.bar length '+md.items[0].properties.bar.length+' instead of 1'; }
    101 
    102  if( !md.items[0].properties.foo[0] ) { return 'properties.foo[0] <i>'+md.items[0].properties.foo[0]+'</i> instead of <i>{properties:{}}</i>'; }
    103  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>{}</i>'; }
    104 
    105  if( !md.items[0].properties.bar[0] ) { return 'properties.bar[0] <i>'+md.items[0].properties.bar[0]+'</i> instead of <i>{properties:{}}</i>'; }
    106  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>{}</i>'; }
    107  return '';
    108 }
    109 
    110 </script>
    111 
    112 <div draggable='true' itemscope></div><div></div><div></div>
    113 
    114 <p>Use your pointing device to drag the orange box to the pink box, then back to the blue box, and release it.</p>
    115 <noscript><p>Enable JavaScript and reload</p></noscript>