summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/dnd/microdata/008.html
blob: d4cd7978174e6cd0ff5c029396b596ff4f094651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<title>drag &amp; drop - no microdata for selection with no items</title>
<style>
  body > div {
    height: 100px;
    width: 200px;
    background-color: fuchsia;
    position: absolute;
    top: 8px;
    left: 8px;
  }
  span span {
    display: none;
  }
  body > div + div {
    background-color: navy;
    top: 116px;
  }
  body > div + div + div {
    background-color: orange;
    top: 224px;
  }
  p:first-of-type {
    margin-top: 350px;
  }
</style>

<script>

function makeEl(eltype,props,contents) {
  var elem = document.createElement(eltype);
  for( var i in props ) {
    if( props.hasOwnProperty(i) ) {
      elem.setAttribute(i,props[i]);
    }
  }
  if( contents ) {
    elem.innerHTML = contents;
  }
  return elem;
}

var orange, fails = [], doneonce = false;
window.onload = function() {
  orange = document.getElementsByTagName('div')[2];
  orange.ondragstart = function(e) {
    e.dataTransfer.effectAllowed = 'copy';
    e.dataTransfer.setData('Text', 'dummy text');
    var err;
    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
      fails[fails.length] = e.type + ' ' + err;
    }
  };
  orange.previousSibling.ondragenter = orange.previousSibling.ondragleave = orange.previousSibling.ondragover =
  orange.ondrag = orange.ondragend = function(e) {
    if( e.type == 'dragover' || e.type == 'dragenter' ) {
      e.preventDefault();
      e.dataTransfer.dropEffect = 'copy';
    }
    if( e.dataTransfer.getData('application/microdata+json') ) {
      fails[fails.length] = e.type + ' unexpectedly had microdata (security restriction)';
    }
  };
  orange.previousSibling.ondrop = function(e) {
    var err;
    if( err = checkprops(e.dataTransfer.getData('application/microdata+json')) ) {
      fails[fails.length] = e.type + ' ' + err;
    }
    if( e.type != 'drop' ) { return; }
    if( doneonce ) { return; }
    doneonce = true;
    setTimeout(function () {
      document.getElementsByTagName('p')[0].innerHTML = fails.length ? ( 'FAIL: ' + fails.join('<br>') ) : 'PASS';
      fails = [];
    }, 200 );
  };

};
function checkprops(md) {
  var i;
  if( !md ) { return 'no microdata'; }
  md = JSON.parse(md);
  if( !md.items ) { return 'no items collection'; }
  if( md.items.length != 0 ) { return 'unexpected items found'; }
  return '';
}

</script>

<div></div><div></div><div>01<span>23</span>45<span>67</span>89</div>

<p>Use your pointing device to select the text substring "12345678" above, drag the selection upwards to the pink box,
then back to the blue box, and release it.</p>
<noscript><p>Enable JavaScript and reload</p></noscript>